3
0
mirror of https://git.kernel.org/pub/scm/network/wireless/iwd.git synced 2024-11-28 21:19:24 +01:00

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.
This commit is contained in:
Andrew Zaborowski 2019-04-20 22:29:05 +02:00 committed by Denis Kenzior
parent f456ac49dc
commit c73575585b
32 changed files with 31 additions and 180 deletions

View File

@ -31,10 +31,7 @@ class Test(unittest.TestCase):
def test_connection_success(self): def test_connection_success(self):
wd = IWD(True) wd = IWD(True)
try:
self.validate_connection(wd) self.validate_connection(wd)
finally:
del wd
@classmethod @classmethod
def setUpClass(cls): def setUpClass(cls):

View File

@ -33,10 +33,7 @@ class Test(unittest.TestCase):
def test_connection_failure(self): def test_connection_failure(self):
wd = IWD(True) wd = IWD(True)
try:
self.validate_connection(wd) self.validate_connection(wd)
finally:
del wd
@classmethod @classmethod
def setUpClass(cls): def setUpClass(cls):

View File

@ -32,10 +32,7 @@ class Test(unittest.TestCase):
def test_connection_success(self): def test_connection_success(self):
wd = IWD(True) wd = IWD(True)
try:
self.validate_connection(wd) self.validate_connection(wd)
finally:
del wd
@classmethod @classmethod
def setUpClass(cls): def setUpClass(cls):

View File

@ -101,8 +101,6 @@ class Test(unittest.TestCase):
wd.unregister_psk_agent(psk_agent) wd.unregister_psk_agent(psk_agent)
del wd
@classmethod @classmethod
def setUpClass(cls): def setUpClass(cls):
pass pass

View File

@ -98,8 +98,6 @@ class Test(unittest.TestCase):
condition = 'obj.connected' condition = 'obj.connected'
wd.wait_for_object_condition(ordered_network.network_object, condition) wd.wait_for_object_condition(ordered_network.network_object, condition)
del wd
@classmethod @classmethod
def setUpClass(cls): def setUpClass(cls):
pass pass

View File

@ -153,8 +153,6 @@ class Test(unittest.TestCase):
wd.unregister_psk_agent(psk_agent) wd.unregister_psk_agent(psk_agent)
del wd
@classmethod @classmethod
def setUpClass(cls): def setUpClass(cls):
IWD.copy_to_storage('main.conf') IWD.copy_to_storage('main.conf')

View File

@ -133,8 +133,6 @@ class Test(unittest.TestCase):
wd.unregister_psk_agent(psk_agent) wd.unregister_psk_agent(psk_agent)
del wd
@classmethod @classmethod
def setUpClass(cls): def setUpClass(cls):
IWD.copy_to_storage('main.conf') IWD.copy_to_storage('main.conf')

View File

@ -71,10 +71,4 @@ class TestConnectAutoconnect(unittest.TestCase):
def validate(self, ssid, autoconnect, throws = None, use_agent = False): def validate(self, ssid, autoconnect, throws = None, use_agent = False):
wd = IWD(True) wd = IWD(True)
try:
self.validate_connection(wd, ssid, autoconnect, throws, use_agent) self.validate_connection(wd, ssid, autoconnect, throws, use_agent)
except:
del wd
raise
del wd

View File

@ -52,14 +52,9 @@ class Test(unittest.TestCase):
try: try:
self.validate_connection(wd) self.validate_connection(wd)
except: finally:
del wd
raise
wd.unregister_psk_agent(psk_agent) wd.unregister_psk_agent(psk_agent)
del wd
@classmethod @classmethod
def setUpClass(cls): def setUpClass(cls):
IWD.copy_to_storage('ssidEAP-PEAPv1-GTC-nosecret.8021x') IWD.copy_to_storage('ssidEAP-PEAPv1-GTC-nosecret.8021x')

View File

@ -45,13 +45,7 @@ class Test(unittest.TestCase):
def test_connection_success(self): def test_connection_success(self):
wd = IWD(True) wd = IWD(True)
try:
self.validate_connection(wd) self.validate_connection(wd)
except:
del wd
raise
del wd
@classmethod @classmethod
def setUpClass(cls): def setUpClass(cls):

View File

@ -46,14 +46,7 @@ class Test(unittest.TestCase):
def test_connection_success(self): def test_connection_success(self):
wd = IWD(True) wd = IWD(True)
try:
self.validate_connection(wd) self.validate_connection(wd)
except:
del wd
raise
del wd
@classmethod @classmethod
def setUpClass(cls): def setUpClass(cls):

View File

