|
16 | 16 | from palindrome_products import smallest_palindrome, largest_palindrome |
17 | 17 |
|
18 | 18 |
|
19 | | -# Tests adapted from `problem-specifications//canonical-data.json` @ v1.0.0 |
| 19 | +# Tests adapted from `problem-specifications//canonical-data.json` @ v1.1.0 |
20 | 20 |
|
21 | 21 | class PalindromesTests(unittest.TestCase): |
22 | 22 | def test_smallest_palindrome_from_single_digit_factors(self): |
@@ -60,24 +60,32 @@ def test_largest_palindrome_from_four_digit_factors(self): |
60 | 60 | self.assertFactorsEqual(factors, {(9901, 9999)}) |
61 | 61 |
|
62 | 62 | def test_empty_for_smallest_palindrome_if_none_in_range(self): |
63 | | - with self.assertRaises(ValueError): |
| 63 | + with self.assertRaisesWithMessage(ValueError): |
64 | 64 | value, factors = smallest_palindrome(min_factor=1002, |
65 | 65 | max_factor=1003) |
66 | 66 |
|
67 | 67 | def test_empty_for_largest_palindrome_if_none_in_range(self): |
68 | | - with self.assertRaises(ValueError): |
| 68 | + with self.assertRaisesWithMessage(ValueError): |
69 | 69 | value, factors = largest_palindrome(min_factor=15, max_factor=15) |
70 | 70 |
|
71 | 71 | def test_error_for_smallest_if_min_is_more_than_max(self): |
72 | | - with self.assertRaises(ValueError): |
| 72 | + with self.assertRaisesWithMessage(ValueError): |
73 | 73 | value, factors = smallest_palindrome(min_factor=10000, |
74 | 74 | max_factor=1) |
75 | 75 |
|
76 | 76 | def test_error_for_largest_if_min_is_more_than_max(self): |
77 | | - with self.assertRaises(ValueError): |
| 77 | + with self.assertRaisesWithMessage(ValueError): |
78 | 78 | value, factors = largest_palindrome(min_factor=2, max_factor=1) |
79 | 79 |
|
80 | | - # Utility methods |
| 80 | + # Utility functions |
| 81 | + def setUp(self): |
| 82 | + try: |
| 83 | + self.assertRaisesRegex |
| 84 | + except AttributeError: |
| 85 | + self.assertRaisesRegex = self.assertRaisesRegexp |
| 86 | + |
| 87 | + def assertRaisesWithMessage(self, exception): |
| 88 | + return self.assertRaisesRegex(exception, r".+") |
81 | 89 |
|
82 | 90 | def assertFactorsEqual(self, actual, expected): |
83 | 91 | self.assertEqual(set(map(frozenset, actual)), |
|
0 commit comments