1
0
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:
matejcik 2018-03-09 10:58:24 +01:00 committed by GitHub
parent 89eac8f157
commit 5edcea9ba6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 41 additions and 6 deletions

View File

@ -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

View 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)

View File

@ -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():