From 61028b4cd512a263c3dde1dca5c412a74fb02a14 Mon Sep 17 00:00:00 2001 From: Noorul Islam K M Date: Sat, 9 Nov 2013 23:11:00 +0530 Subject: [PATCH] Use better predicates from testtools instead of plain assert Change-Id: I8c9b05db59cc08a5668871d4ce305856c659b833 --- ..._compute_duration_by_resource_scenarios.py | 16 ++++----- .../v1/test_max_project_volume_scenarios.py | 12 +++---- .../v1/test_max_resource_volume_scenarios.py | 12 +++---- .../v1/test_sum_project_volume_scenarios.py | 12 +++---- .../v1/test_sum_resource_volume_scenarios.py | 12 +++---- ..._compute_duration_by_resource_scenarios.py | 2 +- tests/api/v2/test_statistics.py | 34 +++++++++---------- tests/compute/pollsters/test_cpu.py | 2 +- tests/compute/pollsters/test_diskio.py | 4 +-- 9 files changed, 53 insertions(+), 53 deletions(-) diff --git a/tests/api/v1/test_compute_duration_by_resource_scenarios.py b/tests/api/v1/test_compute_duration_by_resource_scenarios.py index f011f1db7..1d61823ff 100644 --- a/tests/api/v1/test_compute_duration_by_resource_scenarios.py +++ b/tests/api/v1/test_compute_duration_by_resource_scenarios.py @@ -83,13 +83,13 @@ class TestComputeDurationByResource(tests_api.TestBase, def test_before_range(self): self._set_stats(self.early1, self.early2) data = self._invoke_api() - assert data['start_timestamp'] is None - assert data['end_timestamp'] is None - assert data['duration'] is None + self.assertIsNone(data['start_timestamp']) + self.assertIsNone(data['end_timestamp']) + self.assertIsNone(data['duration']) def _assert_times_match(self, actual, expected): actual = timeutils.parse_isotime(actual).replace(tzinfo=None) - assert actual == expected + self.assertEqual(actual, expected) def test_overlap_range_start(self): self._set_stats(self.early1, self.middle1) @@ -110,7 +110,7 @@ class TestComputeDurationByResource(tests_api.TestBase, data = self._invoke_api() self._assert_times_match(data['start_timestamp'], self.middle1) self._assert_times_match(data['end_timestamp'], self.middle1) - assert data['duration'] == 0 + self.assertEqual(data['duration'], 0) def test_overlap_range_end(self): self._set_stats(self.middle2, self.late1) @@ -122,9 +122,9 @@ class TestComputeDurationByResource(tests_api.TestBase, def test_after_range(self): self._set_stats(self.late1, self.late2) data = self._invoke_api() - assert data['start_timestamp'] is None - assert data['end_timestamp'] is None - assert data['duration'] is None + self.assertIsNone(data['start_timestamp']) + self.assertIsNone(data['end_timestamp']) + self.assertIsNone(data['duration']) def test_without_end_timestamp(self): self._set_stats(self.late1, self.late2) diff --git a/tests/api/v1/test_max_project_volume_scenarios.py b/tests/api/v1/test_max_project_volume_scenarios.py index 86d3d42bb..25e513041 100644 --- a/tests/api/v1/test_max_project_volume_scenarios.py +++ b/tests/api/v1/test_max_project_volume_scenarios.py @@ -60,7 +60,7 @@ class TestMaxProjectVolume(tests_api.TestBase, def test_no_time_bounds(self): data = self.get('/projects/project1/meters/volume.size/volume/max') expected = {'volume': 7} - assert data == expected + self.assertEqual(data, expected) def test_no_time_bounds_non_admin(self): data = self.get('/projects/project1/meters/volume.size/volume/max', @@ -78,29 +78,29 @@ class TestMaxProjectVolume(tests_api.TestBase, data = self.get('/projects/project1/meters/volume.size/volume/max', start_timestamp='2012-09-25T11:30:00') expected = {'volume': 7} - assert data == expected + self.assertEqual(data, expected) def test_start_timestamp_after(self): data = self.get('/projects/project1/meters/volume.size/volume/max', start_timestamp='2012-09-25T12:34:00') expected = {'volume': None} - assert data == expected + self.assertEqual(data, expected) def test_end_timestamp(self): data = self.get('/projects/project1/meters/volume.size/volume/max', end_timestamp='2012-09-25T11:30:00') expected = {'volume': 5} - assert data == expected + self.assertEqual(data, expected) def test_end_timestamp_before(self): data = self.get('/projects/project1/meters/volume.size/volume/max', end_timestamp='2012-09-25T09:54:00') expected = {'volume': None} - assert data == expected + self.assertEqual(data, expected) def test_start_end_timestamp(self): data = self.get('/projects/project1/meters/volume.size/volume/max', start_timestamp='2012-09-25T11:30:00', end_timestamp='2012-09-25T11:32:00') expected = {'volume': 6} - assert data == expected + self.assertEqual(data, expected) diff --git a/tests/api/v1/test_max_resource_volume_scenarios.py b/tests/api/v1/test_max_resource_volume_scenarios.py index d6c8dc134..b6aec03d6 100644 --- a/tests/api/v1/test_max_resource_volume_scenarios.py +++ b/tests/api/v1/test_max_resource_volume_scenarios.py @@ -59,7 +59,7 @@ class TestMaxResourceVolume(tests_api.TestBase, def test_no_time_bounds(self): data = self.get('/resources/resource-id/meters/volume.size/volume/max') expected = {'volume': 7} - assert data == expected + self.assertEqual(data, expected) def test_no_time_bounds_non_admin(self): data = self.get('/resources/resource-id/meters/volume.size/volume/max', @@ -77,29 +77,29 @@ class TestMaxResourceVolume(tests_api.TestBase, data = self.get('/resources/resource-id/meters/volume.size/volume/max', start_timestamp='2012-09-25T11:30:00') expected = {'volume': 7} - assert data == expected + self.assertEqual(data, expected) def test_start_timestamp_after(self): data = self.get('/resources/resource-id/meters/volume.size/volume/max', start_timestamp='2012-09-25T12:34:00') expected = {'volume': None} - assert data == expected + self.assertEqual(data, expected) def test_end_timestamp(self): data = self.get('/resources/resource-id/meters/volume.size/volume/max', end_timestamp='2012-09-25T11:30:00') expected = {'volume': 5} - assert data == expected + self.assertEqual(data, expected) def test_end_timestamp_before(self): data = self.get('/resources/resource-id/meters/volume.size/volume/max', end_timestamp='2012-09-25T09:54:00') expected = {'volume': None} - assert data == expected + self.assertEqual(data, expected) def test_start_end_timestamp(self): data = self.get('/resources/resource-id/meters/volume.size/volume/max', start_timestamp='2012-09-25T11:30:00', end_timestamp='2012-09-25T11:32:00') expected = {'volume': 6} - assert data == expected + self.assertEqual(data, expected) diff --git a/tests/api/v1/test_sum_project_volume_scenarios.py b/tests/api/v1/test_sum_project_volume_scenarios.py index 68717bd2e..c120c5bfb 100644 --- a/tests/api/v1/test_sum_project_volume_scenarios.py +++ b/tests/api/v1/test_sum_project_volume_scenarios.py @@ -60,7 +60,7 @@ class TestSumProjectVolume(tests_api.TestBase, def test_no_time_bounds(self): data = self.get('/projects/project1/meters/volume.size/volume/sum') expected = {'volume': 5 + 6 + 7} - assert data == expected + self.assertEqual(data, expected) def test_no_time_bounds_non_admin(self): data = self.get('/projects/project1/meters/volume.size/volume/sum', @@ -78,29 +78,29 @@ class TestSumProjectVolume(tests_api.TestBase, data = self.get('/projects/project1/meters/volume.size/volume/sum', start_timestamp='2012-09-25T11:30:00') expected = {'volume': 6 + 7} - assert data == expected + self.assertEqual(data, expected) def test_start_timestamp_after(self): data = self.get('/projects/project1/meters/volume.size/volume/sum', start_timestamp='2012-09-25T12:34:00') expected = {'volume': None} - assert data == expected + self.assertEqual(data, expected) def test_end_timestamp(self): data = self.get('/projects/project1/meters/volume.size/volume/sum', end_timestamp='2012-09-25T11:30:00') expected = {'volume': 5} - assert data == expected + self.assertEqual(data, expected) def test_end_timestamp_before(self): data = self.get('/projects/project1/meters/volume.size/volume/sum', end_timestamp='2012-09-25T09:54:00') expected = {'volume': None} - assert data == expected + self.assertEqual(data, expected) def test_start_end_timestamp(self): data = self.get('/projects/project1/meters/volume.size/volume/sum', start_timestamp='2012-09-25T11:30:00', end_timestamp='2012-09-25T11:32:00') expected = {'volume': 6} - assert data == expected + self.assertEqual(data, expected) diff --git a/tests/api/v1/test_sum_resource_volume_scenarios.py b/tests/api/v1/test_sum_resource_volume_scenarios.py index 113775623..952e21a1f 100644 --- a/tests/api/v1/test_sum_resource_volume_scenarios.py +++ b/tests/api/v1/test_sum_resource_volume_scenarios.py @@ -60,7 +60,7 @@ class TestSumResourceVolume(tests_api.TestBase, def test_no_time_bounds(self): data = self.get('/resources/resource-id/meters/volume.size/volume/sum') expected = {'volume': 5 + 6 + 7} - assert data == expected + self.assertEqual(data, expected) def test_no_time_bounds_non_admin(self): data = self.get('/resources/resource-id/meters/volume.size/volume/sum', @@ -78,29 +78,29 @@ class TestSumResourceVolume(tests_api.TestBase, data = self.get('/resources/resource-id/meters/volume.size/volume/sum', start_timestamp='2012-09-25T11:30:00') expected = {'volume': 6 + 7} - assert data == expected + self.assertEqual(data, expected) def test_start_timestamp_after(self): data = self.get('/resources/resource-id/meters/volume.size/volume/sum', start_timestamp='2012-09-25T12:34:00') expected = {'volume': None} - assert data == expected + self.assertEqual(data, expected) def test_end_timestamp(self): data = self.get('/resources/resource-id/meters/volume.size/volume/sum', end_timestamp='2012-09-25T11:30:00') expected = {'volume': 5} - assert data == expected + self.assertEqual(data, expected) def test_end_timestamp_before(self): data = self.get('/resources/resource-id/meters/volume.size/volume/sum', end_timestamp='2012-09-25T09:54:00') expected = {'volume': None} - assert data == expected + self.assertEqual(data, expected) def test_start_end_timestamp(self): data = self.get('/resources/resource-id/meters/volume.size/volume/sum', start_timestamp='2012-09-25T11:30:00', end_timestamp='2012-09-25T11:32:00') expected = {'volume': 6} - assert data == expected + self.assertEqual(data, expected) diff --git a/tests/api/v2/test_compute_duration_by_resource_scenarios.py b/tests/api/v2/test_compute_duration_by_resource_scenarios.py index 1f9b0a98d..97b2fa1f6 100644 --- a/tests/api/v2/test_compute_duration_by_resource_scenarios.py +++ b/tests/api/v2/test_compute_duration_by_resource_scenarios.py @@ -106,7 +106,7 @@ class TestComputeDurationByResource(FunctionalTest, if actual: actual = timeutils.parse_isotime(actual) actual = actual.replace(tzinfo=None) - assert actual == expected + self.assertEqual(actual, expected) def test_overlap_range_start(self): self._set_interval(self.early1, self.middle1) diff --git a/tests/api/v2/test_statistics.py b/tests/api/v2/test_statistics.py index 9a415d476..18bd73a7e 100644 --- a/tests/api/v2/test_statistics.py +++ b/tests/api/v2/test_statistics.py @@ -50,9 +50,9 @@ class TestStatisticsDuration(test.BaseTestCase): start_timestamp=None, end_timestamp=None, ) - assert s.duration_start is None - assert s.duration_end is None - assert s.duration is None + self.assertIsNone(s.duration_start) + self.assertIsNone(s.duration_end) + self.assertIsNone(s.duration) def test_overlap_range_start(self): s = v2.Statistics(duration_start=self.early1, @@ -60,8 +60,8 @@ class TestStatisticsDuration(test.BaseTestCase): start_timestamp=self.start, end_timestamp=self.end, ) - assert s.duration_start == self.start - assert s.duration_end == self.middle1 + self.assertEqual(s.duration_start, self.start) + self.assertEqual(s.duration_end, self.middle1) self.assertEqual(s.duration, 8 * 60 * 60) def test_within_range(self): @@ -70,8 +70,8 @@ class TestStatisticsDuration(test.BaseTestCase): start_timestamp=self.start, end_timestamp=self.end, ) - assert s.duration_start == self.middle1 - assert s.duration_end == self.middle2 + self.assertEqual(s.duration_start, self.middle1) + self.assertEqual(s.duration_end, self.middle2) self.assertEqual(s.duration, 10 * 60 * 60) def test_within_range_zero_duration(self): @@ -80,9 +80,9 @@ class TestStatisticsDuration(test.BaseTestCase): start_timestamp=self.start, end_timestamp=self.end, ) - assert s.duration_start == self.middle1 - assert s.duration_end == self.middle1 - assert s.duration == 0 + self.assertEqual(s.duration_start, self.middle1) + self.assertEqual(s.duration_end, self.middle1) + self.assertEqual(s.duration, 0) def test_overlap_range_end(self): s = v2.Statistics(duration_start=self.middle2, @@ -90,8 +90,8 @@ class TestStatisticsDuration(test.BaseTestCase): start_timestamp=self.start, end_timestamp=self.end, ) - assert s.duration_start == self.middle2 - assert s.duration_end == self.end + self.assertEqual(s.duration_start, self.middle2) + self.assertEqual(s.duration_end, self.end) self.assertEqual(s.duration, ((6 * 60) - 1) * 60) def test_after_range(self): @@ -100,9 +100,9 @@ class TestStatisticsDuration(test.BaseTestCase): start_timestamp=self.start, end_timestamp=self.end, ) - assert s.duration_start is None - assert s.duration_end is None - assert s.duration is None + self.assertIsNone(s.duration_start) + self.assertIsNone(s.duration_end) + self.assertIsNone(s.duration) def test_without_timestamp(self): s = v2.Statistics(duration_start=self.late1, @@ -110,5 +110,5 @@ class TestStatisticsDuration(test.BaseTestCase): start_timestamp=None, end_timestamp=None, ) - assert s.duration_start == self.late1 - assert s.duration_end == self.late2 + self.assertEqual(s.duration_start, self.late1) + self.assertEqual(s.duration_end, self.late2) diff --git a/tests/compute/pollsters/test_cpu.py b/tests/compute/pollsters/test_cpu.py index 3d8881810..1c111076f 100644 --- a/tests/compute/pollsters/test_cpu.py +++ b/tests/compute/pollsters/test_cpu.py @@ -58,7 +58,7 @@ class TestCPUPollster(base.TestPollsterBase): self.assertEqual(len(samples), 1) self.assertEqual(set([s.name for s in samples]), set(['cpu'])) - assert samples[0].volume == expected_time + self.assertEqual(samples[0].volume, expected_time) self.assertEqual(samples[0].resource_metadata.get('cpu_number'), 2) # ensure elapsed time between polling cycles is non-zero time.sleep(0.001) diff --git a/tests/compute/pollsters/test_diskio.py b/tests/compute/pollsters/test_diskio.py index 37c4dc8cd..be0b6a114 100644 --- a/tests/compute/pollsters/test_diskio.py +++ b/tests/compute/pollsters/test_diskio.py @@ -48,8 +48,8 @@ class TestDiskPollsters(base.TestPollsterBase): cache = {} samples = list(pollster.get_samples(mgr, cache, self.instance)) assert samples - assert pollster.CACHE_KEY_DISK in cache - assert self.instance.name in cache[pollster.CACHE_KEY_DISK] + self.assertIn(pollster.CACHE_KEY_DISK, cache) + self.assertIn(self.instance.name, cache[pollster.CACHE_KEY_DISK]) self.assertEqual(set([s.name for s in samples]), set([name]))