@ -48,12 +48,7 @@ class Test(unittest.TestCase):
try: try:
self.validate_connection(wd) self.validate_connection(wd)
except: finally:
del wd
auth.stop()
raise
del wd
auth.stop() auth.stop()
@classmethod @classmethod

View File

@ -44,13 +44,7 @@ class Test(unittest.TestCase):
def test_connection_success(self): def test_connection_success(self):
wd = IWD(True, '/tmp/IWD-Frag') wd = IWD(True, '/tmp/IWD-Frag')
try:
self.validate_connection(wd) self.validate_connection(wd)
except:
del wd
raise
del wd
@classmethod @classmethod
def setUpClass(cls): def setUpClass(cls):

View File

@ -44,13 +44,7 @@ class Test(unittest.TestCase):
def test_connection_success(self): def test_connection_success(self):
wd = IWD(True) wd = IWD(True)
try:
self.validate_connection(wd) self.validate_connection(wd)
except:
del wd
raise
del wd
@classmethod @classmethod
def setUpClass(cls): def setUpClass(cls):

View File

@ -44,13 +44,7 @@ class Test(unittest.TestCase):
def test_connection_success(self): def test_connection_success(self):
wd = IWD(True) wd = IWD(True)
try:
self.validate_connection(wd) self.validate_connection(wd)
except:
del wd
raise
del wd
@classmethod @classmethod
def setUpClass(cls): def setUpClass(cls):

View File

@ -71,13 +71,7 @@ class Test(unittest.TestCase):
def test_connection_success(self): def test_connection_success(self):
wd = IWD(True) wd = IWD(True)
try:
self.validate_connection(wd) self.validate_connection(wd)
except:
del wd
raise
del wd
@classmethod @classmethod
def setUpClass(cls): def setUpClass(cls):

View File

@ -43,13 +43,7 @@ class Test(unittest.TestCase):
def test_connection_success(self): def test_connection_success(self):
wd = IWD(True) wd = IWD(True)
try:
self.validate_connection(wd) self.validate_connection(wd)
except:
del wd
raise
del wd
@classmethod @classmethod
def setUpClass(cls): def setUpClass(cls):

View File

@ -73,10 +73,7 @@ class Test(unittest.TestCase):
def test_connection_success(self): def test_connection_success(self):
wd = IWD(True) wd = IWD(True)
try:
self.validate_connection(wd) self.validate_connection(wd)
finally:
del wd
@classmethod @classmethod
def setUpClass(cls): def setUpClass(cls):

View File

@ -31,13 +31,9 @@ class Test(unittest.TestCase):
wd.wait_for_object_condition(device, condition) wd.wait_for_object_condition(device, condition)
def test_connection_success(self): def test_connection_success(self):
wd = IWD(True) wd = IWD(True)
try:
self.four_digit_pin_success(wd) self.four_digit_pin_success(wd)
finally:
del wd
@classmethod @classmethod
def setUpClass(cls): def setUpClass(cls):

View File

@ -32,10 +32,7 @@ class Test(unittest.TestCase):
def test_connection_success(self): def test_connection_success(self):
wd = IWD(True) wd = IWD(True)
try:
self.push_button_success(wd) self.push_button_success(wd)
finally:
del wd
@classmethod @classmethod
def setUpClass(cls): def setUpClass(cls):

View File

@ -73,11 +73,5 @@ class TestConnectAutoconnect(unittest.TestCase):
wait_periodic_scan = False): wait_periodic_scan = False):
wd = IWD(True, '/tmp') wd = IWD(True, '/tmp')
try:
self.validate_connection(wd, ssid, autoconnect, throws, use_agent, self.validate_connection(wd, ssid, autoconnect, throws, use_agent,
wait_periodic_scan) wait_periodic_scan)
except:
del wd
raise
del wd

View File

@ -75,13 +75,7 @@ class Test(unittest.TestCase):
def test_known_networks(self): def test_known_networks(self):
wd = IWD(True) wd = IWD(True)
try:
self.list_removal_and_addition(wd) self.list_removal_and_addition(wd)
except:
del wd
raise
del wd
@classmethod @classmethod
def setUpClass(cls): def setUpClass(cls):

View File

