Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions core/tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,6 @@ class TestSomething(unittest.TestCase):
```

Usage of `assert` is discouraged because it is not evaluated in production code (when `PYOPT=1`). Use `self.assertXY` instead, see `unittest.py`.

## Logging
By default, logging in unittests (using `trezor.log`) is disabled _even_ on debug builds. To enable logging, set `DISABLE_LOG` in `unittest.py` to `False`.
2 changes: 0 additions & 2 deletions core/tests/test_apps.bitcoin.approver.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ class TestApprover(unittest.TestCase):
if utils.USE_THP:

def setUpClass(self):
if __debug__:
thp_common.suppress_debug_log()
thp_common.prepare_context()

else:
Expand Down
2 changes: 0 additions & 2 deletions core/tests/test_apps.bitcoin.authorization.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ class TestAuthorization(unittest.TestCase):
if utils.USE_THP:

def setUpClass(self):
if __debug__:
thp_common.suppress_debug_log()
thp_common.prepare_context()

else:
Expand Down
4 changes: 0 additions & 4 deletions core/tests/test_apps.bitcoin.keychain.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ class TestBitcoinKeychain(unittest.TestCase):
if utils.USE_THP:

def setUpClass(self):
if __debug__:
thp_common.suppress_debug_log()
thp_common.prepare_context()

def setUp(self):
Expand Down Expand Up @@ -119,8 +117,6 @@ class TestAltcoinKeychains(unittest.TestCase):
if utils.USE_THP:

def setUpClass(self):
if __debug__:
thp_common.suppress_debug_log()
thp_common.prepare_context()

def setUp(self):
Expand Down
2 changes: 0 additions & 2 deletions core/tests/test_apps.common.keychain.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ class TestKeychain(unittest.TestCase):
if utils.USE_THP:

def setUpClass(self):
if __debug__:
thp_common.suppress_debug_log()
thp_common.prepare_context()

else:
Expand Down
2 changes: 0 additions & 2 deletions core/tests/test_apps.ethereum.keychain.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,6 @@ def _check_keychain(self, keychain, slip44_id):
if utils.USE_THP:

def setUpClass(self):
if __debug__:
thp_common.suppress_debug_log()
thp_common.prepare_context()

def setUp(self):
Expand Down
5 changes: 0 additions & 5 deletions core/tests/test_storage.cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,6 @@ class TestStorageCache(unittest.TestCase):

if utils.USE_THP:

def setUpClass(self):
if __debug__:
thp_common.suppress_debug_log()
super().__init__()

def setUp(self):
self.interface = MockHID()
cache.clear_all()
Expand Down
5 changes: 0 additions & 5 deletions core/tests/test_trezor.wire.thp.crypto.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,6 @@ class TestTrezorHostProtocolCrypto(unittest.TestCase):
(0xFFFFFFFFFFFFFFFF, b"\x00\x00\x00\x00\xff\xff\xff\xff\xff\xff\xff\xff"),
]

def __init__(self):
if __debug__ and utils.USE_THP:
thp_common.suppress_debug_log()
super().__init__()

def test_encryption(self):
for v in self.vectors_enc:
buffer = bytearray(v[3])
Expand Down
5 changes: 0 additions & 5 deletions core/tests/test_trezor.wire.thp.writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,6 @@ def await_until_result(self, task: Awaitable) -> Any:
while True:
task.send(None)

def __init__(self):
if __debug__ and utils.USE_THP:
thp_common.suppress_debug_log()
super().__init__()

def setUp(self):
self.interface = MockHID()
thp_ctx = ThpContext(self.interface)
Expand Down
8 changes: 0 additions & 8 deletions core/tests/thp_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,3 @@ def get_new_channel(iface: WireInterface) -> Channel:
thp_ctx = ThpContext(iface)
(iface_ctx,) = thp_ctx._iface_ctxs
return Channel(channel_cache, iface_ctx, (ThpBuffer(), ThpBuffer()))


if __debug__:
# Disable log.debug
def suppress_debug_log() -> None:
from trezor import log

log._min_level = 1
12 changes: 12 additions & 0 deletions core/tests/unittest.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
OK_COLOR = "\033[32m"
SKIPPED_COLOR = "\033[33m"

DISABLE_LOG = True


class SkipTest(Exception):
pass
Expand Down Expand Up @@ -227,6 +229,16 @@ def addTest(self, cls):


class TestRunner:

def __init__(self):
if __debug__ and DISABLE_LOG:
from trezor.utils import USE_DBG_CONSOLE

if USE_DBG_CONSOLE:
from trezor.utils import set_log_filter

set_log_filter("-*")

def run(self, suite):
res = TestResult()
for c in suite.tests:
Expand Down