1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-29 02:48:18 +00:00

test(core): replace __init__ in unit tests with setUpClass and tearDownClass

[no changelog]
This commit is contained in:
M1nd3r 2024-11-19 12:08:10 +01:00
parent d9a6c3f72f
commit 5ab357f0e0
7 changed files with 30 additions and 23 deletions

View File

@ -23,9 +23,11 @@ from apps.common import coins
class TestApprover(unittest.TestCase): class TestApprover(unittest.TestCase):
def __init__(self): def setUpClass(self):
context.CURRENT_CONTEXT = CodecContext(None, bytearray(64)) context.CURRENT_CONTEXT = CodecContext(None, bytearray(64))
super().__init__()
def tearDownClass(self):
context.CURRENT_CONTEXT = None
def setUp(self): def setUp(self):
self.coin = coins.by_name("Bitcoin") self.coin = coins.by_name("Bitcoin")

View File

@ -14,12 +14,14 @@ _ROUND_ID_LEN = 32
class TestAuthorization(unittest.TestCase): class TestAuthorization(unittest.TestCase):
def __init__(self):
context.CURRENT_CONTEXT = CodecContext(None, bytearray(64))
super().__init__()
coin = coins.by_name("Bitcoin") 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): def setUp(self):
self.msg_auth = AuthorizeCoinJoin( self.msg_auth = AuthorizeCoinJoin(
coordinator="www.example.com", coordinator="www.example.com",

View File

@ -12,9 +12,11 @@ from storage import cache_codec
class TestBitcoinKeychain(unittest.TestCase): class TestBitcoinKeychain(unittest.TestCase):
def __init__(self): def setUpClass(self):
context.CURRENT_CONTEXT = CodecContext(None, bytearray(64)) context.CURRENT_CONTEXT = CodecContext(None, bytearray(64))
super().__init__()
def tearDownClass(self):
context.CURRENT_CONTEXT = None
def setUp(self): def setUp(self):
cache_codec.start_session() cache_codec.start_session()
@ -97,13 +99,11 @@ class TestBitcoinKeychain(unittest.TestCase):
@unittest.skipUnless(not utils.BITCOIN_ONLY, "altcoin") @unittest.skipUnless(not utils.BITCOIN_ONLY, "altcoin")
class TestAltcoinKeychains(unittest.TestCase): class TestAltcoinKeychains(unittest.TestCase):
def __init__(self): def setUpClass(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
context.CURRENT_CONTEXT = CodecContext(None, bytearray(64)) context.CURRENT_CONTEXT = CodecContext(None, bytearray(64))
super().__init__()
def tearDownClass(self):
context.CURRENT_CONTEXT = None
def setUp(self): def setUp(self):
cache_codec.start_session() cache_codec.start_session()

View File

@ -16,9 +16,11 @@ from storage import cache_codec
class TestKeychain(unittest.TestCase): class TestKeychain(unittest.TestCase):
def __init__(self): def setUpClass(self):
context.CURRENT_CONTEXT = CodecContext(None, bytearray(64)) context.CURRENT_CONTEXT = CodecContext(None, bytearray(64))
super().__init__()
def tearDownClass(self):
context.CURRENT_CONTEXT = None
def setUp(self): def setUp(self):
cache_codec.start_session() cache_codec.start_session()

View File

@ -74,9 +74,11 @@ class TestEthereumKeychain(unittest.TestCase):
addr, addr,
) )
def __init__(self): def setUpClass(self):
context.CURRENT_CONTEXT = CodecContext(None, bytearray(64)) context.CURRENT_CONTEXT = CodecContext(None, bytearray(64))
super().__init__()
def tearDownClass(self):
context.CURRENT_CONTEXT = None
def setUp(self): def setUp(self):
cache_codec.start_session() cache_codec.start_session()

View File

@ -11,9 +11,6 @@ if not utils.BITCOIN_ONLY:
@unittest.skipUnless(not utils.BITCOIN_ONLY, "altcoin") @unittest.skipUnless(not utils.BITCOIN_ONLY, "altcoin")
class TestMoneroSerializer(unittest.TestCase): class TestMoneroSerializer(unittest.TestCase):
def __init__(self, *args, **kwargs):
super(TestMoneroSerializer, self).__init__(*args, **kwargs)
def test_varint(self): def test_varint(self):
""" """
Var int Var int

View File

@ -19,9 +19,11 @@ def is_session_started() -> bool:
class TestStorageCache(unittest.TestCase): class TestStorageCache(unittest.TestCase):
def __init__(self): def setUpClass(self):
context.CURRENT_CONTEXT = CodecContext(None, bytearray(64)) context.CURRENT_CONTEXT = CodecContext(None, bytearray(64))
super().__init__()
def tearDownClass(self):
context.CURRENT_CONTEXT = None
def setUp(self): def setUp(self):
cache.clear_all() cache.clear_all()