1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-23 07:58:09 +00:00

tests/unit_tests: update test_transport

This commit is contained in:
matejcik 2018-11-26 15:57:46 +01:00
parent c95489513e
commit 1ded85c746

View File

@ -14,16 +14,42 @@
# You should have received a copy of the License along with this library. # You should have received a copy of the License along with this library.
# If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>. # If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>.
import importlib
from unittest import mock from unittest import mock
from trezorlib.transport import all_transports from trezorlib.transport import all_transports
from trezorlib.transport.bridge import BridgeTransport
def test_all_transports_without_hid(): def test_disabled_transport():
# import all transports, assume this doesn't fail assert BridgeTransport.ENABLED
transports_ref = all_transports() assert BridgeTransport in all_transports()
# also shouldn't fail when bridge transport is missing
with mock.patch.dict("sys.modules", {"trezorlib.transport.bridge": None}): BridgeTransport.ENABLED = False
transports = all_transports() assert BridgeTransport not in all_transports()
# there should now be less transports # re-enable
assert len(transports_ref) > len(transports) BridgeTransport.ENABLED = True
def test_import_all_transports():
from trezorlib.transport.bridge import BridgeTransport
from trezorlib.transport.hid import HidTransport
from trezorlib.transport.webusb import WebUsbTransport
from trezorlib.transport.udp import UdpTransport
assert BridgeTransport
assert HidTransport
assert WebUsbTransport
assert UdpTransport
def test_transport_dependencies():
import trezorlib.transport.hid as hid_transport
with mock.patch.dict("sys.modules", {"hid": None}):
importlib.reload(hid_transport)
assert not hid_transport.HidTransport.ENABLED
with mock.patch.dict("sys.modules", {"hid": mock.Mock()}):
importlib.reload(hid_transport)
assert hid_transport.HidTransport.ENABLED