3
0
mirror of https://git.kernel.org/pub/scm/network/wireless/iwd.git synced 2024-11-25 09:39:25 +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):
wd = IWD(True)
try:
self.validate_connection(wd)
finally:
del wd
@classmethod
def setUpClass(cls):

View File

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

View File

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

View File

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

View File

@ -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

View File

@ -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')

View File

@ -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')

View File

@ -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

View File

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

View File

@ -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
@classmethod
def setUpClass(cls):

View File

@ -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
@classmethod
def setUpClass(cls):

View File

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

View File

@ -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
@classmethod
def setUpClass(cls):

View File

@ -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
@classmethod
def setUpClass(cls):

View File

@ -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
@classmethod
def setUpClass(cls):

View File

@ -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
@classmethod
def setUpClass(cls):

View File

@ -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
@classmethod
def setUpClass(cls):

View File

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

View File

@ -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
@classmethod
def setUpClass(cls):

View File

@ -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
@classmethod
def setUpClass(cls):

View File

@ -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

View File

@ -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
@classmethod
def setUpClass(cls):

View File

@ -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
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
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
if __name__ == '__main__':
unittest.main(exit=True)

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -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
for ssid, seen in self.dict.items():
self.assertEqual(seen, True)

View File

@ -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
for ssid, seen in self.dict.items():
self.assertEqual(seen, True)
@classmethod
def setUpClass(cls):
IWD.copy_to_storage('ssid_hidden_0.open')

View File

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

View File

@ -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()