diff --git a/ensure/main.py b/ensure/main.py index f31fa75..66c163a 100644 --- a/ensure/main.py +++ b/ensure/main.py @@ -657,7 +657,7 @@ def raises_regex(self, expected_exception, expected_regexp): Ensures preceding predicates (specifically, :meth:`called_with()`) result in *expected_exception* being raised, and the string representation of *expected_exception* must match regular expression *expected_regexp*. """ - return unittest_case.assertRaisesRegexp( + return unittest_case.assertRaisesRegex( expected_exception, expected_regexp, self._orig_subject, *self._args, **self._kwargs ) @@ -937,4 +937,4 @@ def f(x: int, y: float) -> float: check = Check() ensure_raises = unittest_case.assertRaises -ensure_raises_regex = unittest_case.assertRaisesRegexp +ensure_raises_regex = unittest_case.assertRaisesRegex diff --git a/test/test.py b/test/test.py index 97fefc1..04eed24 100755 --- a/test/test.py +++ b/test/test.py @@ -245,21 +245,21 @@ def h(x: str, y: int): self.assertEqual(f(1, 2.3), 3.3) self.assertEqual(f(1, y=2.3), 3.3) self.assertEqual(f(y=1.2, x=3), 4.2) - with self.assertRaisesRegexp( + with self.assertRaisesRegex( EnsureError, "Argument y of type to does not match annotation type ", ): self.assertEqual(f(1, 2), 3.3) - with self.assertRaisesRegexp( + with self.assertRaisesRegex( EnsureError, "Argument y of type to does not match annotation type ", ): self.assertEqual(f(y=2, x=1), 3.3) - with self.assertRaisesRegexp( + with self.assertRaisesRegex( EnsureError, "Return value of does not match annotation type " ): self.assertEqual(f(1, -2.3), 4) - with self.assertRaisesRegexp( + with self.assertRaisesRegex( EnsureError, "Return value of does not match annotation type " ): self.assertEqual(f(x=1, y=-2.3), 4) @@ -291,7 +291,7 @@ def f(x: int, y: float=None) -> float: def g(x: str, y: str=5, z='untyped with default') -> str: return x+y+str(z) """ - with self.assertRaisesRegexp( + with self.assertRaisesRegex( EnsureError, "Default argument y of type to does not match annotation type ", ): @@ -321,7 +321,7 @@ def f(x: int, y: float, *args, z: int=5) -> float: self.assertEqual(2.0, f(3, 4.0)) self.assertEqual(62.0, f(3, 4.0, 10, 20, 30)) self.assertEqual(66.0, f(3, 4.0, 10, 20, 30, z=1)) - with self.assertRaisesRegexp( + with self.assertRaisesRegex( EnsureError, "Argument z of type to does not match annotation type ", ): @@ -350,7 +350,7 @@ def f(x: int, y: float, *args, z: int=5) -> str: self.assertEqual("2.0abc", f(3, 4.0, "abc")) self.assertEqual("2.0abc2.0def", f(3, 4.0, "abc", "def")) self.assertEqual("3.0abc3.0def", f(3, 4.0, "abc", "def", z=4)) - with self.assertRaisesRegexp( + with self.assertRaisesRegex( EnsureError, "Argument z of type to does not match annotation type ", ): @@ -372,7 +372,7 @@ def f(x: int, y: float, *args, z: int='not an int') -> str: return r """ - with self.assertRaisesRegexp( + with self.assertRaisesRegex( EnsureError, "Default argument z of type to does not match annotation type ", ): @@ -399,7 +399,7 @@ def g(self, x: int, y: float): c = C() self.assertEqual("3.3", c.f(1, 2.3)) self.assertRegex(repr(c.f), ">") - with self.assertRaisesRegexp( + with self.assertRaisesRegex( EnsureError, "Argument x of type to does not match annotation type ", ): @@ -407,14 +407,14 @@ def g(self, x: int, y: float): self.assertEqual("3.3", c.g(1, 2.3)) self.assertRegex(repr(c.g), ">") - with self.assertRaisesRegexp( + with self.assertRaisesRegex( EnsureError, "Argument x of type to does not match annotation type ", ): g = C().g(3.2, 1) def test_error_formatting(self): - with self.assertRaisesRegexp(Exception, "Major fail detected"): + with self.assertRaisesRegex(Exception, "Major fail detected"): check(False).is_true().or_raise(KeyError, "{} {error} detected", "Major", error="fail")