Add test to validate the error strings in test_expirer

Improve test_get_process_values_* methods in obj/test_expirer in the
form assertRaises(ValueError, x.get_process_values,{}/vals), to use
the assertRaises context form.  This improves understandability by
validateing the error strings in addition to the ValueError.

Related-Change: I3d12b79470d122b2114f9ee486b15d381f290f95

Change-Id: I1c66b8894cba8328d19cf99491a8ad18ded71078
This commit is contained in:
zheng yin 2016-08-26 14:04:46 +08:00 committed by Clay Gerrard
parent a811fe0205
commit cd8eb6db91

View File

@ -89,10 +89,16 @@ class TestObjectExpirer(TestCase):
} }
# from config # from config
x = expirer.ObjectExpirer(vals) x = expirer.ObjectExpirer(vals)
self.assertRaises(ValueError, x.get_process_values, {}) expected_msg = 'process must be an integer greater' \
' than or equal to 0'
with self.assertRaises(ValueError) as ctx:
x.get_process_values({})
self.assertEqual(str(ctx.exception), expected_msg)
# from kwargs # from kwargs
x = expirer.ObjectExpirer({}) x = expirer.ObjectExpirer({})
self.assertRaises(ValueError, x.get_process_values, vals) with self.assertRaises(ValueError) as ctx:
x.get_process_values(vals)
self.assertEqual(str(ctx.exception), expected_msg)
def test_get_process_values_negative_processes(self): def test_get_process_values_negative_processes(self):
vals = { vals = {
@ -101,10 +107,16 @@ class TestObjectExpirer(TestCase):
} }
# from config # from config
x = expirer.ObjectExpirer(vals) x = expirer.ObjectExpirer(vals)
self.assertRaises(ValueError, x.get_process_values, {}) expected_msg = 'processes must be an integer greater' \
' than or equal to 0'
with self.assertRaises(ValueError) as ctx:
x.get_process_values({})
self.assertEqual(str(ctx.exception), expected_msg)
# from kwargs # from kwargs
x = expirer.ObjectExpirer({}) x = expirer.ObjectExpirer({})
self.assertRaises(ValueError, x.get_process_values, vals) with self.assertRaises(ValueError) as ctx:
x.get_process_values(vals)
self.assertEqual(str(ctx.exception), expected_msg)
def test_get_process_values_process_greater_than_processes(self): def test_get_process_values_process_greater_than_processes(self):
vals = { vals = {
@ -113,10 +125,15 @@ class TestObjectExpirer(TestCase):
} }
# from config # from config
x = expirer.ObjectExpirer(vals) x = expirer.ObjectExpirer(vals)
self.assertRaises(ValueError, x.get_process_values, {}) expected_msg = 'process must be less than processes'
with self.assertRaises(ValueError) as ctx:
x.get_process_values({})
self.assertEqual(str(ctx.exception), expected_msg)
# from kwargs # from kwargs
x = expirer.ObjectExpirer({}) x = expirer.ObjectExpirer({})
self.assertRaises(ValueError, x.get_process_values, vals) with self.assertRaises(ValueError) as ctx:
x.get_process_values(vals)
self.assertEqual(str(ctx.exception), expected_msg)
def test_get_process_values_process_equal_to_processes(self): def test_get_process_values_process_equal_to_processes(self):
vals = { vals = {