From 5ab357f0e0fe7a00f24b0f622e4b6a613d98b423 Mon Sep 17 00:00:00 2001 From: M1nd3r Date: Tue, 19 Nov 2024 12:08:10 +0100 Subject: [PATCH] test(core): replace __init__ in unit tests with setUpClass and tearDownClass [no changelog] --- core/tests/test_apps.bitcoin.approver.py | 6 ++++-- core/tests/test_apps.bitcoin.authorization.py | 10 ++++++---- core/tests/test_apps.bitcoin.keychain.py | 16 ++++++++-------- core/tests/test_apps.common.keychain.py | 6 ++++-- core/tests/test_apps.ethereum.keychain.py | 6 ++++-- core/tests/test_apps.monero.serializer.py | 3 --- core/tests/test_storage.cache.py | 6 ++++-- 7 files changed, 30 insertions(+), 23 deletions(-) diff --git a/core/tests/test_apps.bitcoin.approver.py b/core/tests/test_apps.bitcoin.approver.py index 1bc48040e7..22888546f0 100644 --- a/core/tests/test_apps.bitcoin.approver.py +++ b/core/tests/test_apps.bitcoin.approver.py @@ -23,9 +23,11 @@ from apps.common import coins class TestApprover(unittest.TestCase): - def __init__(self): + def setUpClass(self): context.CURRENT_CONTEXT = CodecContext(None, bytearray(64)) - super().__init__() + + def tearDownClass(self): + context.CURRENT_CONTEXT = None def setUp(self): self.coin = coins.by_name("Bitcoin") diff --git a/core/tests/test_apps.bitcoin.authorization.py b/core/tests/test_apps.bitcoin.authorization.py index a2a8747285..03d32651c7 100644 --- a/core/tests/test_apps.bitcoin.authorization.py +++ b/core/tests/test_apps.bitcoin.authorization.py @@ -14,12 +14,14 @@ _ROUND_ID_LEN = 32 class TestAuthorization(unittest.TestCase): - def __init__(self): - context.CURRENT_CONTEXT = CodecContext(None, bytearray(64)) - super().__init__() - coin = coins.by_name("Bitcoin") + def setUpClass(self): + context.CURRENT_CONTEXT = CodecContext(None, bytearray(64)) + + def tearDownClass(self): + context.CURRENT_CONTEXT = None + def setUp(self): self.msg_auth = AuthorizeCoinJoin( coordinator="www.example.com", diff --git a/core/tests/test_apps.bitcoin.keychain.py b/core/tests/test_apps.bitcoin.keychain.py index e21f88c8c0..a232a000ae 100644 --- a/core/tests/test_apps.bitcoin.keychain.py +++ b/core/tests/test_apps.bitcoin.keychain.py @@ -12,9 +12,11 @@ from storage import cache_codec class TestBitcoinKeychain(unittest.TestCase): - def __init__(self): + def setUpClass(self): context.CURRENT_CONTEXT = CodecContext(None, bytearray(64)) - super().__init__() + + def tearDownClass(self): + context.CURRENT_CONTEXT = None def setUp(self): cache_codec.start_session() @@ -97,13 +99,11 @@ class TestBitcoinKeychain(unittest.TestCase): @unittest.skipUnless(not utils.BITCOIN_ONLY, "altcoin") class TestAltcoinKeychains(unittest.TestCase): - def __init__(self): - # Context is needed to test decorators and handleInitialize - # It allows access to codec cache from different parts of the code - from trezor.wire import context - + def setUpClass(self): context.CURRENT_CONTEXT = CodecContext(None, bytearray(64)) - super().__init__() + + def tearDownClass(self): + context.CURRENT_CONTEXT = None def setUp(self): cache_codec.start_session() diff --git a/core/tests/test_apps.common.keychain.py b/core/tests/test_apps.common.keychain.py index ea85b2eb8f..fa2e3ff041 100644 --- a/core/tests/test_apps.common.keychain.py +++ b/core/tests/test_apps.common.keychain.py @@ -16,9 +16,11 @@ from storage import cache_codec class TestKeychain(unittest.TestCase): - def __init__(self): + def setUpClass(self): context.CURRENT_CONTEXT = CodecContext(None, bytearray(64)) - super().__init__() + + def tearDownClass(self): + context.CURRENT_CONTEXT = None def setUp(self): cache_codec.start_session() diff --git a/core/tests/test_apps.ethereum.keychain.py b/core/tests/test_apps.ethereum.keychain.py index 404dc07641..a00b412a5f 100644 --- a/core/tests/test_apps.ethereum.keychain.py +++ b/core/tests/test_apps.ethereum.keychain.py @@ -74,9 +74,11 @@ class TestEthereumKeychain(unittest.TestCase): addr, ) - def __init__(self): + def setUpClass(self): context.CURRENT_CONTEXT = CodecContext(None, bytearray(64)) - super().__init__() + + def tearDownClass(self): + context.CURRENT_CONTEXT = None def setUp(self): cache_codec.start_session() diff --git a/core/tests/test_apps.monero.serializer.py b/core/tests/test_apps.monero.serializer.py index 7f11afbd39..2194a07f98 100644 --- a/core/tests/test_apps.monero.serializer.py +++ b/core/tests/test_apps.monero.serializer.py @@ -11,9 +11,6 @@ if not utils.BITCOIN_ONLY: @unittest.skipUnless(not utils.BITCOIN_ONLY, "altcoin") class TestMoneroSerializer(unittest.TestCase): - def __init__(self, *args, **kwargs): - super(TestMoneroSerializer, self).__init__(*args, **kwargs) - def test_varint(self): """ Var int diff --git a/core/tests/test_storage.cache.py b/core/tests/test_storage.cache.py index 60d1168004..25eb119bd3 100644 --- a/core/tests/test_storage.cache.py +++ b/core/tests/test_storage.cache.py @@ -19,9 +19,11 @@ def is_session_started() -> bool: class TestStorageCache(unittest.TestCase): - def __init__(self): + def setUpClass(self): context.CURRENT_CONTEXT = CodecContext(None, bytearray(64)) - super().__init__() + + def tearDownClass(self): + context.CURRENT_CONTEXT = None def setUp(self): cache.clear_all()