From fea24d0a06932063bd8bec8d936a0e45210750af Mon Sep 17 00:00:00 2001 From: Alex Szarka Date: Thu, 22 Jun 2017 13:57:11 +0200 Subject: [PATCH] Use more specific asserts in test/unit/account tests I changed asserts with more specific assert methods. e.g.: from assertTrue(x in y) to assertIn(x, y). The code gets more readable, and a better description will be shown on fail Change-Id: Ic20fbff8a7bb2e870c1609d4fa6e6255eabbeced --- test/unit/account/test_auditor.py | 6 +++--- test/unit/account/test_backend.py | 14 +++++++------- test/unit/account/test_server.py | 2 +- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/test/unit/account/test_auditor.py b/test/unit/account/test_auditor.py index e4cb382c23..3ea361ff14 100644 --- a/test/unit/account/test_auditor.py +++ b/test/unit/account/test_auditor.py @@ -252,9 +252,9 @@ class TestAuditorRealBroker(unittest.TestCase): error_lines = test_auditor.logger.get_lines_for_level('error') self.assertEqual(len(error_lines), 1) error_message = error_lines[0] - self.assertTrue(broker.db_file in error_message) - self.assertTrue('container_count' in error_message) - self.assertTrue('does not match' in error_message) + self.assertIn(broker.db_file, error_message) + self.assertIn('container_count', error_message) + self.assertIn('does not match', error_message) self.assertEqual(test_auditor.logger.get_increment_counts(), {'failures': 1}) diff --git a/test/unit/account/test_backend.py b/test/unit/account/test_backend.py index 6810d77546..a09b9a3fac 100644 --- a/test/unit/account/test_backend.py +++ b/test/unit/account/test_backend.py @@ -1062,7 +1062,7 @@ class TestAccountBrokerBeforeMetadata(TestAccountBroker): conn.execute('SELECT metadata FROM account_stat') except BaseException as err: exc = err - self.assertTrue('no such column: metadata' in str(exc)) + self.assertIn('no such column: metadata', str(exc)) def tearDown(self): AccountBroker.create_account_stat_table = \ @@ -1149,12 +1149,12 @@ class TestAccountBrokerBeforeSPI(TestAccountBroker): conn.execute('SELECT storage_policy_index FROM container') except BaseException as err: exc = err - self.assertTrue('no such column: storage_policy_index' in str(exc)) + self.assertIn('no such column: storage_policy_index', str(exc)) with broker.get() as conn: try: conn.execute('SELECT * FROM policy_stat') except sqlite3.OperationalError as err: - self.assertTrue('no such table: policy_stat' in str(err)) + self.assertIn('no such table: policy_stat', str(err)) else: self.fail('database created with policy_stat table') @@ -1181,7 +1181,7 @@ class TestAccountBrokerBeforeSPI(TestAccountBroker): ''').fetchone()[0] except sqlite3.OperationalError as err: # confirm that the table really isn't there - self.assertTrue('no such table: policy_stat' in str(err)) + self.assertIn('no such table: policy_stat', str(err)) else: self.fail('broker did not raise sqlite3.OperationalError ' 'trying to select from policy_stat table!') @@ -1330,7 +1330,7 @@ class TestAccountBrokerBeforeSPI(TestAccountBroker): self.fail('mock exception was not raised') self.assertEqual(len(called), 1) - self.assertTrue('CREATE TABLE policy_stat' in called[0]) + self.assertIn('CREATE TABLE policy_stat', called[0]) # nothing was committed broker = AccountBroker(db_path, account='a') @@ -1338,7 +1338,7 @@ class TestAccountBrokerBeforeSPI(TestAccountBroker): try: conn.execute('SELECT * FROM policy_stat') except sqlite3.OperationalError as err: - self.assertTrue('no such table: policy_stat' in str(err)) + self.assertIn('no such table: policy_stat', str(err)) else: self.fail('half upgraded database!') container_count = conn.execute( @@ -1503,7 +1503,7 @@ class AccountBrokerPreTrackContainerCountSetup(object): ''').fetchone()[0] except sqlite3.OperationalError as err: # confirm that the column really isn't there - self.assertTrue('no such column: container_count' in str(err)) + self.assertIn('no such column: container_count', str(err)) else: self.fail('broker did not raise sqlite3.OperationalError ' 'trying to select container_count from policy_stat!') diff --git a/test/unit/account/test_server.py b/test/unit/account/test_server.py index 7520669f34..e2ff6f2cda 100644 --- a/test/unit/account/test_server.py +++ b/test/unit/account/test_server.py @@ -2046,7 +2046,7 @@ class TestAccountController(unittest.TestCase): self.assertEqual(resp.status_int // 100, 2) for key in resp.headers: if 'storage-policy' in key.lower(): - self.assertTrue(policy.name.lower() in key.lower()) + self.assertIn(policy.name.lower(), key.lower()) def test_multiple_policies_in_use(self): ts = itertools.count()