mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-02-18 02:22:01 +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]
|
[tox]
|
||||||
envlist =
|
envlist =
|
||||||
py27,
|
py33,
|
||||||
py34,
|
py34,
|
||||||
py35,
|
py35,
|
||||||
py36,
|
py36,
|
||||||
@ -9,6 +9,7 @@ envlist =
|
|||||||
deps =
|
deps =
|
||||||
-rrequirements.txt
|
-rrequirements.txt
|
||||||
pytest
|
pytest
|
||||||
|
mock
|
||||||
commands =
|
commands =
|
||||||
python -m compileall trezorlib/
|
python -m compileall trezorlib/
|
||||||
python trezorctl --help
|
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():
|
def all_transports():
|
||||||
from .bridge import BridgeTransport
|
transports = []
|
||||||
from .hid import HidTransport
|
try:
|
||||||
from .udp import UdpTransport
|
from .bridge import BridgeTransport
|
||||||
from .webusb import WebUsbTransport
|
transports.append(BridgeTransport)
|
||||||
return (BridgeTransport, HidTransport, UdpTransport, WebUsbTransport)
|
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():
|
def enumerate_devices():
|
||||||
|
Loading…
Reference in New Issue
Block a user