From d4da920d9b38a15eb04decc6b891b1dc1fae8355 Mon Sep 17 00:00:00 2001 From: Cao Xuan Hoang Date: Thu, 8 Dec 2016 15:44:48 +0700 Subject: [PATCH] Use assertGreater(len(x), 0) instead of assertTrue(len(x) > 0) assertGreater provides a nicer error message if it fails. Change-Id: I5b045042b5991280a5b6a12ccde09fa733a19e26 --- test/unit/common/middleware/test_xprofile.py | 2 +- test/unit/common/test_storage_policy.py | 2 +- test/unit/container/test_updater.py | 2 +- test/unit/obj/test_auditor.py | 4 ++-- test/unit/obj/test_diskfile.py | 4 ++-- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/test/unit/common/middleware/test_xprofile.py b/test/unit/common/middleware/test_xprofile.py index 720a722311..dbcc660245 100644 --- a/test/unit/common/middleware/test_xprofile.py +++ b/test/unit/common/middleware/test_xprofile.py @@ -78,7 +78,7 @@ class TestProfilers(unittest.TestCase): p.runctx('import os;os.getcwd();', globals(), locals()) p.snapshot_stats() self.assertTrue(p.stats is not None) - self.assertTrue(len(p.stats.keys()) > 0) + self.assertGreater(len(p.stats.keys()), 0) class TestProfileMiddleware(unittest.TestCase): diff --git a/test/unit/common/test_storage_policy.py b/test/unit/common/test_storage_policy.py index 5b9c38b913..57007ac1bf 100644 --- a/test/unit/common/test_storage_policy.py +++ b/test/unit/common/test_storage_policy.py @@ -130,7 +130,7 @@ class TestStoragePolicies(unittest.TestCase): self.assertEqual(policy_string, get_policy_string(*expected)) def test_defaults(self): - self.assertTrue(len(POLICIES) > 0) + self.assertGreater(len(POLICIES), 0) # test class functions default_policy = POLICIES.default diff --git a/test/unit/container/test_updater.py b/test/unit/container/test_updater.py index 0c9c128fef..576860d0de 100644 --- a/test/unit/container/test_updater.py +++ b/test/unit/container/test_updater.py @@ -105,7 +105,7 @@ class TestContainerUpdater(unittest.TestCase): cu.logger = FakeLogger() cu.run_once() log_lines = cu.logger.get_lines_for_level('warning') - self.assertTrue(len(log_lines) > 0) + self.assertGreater(len(log_lines), 0) msg = 'sda1 is not mounted' self.assertEqual(log_lines[0], msg) # Ensure that the container_sweep did not run diff --git a/test/unit/obj/test_auditor.py b/test/unit/obj/test_auditor.py index 3924d22d07..2c098294fa 100644 --- a/test/unit/obj/test_auditor.py +++ b/test/unit/obj/test_auditor.py @@ -604,7 +604,7 @@ class TestAuditor(unittest.TestCase): self.rcache, self.devices) auditor_worker.audit_all_objects(device_dirs=['sda']) log_lines = logger.get_lines_for_level('info') - self.assertTrue(len(log_lines) > 0) + self.assertGreater(len(log_lines), 0) self.assertTrue(log_lines[0].index('ALL - parallel, sda')) logger = FakeLogger() @@ -613,7 +613,7 @@ class TestAuditor(unittest.TestCase): zero_byte_only_at_fps=50) auditor_worker.audit_all_objects(device_dirs=['sda']) log_lines = logger.get_lines_for_level('info') - self.assertTrue(len(log_lines) > 0) + self.assertGreater(len(log_lines), 0) self.assertTrue(log_lines[0].index('ZBF - sda')) def test_object_run_once_no_sda(self): diff --git a/test/unit/obj/test_diskfile.py b/test/unit/obj/test_diskfile.py index 5739cf1dbe..f63e99c901 100644 --- a/test/unit/obj/test_diskfile.py +++ b/test/unit/obj/test_diskfile.py @@ -924,7 +924,7 @@ class DiskFileManagerMixin(BaseDiskFileTestMixin): mgr = diskfile.DiskFileManager(self.conf, logger) warnings = logger.get_lines_for_level('warning') - self.assertTrue(len(warnings) > 0) + self.assertGreater(len(warnings), 0) self.assertTrue('splice()' in warnings[-1]) self.assertFalse(mgr.use_splice) @@ -4671,7 +4671,7 @@ class DiskFileMixin(BaseDiskFileTestMixin): # Despite fs not supporting O_TMPFILE, use_linkat should not change self.assertTrue(df._use_linkat) log = df._logger.get_lines_for_level('warning') - self.assertTrue(len(log) > 0) + self.assertGreater(len(log), 0) self.assertTrue('O_TMPFILE' in log[-1]) @requires_o_tmpfile_support