@ -86,35 +86,17 @@ class TestMFP(unittest.TestCase):
def test_iwd_mfp0(self): def test_iwd_mfp0(self):
wd = IWD(True, '/tmp/IWD-MFP0') wd = IWD(True, '/tmp/IWD-MFP0')
try:
self.stage_iwd(wd, '/tmp/IWD-MFP0') self.stage_iwd(wd, '/tmp/IWD-MFP0')
except:
del wd
raise
del wd
def test_iwd_mfp1(self): def test_iwd_mfp1(self):
wd = IWD(True, '/tmp/IWD-MFP1') wd = IWD(True, '/tmp/IWD-MFP1')
try:
self.stage_iwd(wd, '/tmp/IWD-MFP1') self.stage_iwd(wd, '/tmp/IWD-MFP1')
except:
del wd
raise
del wd
def test_iwd_mfp2(self): def test_iwd_mfp2(self):
wd = IWD(True, '/tmp/IWD-MFP2') wd = IWD(True, '/tmp/IWD-MFP2')
try:
self.stage_iwd(wd, '/tmp/IWD-MFP2') self.stage_iwd(wd, '/tmp/IWD-MFP2')
except:
del wd
raise
del wd
if __name__ == '__main__': if __name__ == '__main__':
unittest.main(exit=True) unittest.main(exit=True)

View File

@ -48,10 +48,7 @@ class Test(unittest.TestCase):
def test_connection_success(self): def test_connection_success(self):
wd = IWD(True) wd = IWD(True)
try:
self.validate_connection(wd) self.validate_connection(wd)
finally:
del wd
@classmethod @classmethod
def setUpClass(cls): def setUpClass(cls):

View File

@ -62,10 +62,7 @@ class Test(unittest.TestCase):
def test_connection_success(self): def test_connection_success(self):
wd = IWD(True) wd = IWD(True)
try:
self.validate_connection(wd) self.validate_connection(wd)
finally:
del wd
@classmethod @classmethod
def setUpClass(cls): def setUpClass(cls):

View File

@ -68,10 +68,7 @@ class Test(unittest.TestCase):
def test_connection_success(self): def test_connection_success(self):
wd = IWD(True) wd = IWD(True)
try:
self.validate_connection(wd) self.validate_connection(wd)
finally:
del wd
@classmethod @classmethod
def setUpClass(cls): def setUpClass(cls):

View File

@ -43,10 +43,7 @@ class Test(unittest.TestCase):
def test_connection_success(self): def test_connection_success(self):
wd = IWD(True) wd = IWD(True)
try:
self.validate_connection(wd) self.validate_connection(wd)
finally:
del wd
@classmethod @classmethod
def setUpClass(cls): def setUpClass(cls):

View File

@ -68,10 +68,7 @@ class Test(unittest.TestCase):
def test_connection_success(self): def test_connection_success(self):
wd = IWD(True) wd = IWD(True)
try:
self.validate_connection(wd) self.validate_connection(wd)
finally:
del wd
@classmethod @classmethod
def setUpClass(cls): def setUpClass(cls):

View File

@ -54,13 +54,7 @@ class Test(unittest.TestCase):
def test_scan(self): def test_scan(self):
wd = IWD(True, '/tmp') wd = IWD(True, '/tmp')
try:
self.validate_scan(wd) self.validate_scan(wd)
except:
del wd
raise
del wd
for ssid, seen in self.dict.items(): for ssid, seen in self.dict.items():
self.assertEqual(seen, True) self.assertEqual(seen, True)

View File

@ -55,18 +55,11 @@ class Test(unittest.TestCase):
def test_scan(self): def test_scan(self):
wd = IWD(True, '/tmp') wd = IWD(True, '/tmp')
try:
self.validate_scan(wd) self.validate_scan(wd)
except:
del wd
raise
del wd
for ssid, seen in self.dict.items(): for ssid, seen in self.dict.items():
self.assertEqual(seen, True) self.assertEqual(seen, True)
@classmethod @classmethod
def setUpClass(cls): def setUpClass(cls):
IWD.copy_to_storage('ssid_hidden_0.open') IWD.copy_to_storage('ssid_hidden_0.open')

View File

@ -40,10 +40,7 @@ class Test(unittest.TestCase):
def test_scan(self): def test_scan(self):
wd = IWD(True) wd = IWD(True)
try:
self.validate_quick_scan(wd) self.validate_quick_scan(wd)
finally:
del wd
# Only ssid_open_1 and ssid_open_2 should be discovered. # Only ssid_open_1 and ssid_open_2 should be discovered.
self.assertEqual(self.dict['ssid_open_1'], True) self.assertEqual(self.dict['ssid_open_1'], True)

View File

@ -60,8 +60,6 @@ class Test(unittest.TestCase):
self.assertRaises(iwd.InvalidFormatEx, network.connect) self.assertRaises(iwd.InvalidFormatEx, network.connect)
wd.unregister_psk_agent(psk_agent) wd.unregister_psk_agent(psk_agent)
del wd
@classmethod @classmethod
def tearDownClass(cls): def tearDownClass(cls):
IWD.clear_storage() IWD.clear_storage()