Use better predicates from testtools instead of plain assert

Change-Id: I8c9b05db59cc08a5668871d4ce305856c659b833
This commit is contained in:
Noorul Islam K M 2013-11-09 23:11:00 +05:30
parent c40b23f9ec
commit 61028b4cd5
9 changed files with 53 additions and 53 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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