From 71c71e94445f158f3a731b0e29e40f08f1ca8a0b Mon Sep 17 00:00:00 2001 From: Andrea Frittoli Date: Fri, 7 Apr 2017 17:45:21 +0100 Subject: [PATCH] Beautify assertEmpty and assertNotEmpty Don't use 'list' as a parameter name since this assert can be used for any sequence or collection. Add docstring for both helpers. Change-Id: I747507c3a5d0cf6f84915c8dd9222f4c082cbc04 --- tempest/test.py | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/tempest/test.py b/tempest/test.py index 52994ac77a..70421fd1c5 100644 --- a/tempest/test.py +++ b/tempest/test.py @@ -642,12 +642,24 @@ class BaseTestCase(testtools.testcase.WithAttributes, return fixed_network.get_tenant_network( cred_provider, networks_client, CONF.compute.fixed_network_name) - def assertEmpty(self, list, msg=None): - if msg is None: - msg = "list is not empty: %s" % list - self.assertEqual(0, len(list), msg) + def assertEmpty(self, items, msg=None): + """Asserts whether a sequence or collection is empty - def assertNotEmpty(self, list, msg=None): + :param items: sequence or collection to be tested + :param msg: message to be passed to the AssertionError + :raises AssertionError: when items is not empty + """ if msg is None: - msg = "list is empty." - self.assertGreater(len(list), 0, msg) + msg = "sequence or collection is not empty: %s" % items + self.assertEqual(0, len(items), msg) + + def assertNotEmpty(self, items, msg=None): + """Asserts whether a sequence or collection is not empty + + :param items: sequence or collection to be tested + :param msg: message to be passed to the AssertionError + :raises AssertionError: when items is empty + """ + if msg is None: + msg = "sequence or collection is empty." + self.assertGreater(len(items), 0, msg)