From c73575585b58fda5539acd7ea573e136a0e0249c Mon Sep 17 00:00:00 2001 From: Andrew Zaborowski Date: Sat, 20 Apr 2019 22:29:05 +0200 Subject: [PATCH] autotests: Remove del wd at the end function pattern Don't use del wd to dereference the IWD instance at the end of the function where it has been defined in the first place as at this point wd is about to have its reference count decreased anyway (the variable's scope is ending) so it's pointless (but didn't hurt). Relying on the __del__ destructor to kill the IWD process in those tests it has been started in the constructor is a bit of a hack in the first place, because the destructor is called on garbage collection and even through CPython does this on the refcount reaching 0, this is not documented and there's no guideline on when it should happen or if it should happen at all. So it could be argued that we should keep the del wd statemenets to be able to easily replace all of them with a call to a new method. But most of them are not placed so that they're guaranteed to happen on test success or failure. It would probably be easier to do this and other housekeeping in a base class and make the tests its subclasses. Also some of these tests don't really need to launch iwd themselves, since IWD now tracks changes in the known network files I think IWD only really needs to be killed between tests when main.conf changes. --- autotests/testAdHoc/adhoc_test.py | 5 +--- autotests/testAdHoc/failure_test.py | 5 +--- autotests/testAdHoc/open_test.py | 5 +--- .../testBSSBlacklist/all_blacklisted_test.py | 2 -- autotests/testBSSBlacklist/bad_pass_test.py | 2 -- autotests/testBSSBlacklist/connection_test.py | 2 -- .../testBSSBlacklist/temp_blacklist_test.py | 2 -- .../testConnectAutoconnect/validation.py | 8 +------ .../peap_gtc_nosecret_test.py | 9 ++----- autotests/testEAP-PEAP-GTC/peap_gtc_test.py | 8 +------ .../testEAP-PEAP-MSCHAPv2/connection_test.py | 9 +------ autotests/testEAP-PEAP-SIM/connection_test.py | 7 +----- autotests/testEAP-PEAP/peap_frag_test.py | 8 +------ autotests/testEAP-PEAP/peap_v0_test.py | 8 +------ autotests/testEAP-PEAP/peap_v1_test.py | 8 +------ autotests/testEAP-PWD/connection_test.py | 8 +------ autotests/testEAP-PWD/frag_test.py | 8 +------ .../testEAP-TTLS-MSCHAPv2/connection_test.py | 5 +--- autotests/testEAP-WPS/four_digit_pin_test.py | 6 +---- autotests/testEAP-WPS/push_button_test.py | 5 +--- autotests/testHiddenNetworks/validation.py | 10 ++------ .../testKnownNetworks/known_network_test.py | 8 +------ autotests/testMFP-Options/connection_test.py | 24 +++---------------- autotests/testSAE/autoconnect_test.py | 5 +--- autotests/testSAE/clogging_test.py | 5 +--- autotests/testSAE/connection_test.py | 5 +--- autotests/testSAE/failure_test.py | 5 +--- autotests/testSAE/group_20_connection_test.py | 5 +--- autotests/testScan/periodic_scan_test.py | 8 +------ autotests/testScan/requested_scan_test.py | 9 +------ .../testScanKnownFreqs/quick_scan_test.py | 5 +--- autotests/testWPA2/password_test.py | 2 -- 32 files changed, 31 insertions(+), 180 deletions(-) diff --git a/autotests/testAdHoc/adhoc_test.py b/autotests/testAdHoc/adhoc_test.py index 856c4afb..83c99fe5 100644 --- a/autotests/testAdHoc/adhoc_test.py +++ b/autotests/testAdHoc/adhoc_test.py @@ -31,10 +31,7 @@ class Test(unittest.TestCase): def test_connection_success(self): wd = IWD(True) - try: - self.validate_connection(wd) - finally: - del wd + self.validate_connection(wd) @classmethod def setUpClass(cls): diff --git a/autotests/testAdHoc/failure_test.py b/autotests/testAdHoc/failure_test.py index f96f3a1f..414932dc 100644 --- a/autotests/testAdHoc/failure_test.py +++ b/autotests/testAdHoc/failure_test.py @@ -33,10 +33,7 @@ class Test(unittest.TestCase): def test_connection_failure(self): wd = IWD(True) - try: - self.validate_connection(wd) - finally: - del wd + self.validate_connection(wd) @classmethod def setUpClass(cls): diff --git a/autotests/testAdHoc/open_test.py b/autotests/testAdHoc/open_test.py index b6b10e24..815533bb 100644 --- a/autotests/testAdHoc/open_test.py +++ b/autotests/testAdHoc/open_test.py @@ -32,10 +32,7 @@ class Test(unittest.TestCase): def test_connection_success(self): wd = IWD(True) - try: - self.validate_connection(wd) - finally: - del wd + self.validate_connection(wd) @classmethod def setUpClass(cls): diff --git a/autotests/testBSSBlacklist/all_blacklisted_test.py b/autotests/testBSSBlacklist/all_blacklisted_test.py index 9e721d1a..61635eca 100644 --- a/autotests/testBSSBlacklist/all_blacklisted_test.py +++ b/autotests/testBSSBlacklist/all_blacklisted_test.py @@ -101,8 +101,6 @@ class Test(unittest.TestCase): wd.unregister_psk_agent(psk_agent) - del wd - @classmethod def setUpClass(cls): pass diff --git a/autotests/testBSSBlacklist/bad_pass_test.py b/autotests/testBSSBlacklist/bad_pass_test.py index c1452cb6..f31549c3 100644 --- a/autotests/testBSSBlacklist/bad_pass_test.py +++ b/autotests/testBSSBlacklist/bad_pass_test.py @@ -98,8 +98,6 @@ class Test(unittest.TestCase): condition = 'obj.connected' wd.wait_for_object_condition(ordered_network.network_object, condition) - del wd - @classmethod def setUpClass(cls): pass diff --git a/autotests/testBSSBlacklist/connection_test.py b/autotests/testBSSBlacklist/connection_test.py index ef350a2a..9ed19d25 100644 --- a/autotests/testBSSBlacklist/connection_test.py +++ b/autotests/testBSSBlacklist/connection_test.py @@ -153,8 +153,6 @@ class Test(unittest.TestCase): wd.unregister_psk_agent(psk_agent) - del wd - @classmethod def setUpClass(cls): IWD.copy_to_storage('main.conf') diff --git a/autotests/testBSSBlacklist/temp_blacklist_test.py b/autotests/testBSSBlacklist/temp_blacklist_test.py index 82a1af51..1ed19ac6 100644 --- a/autotests/testBSSBlacklist/temp_blacklist_test.py +++ b/autotests/testBSSBlacklist/temp_blacklist_test.py @@ -133,8 +133,6 @@ class Test(unittest.TestCase): wd.unregister_psk_agent(psk_agent) - del wd - @classmethod def setUpClass(cls): IWD.copy_to_storage('main.conf') diff --git a/autotests/testConnectAutoconnect/validation.py b/autotests/testConnectAutoconnect/validation.py index 2118f55b..ed7ea155 100644 --- a/autotests/testConnectAutoconnect/validation.py +++ b/autotests/testConnectAutoconnect/validation.py @@ -71,10 +71,4 @@ class TestConnectAutoconnect(unittest.TestCase): def validate(self, ssid, autoconnect, throws = None, use_agent = False): wd = IWD(True) - try: - self.validate_connection(wd, ssid, autoconnect, throws, use_agent) - except: - del wd - raise - - del wd + self.validate_connection(wd, ssid, autoconnect, throws, use_agent) diff --git a/autotests/testEAP-PEAP-GTC/peap_gtc_nosecret_test.py b/autotests/testEAP-PEAP-GTC/peap_gtc_nosecret_test.py index a7f0cbf1..c372ab64 100644 --- a/autotests/testEAP-PEAP-GTC/peap_gtc_nosecret_test.py +++ b/autotests/testEAP-PEAP-GTC/peap_gtc_nosecret_test.py @@ -52,13 +52,8 @@ class Test(unittest.TestCase): try: self.validate_connection(wd) - except: - del wd - raise - - wd.unregister_psk_agent(psk_agent) - - del wd + finally: + wd.unregister_psk_agent(psk_agent) @classmethod def setUpClass(cls): diff --git a/autotests/testEAP-PEAP-GTC/peap_gtc_test.py b/autotests/testEAP-PEAP-GTC/peap_gtc_test.py index d3754d94..c81367d7 100644 --- a/autotests/testEAP-PEAP-GTC/peap_gtc_test.py +++ b/autotests/testEAP-PEAP-GTC/peap_gtc_test.py @@ -45,13 +45,7 @@ class Test(unittest.TestCase): def test_connection_success(self): wd = IWD(True) - try: - self.validate_connection(wd) - except: - del wd - raise - - del wd + self.validate_connection(wd) @classmethod def setUpClass(cls): diff --git a/autotests/testEAP-PEAP-MSCHAPv2/connection_test.py b/autotests/testEAP-PEAP-MSCHAPv2/connection_test.py index 75f858ad..7c6eb61b 100644 --- a/autotests/testEAP-PEAP-MSCHAPv2/connection_test.py +++ b/autotests/testEAP-PEAP-MSCHAPv2/connection_test.py @@ -46,14 +46,7 @@ class Test(unittest.TestCase): def test_connection_success(self): wd = IWD(True) - try: - self.validate_connection(wd) - except: - del wd - raise - - del wd - + self.validate_connection(wd) @classmethod def setUpClass(cls): diff --git a/autotests/testEAP-PEAP-SIM/connection_test.py b/autotests/testEAP-PEAP-SIM/connection_test.py index 78435435..26643d78 100644 --- a/autotests/testEAP-PEAP-SIM/connection_test.py +++ b/autotests/testEAP-PEAP-SIM/connection_test.py @@ -48,13 +48,8 @@ class Test(unittest.TestCase): try: self.validate_connection(wd) - except: - del wd + finally: auth.stop() - raise - - del wd - auth.stop() @classmethod def setUpClass(cls): diff --git a/autotests/testEAP-PEAP/peap_frag_test.py b/autotests/testEAP-PEAP/peap_frag_test.py index f1793ca1..2299816d 100644 --- a/autotests/testEAP-PEAP/peap_frag_test.py +++ b/autotests/testEAP-PEAP/peap_frag_test.py @@ -44,13 +44,7 @@ class Test(unittest.TestCase): def test_connection_success(self): wd = IWD(True, '/tmp/IWD-Frag') - try: - self.validate_connection(wd) - except: - del wd - raise - - del wd + self.validate_connection(wd) @classmethod def setUpClass(cls): diff --git a/autotests/testEAP-PEAP/peap_v0_test.py b/autotests/testEAP-PEAP/peap_v0_test.py index 54d5803b..1022d00a 100644 --- a/autotests/testEAP-PEAP/peap_v0_test.py +++ b/autotests/testEAP-PEAP/peap_v0_test.py @@ -44,13 +44,7 @@ class Test(unittest.TestCase): def test_connection_success(self): wd = IWD(True) - try: - self.validate_connection(wd) - except: - del wd - raise - - del wd + self.validate_connection(wd) @classmethod def setUpClass(cls): diff --git a/autotests/testEAP-PEAP/peap_v1_test.py b/autotests/testEAP-PEAP/peap_v1_test.py index b0670341..32c27b75 100644 --- a/autotests/testEAP-PEAP/peap_v1_test.py +++ b/autotests/testEAP-PEAP/peap_v1_test.py @@ -44,13 +44,7 @@ class Test(unittest.TestCase): def test_connection_success(self): wd = IWD(True) - try: - self.validate_connection(wd) - except: - del wd - raise - - del wd + self.validate_connection(wd) @classmethod def setUpClass(cls): diff --git a/autotests/testEAP-PWD/connection_test.py b/autotests/testEAP-PWD/connection_test.py index c14b5e9f..e5d6e621 100644 --- a/autotests/testEAP-PWD/connection_test.py +++ b/autotests/testEAP-PWD/connection_test.py @@ -71,13 +71,7 @@ class Test(unittest.TestCase): def test_connection_success(self): wd = IWD(True) - try: - self.validate_connection(wd) - except: - del wd - raise - - del wd + self.validate_connection(wd) @classmethod def setUpClass(cls): diff --git a/autotests/testEAP-PWD/frag_test.py b/autotests/testEAP-PWD/frag_test.py index 55162da6..763ecc17 100644 --- a/autotests/testEAP-PWD/frag_test.py +++ b/autotests/testEAP-PWD/frag_test.py @@ -43,13 +43,7 @@ class Test(unittest.TestCase): def test_connection_success(self): wd = IWD(True) - try: - self.validate_connection(wd) - except: - del wd - raise - - del wd + self.validate_connection(wd) @classmethod def setUpClass(cls): diff --git a/autotests/testEAP-TTLS-MSCHAPv2/connection_test.py b/autotests/testEAP-TTLS-MSCHAPv2/connection_test.py index 3182bda3..fb073dc9 100644 --- a/autotests/testEAP-TTLS-MSCHAPv2/connection_test.py +++ b/autotests/testEAP-TTLS-MSCHAPv2/connection_test.py @@ -73,10 +73,7 @@ class Test(unittest.TestCase): def test_connection_success(self): wd = IWD(True) - try: - self.validate_connection(wd) - finally: - del wd + self.validate_connection(wd) @classmethod def setUpClass(cls): diff --git a/autotests/testEAP-WPS/four_digit_pin_test.py b/autotests/testEAP-WPS/four_digit_pin_test.py index 5de74ccc..4a714114 100644 --- a/autotests/testEAP-WPS/four_digit_pin_test.py +++ b/autotests/testEAP-WPS/four_digit_pin_test.py @@ -31,13 +31,9 @@ class Test(unittest.TestCase): wd.wait_for_object_condition(device, condition) def test_connection_success(self): - wd = IWD(True) - try: - self.four_digit_pin_success(wd) - finally: - del wd + self.four_digit_pin_success(wd) @classmethod def setUpClass(cls): diff --git a/autotests/testEAP-WPS/push_button_test.py b/autotests/testEAP-WPS/push_button_test.py index 9e72fa33..18207212 100644 --- a/autotests/testEAP-WPS/push_button_test.py +++ b/autotests/testEAP-WPS/push_button_test.py @@ -32,10 +32,7 @@ class Test(unittest.TestCase): def test_connection_success(self): wd = IWD(True) - try: - self.push_button_success(wd) - finally: - del wd + self.push_button_success(wd) @classmethod def setUpClass(cls): diff --git a/autotests/testHiddenNetworks/validation.py b/autotests/testHiddenNetworks/validation.py index 035c7d09..35932575 100644 --- a/autotests/testHiddenNetworks/validation.py +++ b/autotests/testHiddenNetworks/validation.py @@ -73,11 +73,5 @@ class TestConnectAutoconnect(unittest.TestCase): wait_periodic_scan = False): wd = IWD(True, '/tmp') - try: - self.validate_connection(wd, ssid, autoconnect, throws, use_agent, - wait_periodic_scan) - except: - del wd - raise - - del wd + self.validate_connection(wd, ssid, autoconnect, throws, use_agent, + wait_periodic_scan) diff --git a/autotests/testKnownNetworks/known_network_test.py b/autotests/testKnownNetworks/known_network_test.py index 07f55b40..7678f930 100644 --- a/autotests/testKnownNetworks/known_network_test.py +++ b/autotests/testKnownNetworks/known_network_test.py @@ -75,13 +75,7 @@ class Test(unittest.TestCase): def test_known_networks(self): wd = IWD(True) - try: - self.list_removal_and_addition(wd) - except: - del wd - raise - - del wd + self.list_removal_and_addition(wd) @classmethod def setUpClass(cls): diff --git a/autotests/testMFP-Options/connection_test.py b/autotests/testMFP-Options/connection_test.py index 6aacd9f3..ccdc3452 100644 --- a/autotests/testMFP-Options/connection_test.py +++ b/autotests/testMFP-Options/connection_test.py @@ -86,35 +86,17 @@ class TestMFP(unittest.TestCase): def test_iwd_mfp0(self): wd = IWD(True, '/tmp/IWD-MFP0') - try: - self.stage_iwd(wd, '/tmp/IWD-MFP0') - except: - del wd - raise - - del wd + self.stage_iwd(wd, '/tmp/IWD-MFP0') def test_iwd_mfp1(self): wd = IWD(True, '/tmp/IWD-MFP1') - try: - self.stage_iwd(wd, '/tmp/IWD-MFP1') - except: - del wd - raise - - del wd + self.stage_iwd(wd, '/tmp/IWD-MFP1') def test_iwd_mfp2(self): wd = IWD(True, '/tmp/IWD-MFP2') - try: - self.stage_iwd(wd, '/tmp/IWD-MFP2') - except: - del wd - raise - - del wd + self.stage_iwd(wd, '/tmp/IWD-MFP2') if __name__ == '__main__': unittest.main(exit=True) diff --git a/autotests/testSAE/autoconnect_test.py b/autotests/testSAE/autoconnect_test.py index a1d77787..6d93f591 100644 --- a/autotests/testSAE/autoconnect_test.py +++ b/autotests/testSAE/autoconnect_test.py @@ -48,10 +48,7 @@ class Test(unittest.TestCase): def test_connection_success(self): wd = IWD(True) - try: - self.validate_connection(wd) - finally: - del wd + self.validate_connection(wd) @classmethod def setUpClass(cls): diff --git a/autotests/testSAE/clogging_test.py b/autotests/testSAE/clogging_test.py index 5c31a8c7..e94e2ad6 100644 --- a/autotests/testSAE/clogging_test.py +++ b/autotests/testSAE/clogging_test.py @@ -62,10 +62,7 @@ class Test(unittest.TestCase): def test_connection_success(self): wd = IWD(True) - try: - self.validate_connection(wd) - finally: - del wd + self.validate_connection(wd) @classmethod def setUpClass(cls): diff --git a/autotests/testSAE/connection_test.py b/autotests/testSAE/connection_test.py index 8959e712..874eb833 100644 --- a/autotests/testSAE/connection_test.py +++ b/autotests/testSAE/connection_test.py @@ -68,10 +68,7 @@ class Test(unittest.TestCase): def test_connection_success(self): wd = IWD(True) - try: - self.validate_connection(wd) - finally: - del wd + self.validate_connection(wd) @classmethod def setUpClass(cls): diff --git a/autotests/testSAE/failure_test.py b/autotests/testSAE/failure_test.py index 019fe7da..fdbbf449 100644 --- a/autotests/testSAE/failure_test.py +++ b/autotests/testSAE/failure_test.py @@ -43,10 +43,7 @@ class Test(unittest.TestCase): def test_connection_success(self): wd = IWD(True) - try: - self.validate_connection(wd) - finally: - del wd + self.validate_connection(wd) @classmethod def setUpClass(cls): diff --git a/autotests/testSAE/group_20_connection_test.py b/autotests/testSAE/group_20_connection_test.py index 9c6cd61d..033c8850 100644 --- a/autotests/testSAE/group_20_connection_test.py +++ b/autotests/testSAE/group_20_connection_test.py @@ -68,10 +68,7 @@ class Test(unittest.TestCase): def test_connection_success(self): wd = IWD(True) - try: - self.validate_connection(wd) - finally: - del wd + self.validate_connection(wd) @classmethod def setUpClass(cls): diff --git a/autotests/testScan/periodic_scan_test.py b/autotests/testScan/periodic_scan_test.py index 2bca624e..3252f79f 100644 --- a/autotests/testScan/periodic_scan_test.py +++ b/autotests/testScan/periodic_scan_test.py @@ -54,13 +54,7 @@ class Test(unittest.TestCase): def test_scan(self): wd = IWD(True, '/tmp') - try: - self.validate_scan(wd) - except: - del wd - raise - - del wd + self.validate_scan(wd) for ssid, seen in self.dict.items(): self.assertEqual(seen, True) diff --git a/autotests/testScan/requested_scan_test.py b/autotests/testScan/requested_scan_test.py index 7ab7f61a..11282ce1 100644 --- a/autotests/testScan/requested_scan_test.py +++ b/autotests/testScan/requested_scan_test.py @@ -55,18 +55,11 @@ class Test(unittest.TestCase): def test_scan(self): wd = IWD(True, '/tmp') - try: - self.validate_scan(wd) - except: - del wd - raise - - del wd + self.validate_scan(wd) for ssid, seen in self.dict.items(): self.assertEqual(seen, True) - @classmethod def setUpClass(cls): IWD.copy_to_storage('ssid_hidden_0.open') diff --git a/autotests/testScanKnownFreqs/quick_scan_test.py b/autotests/testScanKnownFreqs/quick_scan_test.py index c7dd8bba..35f71457 100644 --- a/autotests/testScanKnownFreqs/quick_scan_test.py +++ b/autotests/testScanKnownFreqs/quick_scan_test.py @@ -40,10 +40,7 @@ class Test(unittest.TestCase): def test_scan(self): wd = IWD(True) - try: - self.validate_quick_scan(wd) - finally: - del wd + self.validate_quick_scan(wd) # Only ssid_open_1 and ssid_open_2 should be discovered. self.assertEqual(self.dict['ssid_open_1'], True) diff --git a/autotests/testWPA2/password_test.py b/autotests/testWPA2/password_test.py index 4986d88b..3c6ed407 100644 --- a/autotests/testWPA2/password_test.py +++ b/autotests/testWPA2/password_test.py @@ -60,8 +60,6 @@ class Test(unittest.TestCase): self.assertRaises(iwd.InvalidFormatEx, network.connect) wd.unregister_psk_agent(psk_agent) - del wd - @classmethod def tearDownClass(cls): IWD.clear_storage()