diff options
author | Jonathan Vanasco <jonathan@2xlp.com> | 2020-01-08 22:42:39 -0500 |
---|---|---|
committer | Benjamin Peterson <benjamin@python.org> | 2020-01-08 19:42:39 -0800 |
commit | 10a2b75b8be7b68eacfa168834d9938b77d2d7e3 (patch) | |
tree | b432f365a335b5d66e90e8af5b2156deb84e00b8 | |
parent | 5cd83db203a9f4bffd401e77a48543669548a94e (diff) | |
download | six-git-10a2b75b8be7b68eacfa168834d9938b77d2d7e3.tar.gz |
Add assertNotRegex. (#289)
Fixes #288.
Co-authored-by: Benjamin Peterson <benjamin@python.org>
-rw-r--r-- | documentation/index.rst | 5 | ||||
-rw-r--r-- | six.py | 7 | ||||
-rw-r--r-- | test_six.py | 11 |
3 files changed, 23 insertions, 0 deletions
diff --git a/documentation/index.rst b/documentation/index.rst index e5e2994..e2e82e3 100644 --- a/documentation/index.rst +++ b/documentation/index.rst @@ -510,6 +510,11 @@ Note these functions are only available on Python 2.7 or later. Alias for :meth:`~py3:unittest.TestCase.assertRegex` on Python 3 and :meth:`~py2:unittest.TestCase.assertRegexpMatches` on Python 2. +.. function:: assertNotRegex() + + Alias for :meth:`~py3:unittest.TestCase.assertNotRegex` on Python 3 and + :meth:`~py2:unittest.TestCase.assertNotRegexpMatches` on Python 2. + Renamed modules and attributes compatibility >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> @@ -644,9 +644,11 @@ if PY3: if sys.version_info[1] <= 1: _assertRaisesRegex = "assertRaisesRegexp" _assertRegex = "assertRegexpMatches" + _assertNotRegex = "assertNotRegexpMatches" else: _assertRaisesRegex = "assertRaisesRegex" _assertRegex = "assertRegex" + _assertNotRegex = "assertNotRegex" else: def b(s): return s @@ -668,6 +670,7 @@ else: _assertCountEqual = "assertItemsEqual" _assertRaisesRegex = "assertRaisesRegexp" _assertRegex = "assertRegexpMatches" + _assertNotRegex = "assertNotRegexpMatches" _add_doc(b, """Byte literal""") _add_doc(u, """Text literal""") @@ -684,6 +687,10 @@ def assertRegex(self, *args, **kwargs): return getattr(self, _assertRegex)(*args, **kwargs) +def assertNotRegex(self, *args, **kwargs): + return getattr(self, _assertNotRegex)(*args, **kwargs) + + if PY3: exec_ = getattr(moves.builtins, "exec") diff --git a/test_six.py b/test_six.py index 2cd2112..7b8b03b 100644 --- a/test_six.py +++ b/test_six.py @@ -938,6 +938,17 @@ def test_assertRegex(): TestAssertRegex('test').test() +def test_assertNotRegex(): + class TestAssertNotRegex(unittest.TestCase): + def test(self): + with self.assertRaises(AssertionError): + six.assertNotRegex(self, 'test', r'^t') + + six.assertNotRegex(self, 'test', r'^a') + + TestAssertNotRegex('test').test() + + def test_assertRaisesRegex(): class TestAssertRaisesRegex(unittest.TestCase): def test(self): |