mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-29 10:58:21 +00:00
transport: fix all_transports when required modules are missing (#232)
This lets the library work without libusb or hidapi (`--disable-libusb`, `--disable-hidapi`).
This commit is contained in:
parent
89eac8f157
commit
5edcea9ba6
3
tox.ini
3
tox.ini
@ -1,6 +1,6 @@
|
||||
[tox]
|
||||
envlist =
|
||||
py27,
|
||||
py33,
|
||||
py34,
|
||||
py35,
|
||||
py36,
|
||||
@ -9,6 +9,7 @@ envlist =
|
||||
deps =
|
||||
-rrequirements.txt
|
||||
pytest
|
||||
mock
|
||||
commands =
|
||||
python -m compileall trezorlib/
|
||||
python trezorctl --help
|
||||
|
13
trezorlib/tests/unit_tests/test_transport.py
Normal file
13
trezorlib/tests/unit_tests/test_transport.py
Normal file
@ -0,0 +1,13 @@
|
||||
import mock
|
||||
|
||||
from trezorlib.transport import all_transports
|
||||
|
||||
|
||||
def test_all_transports_without_hid():
|
||||
# import all transports, assume this doesn't fail
|
||||
transports_ref = all_transports()
|
||||
# also shouldn't fail when bridge transport is missing
|
||||
with mock.patch.dict('sys.modules', {'trezorlib.transport.bridge': None}):
|
||||
transports = all_transports()
|
||||
# there should now be less transports
|
||||
assert len(transports_ref) > len(transports)
|
@ -64,11 +64,32 @@ class Transport(object):
|
||||
|
||||
|
||||
def all_transports():
|
||||
from .bridge import BridgeTransport
|
||||
from .hid import HidTransport
|
||||
from .udp import UdpTransport
|
||||
from .webusb import WebUsbTransport
|
||||
return (BridgeTransport, HidTransport, UdpTransport, WebUsbTransport)
|
||||
transports = []
|
||||
try:
|
||||
from .bridge import BridgeTransport
|
||||
transports.append(BridgeTransport)
|
||||
except:
|
||||
pass
|
||||
|
||||
try:
|
||||
from .hid import HidTransport
|
||||
transports.append(HidTransport)
|
||||
except:
|
||||
pass
|
||||
|
||||
try:
|
||||
from .udp import UdpTransport
|
||||
transports.append(UdpTransport)
|
||||
except:
|
||||
pass
|
||||
|
||||
try:
|
||||
from .webusb import WebUsbTransport
|
||||
transports.append(WebUsbTransport)
|
||||
except:
|
||||
pass
|
||||
|
||||
return transports
|
||||
|
||||
|
||||
def enumerate_devices():
|
||||
|
Loading…
Reference in New Issue
Block a user