From cd8eb6db9188359039c1f13e34397cb9b24b8112 Mon Sep 17 00:00:00 2001 From: zheng yin Date: Fri, 26 Aug 2016 14:04:46 +0800 Subject: [PATCH] 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 --- test/unit/obj/test_expirer.py | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/test/unit/obj/test_expirer.py b/test/unit/obj/test_expirer.py index fbf711af06..4830a908c3 100644 --- a/test/unit/obj/test_expirer.py +++ b/test/unit/obj/test_expirer.py @@ -89,10 +89,16 @@ class TestObjectExpirer(TestCase): } # from config 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 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): vals = { @@ -101,10 +107,16 @@ class TestObjectExpirer(TestCase): } # from config 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 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): vals = { @@ -113,10 +125,15 @@ class TestObjectExpirer(TestCase): } # from config 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 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): vals = {