def test_disabled_transport(): assert BridgeTransport.ENABLED assert BridgeTransport in all_transports() BridgeTransport.ENABLED = False assert BridgeTransport not in all_transports() # re-enable BridgeTransport.ENABLED = True
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)
def enumerate(self): try: from trezorlib.transport import all_transports except ImportError: # compat for trezorlib < 0.9.2 def all_transports(): from trezorlib.transport_bridge import BridgeTransport from trezorlib.transport_hid import HidTransport from trezorlib.transport_udp import UdpTransport from trezorlib.transport_webusb import WebUsbTransport return (BridgeTransport, HidTransport, UdpTransport, WebUsbTransport) devices = [] for transport in all_transports(): try: new_devices = transport.enumerate() except BaseException as e: self.print_error('enumerate failed for {}. error {}'.format( transport.__name__, str(e))) else: devices.extend(new_devices) return [ Device(d.get_path(), -1, d.get_path(), 'TREZOR', 0) for d in devices ]
def _all_transports(): """Reimplemented trezorlib.transport.all_transports for old trezorlib. Remove this when we start to require trezorlib 0.9.2 """ try: from trezorlib.transport import all_transports except ImportError: # compat for trezorlib < 0.9.2 def all_transports(): transports = [] try: from trezorlib.transport_bridge import BridgeTransport transports.append(BridgeTransport) except BaseException: pass try: from trezorlib.transport_hid import HidTransport transports.append(HidTransport) except BaseException: pass try: from trezorlib.transport_udp import UdpTransport transports.append(UdpTransport) except BaseException: pass try: from trezorlib.transport_webusb import WebUsbTransport transports.append(WebUsbTransport) except BaseException: pass return transports return all_transports()