From d4e27b8ee2c9badd1a3e4d791dd159914ab59c84 Mon Sep 17 00:00:00 2001 From: James Prestwood Date: Wed, 21 Apr 2021 11:42:28 -0700 Subject: [PATCH] auto-t: move AuthCenter to Setup/Tear down By moving the AuthCenter initializer to SetUpClass we can now call stop() in TearDownClass which handles any exception the test might throw. --- autotests/testEAP-AKA-ofono/connection_test.py | 14 +++++--------- .../testEAP-AKA-prime-ofono/connection_test.py | 14 ++++---------- autotests/testEAP-SIM-ofono/connection_test.py | 14 +++++--------- 3 files changed, 14 insertions(+), 28 deletions(-) diff --git a/autotests/testEAP-AKA-ofono/connection_test.py b/autotests/testEAP-AKA-ofono/connection_test.py index ff987709..e667aa8d 100644 --- a/autotests/testEAP-AKA-ofono/connection_test.py +++ b/autotests/testEAP-AKA-ofono/connection_test.py @@ -12,10 +12,7 @@ from ofono import Ofono from config import ctx class Test(unittest.TestCase): - def test_connection_success(self): - auth = AuthCenter('/tmp/hlrauc.sock', '/tmp/sim.db') - ofono = Ofono() ofono.enable_modem('/phonesim') ofono.wait_for_sim_auth() @@ -40,11 +37,7 @@ class Test(unittest.TestCase): condition = 'not obj.connected' wd.wait_for_object_condition(ordered_network.network_object, condition) - try: - ordered_network.network_object.connect() - except: - auth.stop() - raise + ordered_network.network_object.connect() condition = 'obj.state == DeviceState.connected' wd.wait_for_object_condition(device, condition) @@ -54,7 +47,6 @@ class Test(unittest.TestCase): condition = 'not obj.connected' wd.wait_for_object_condition(ordered_network.network_object, condition) - auth.stop() @classmethod def setUpClass(cls): if not ctx.is_process_running('ofonod'): @@ -62,9 +54,13 @@ class Test(unittest.TestCase): IWD.copy_to_storage('ssidEAP-AKA.8021x') + cls.auth = AuthCenter('/tmp/hlrauc.sock', '/tmp/sim.db') + @classmethod def tearDownClass(cls): IWD.clear_storage() + cls.auth.stop() + if __name__ == '__main__': unittest.main(exit=True) diff --git a/autotests/testEAP-AKA-prime-ofono/connection_test.py b/autotests/testEAP-AKA-prime-ofono/connection_test.py index 01dd8249..e6dfaee0 100644 --- a/autotests/testEAP-AKA-prime-ofono/connection_test.py +++ b/autotests/testEAP-AKA-prime-ofono/connection_test.py @@ -12,10 +12,7 @@ from ofono import Ofono from config import ctx class Test(unittest.TestCase): - def test_connection_success(self): - auth = AuthCenter('/tmp/hlrauc.sock', '/tmp/sim.db') - ofono = Ofono() ofono.enable_modem('/phonesim') ofono.wait_for_sim_auth() @@ -40,11 +37,7 @@ class Test(unittest.TestCase): condition = 'not obj.connected' wd.wait_for_object_condition(ordered_network.network_object, condition) - try: - ordered_network.network_object.connect() - except: - auth.stop() - raise + ordered_network.network_object.connect() condition = 'obj.state == DeviceState.connected' wd.wait_for_object_condition(device, condition) @@ -54,8 +47,6 @@ class Test(unittest.TestCase): condition = 'not obj.connected' wd.wait_for_object_condition(ordered_network.network_object, condition) - auth.stop() - @classmethod def setUpClass(cls): if not ctx.is_process_running('ofonod'): @@ -63,9 +54,12 @@ class Test(unittest.TestCase): IWD.copy_to_storage('ssidEAP-AKA.8021x') + cls.auth = AuthCenter('/tmp/hlrauc.sock', '/tmp/sim.db') + @classmethod def tearDownClass(cls): IWD.clear_storage() + cls.auth.stop() if __name__ == '__main__': unittest.main(exit=True) diff --git a/autotests/testEAP-SIM-ofono/connection_test.py b/autotests/testEAP-SIM-ofono/connection_test.py index dcb2dcbc..e6a2d290 100644 --- a/autotests/testEAP-SIM-ofono/connection_test.py +++ b/autotests/testEAP-SIM-ofono/connection_test.py @@ -14,8 +14,6 @@ from config import ctx class Test(unittest.TestCase): def test_connection_success(self): - auth = AuthCenter('/tmp/hlrauc.sock', '/tmp/sim.db') - ofono = Ofono() ofono.enable_modem('/phonesim') ofono.wait_for_sim_auth() @@ -40,11 +38,7 @@ class Test(unittest.TestCase): condition = 'not obj.connected' wd.wait_for_object_condition(ordered_network.network_object, condition) - try: - ordered_network.network_object.connect() - except: - auth.stop() - raise + ordered_network.network_object.connect() condition = 'obj.state == DeviceState.connected' wd.wait_for_object_condition(device, condition) @@ -54,8 +48,6 @@ class Test(unittest.TestCase): condition = 'not obj.connected' wd.wait_for_object_condition(ordered_network.network_object, condition) - auth.stop() - @classmethod def setUpClass(cls): if not ctx.is_process_running('ofonod'): @@ -63,9 +55,13 @@ class Test(unittest.TestCase): IWD.copy_to_storage('ssidEAP-SIM.8021x') + cls.auth = AuthCenter('/tmp/hlrauc.sock', '/tmp/sim.db') + @classmethod def tearDownClass(cls): IWD.clear_storage() + cls.auth.stop() + if __name__ == '__main__': unittest.main(exit=True)