diff options
author | Ezio Melotti <ezio.melotti@gmail.com> | 2010-12-01 02:32:32 (GMT) |
---|---|---|
committer | Ezio Melotti <ezio.melotti@gmail.com> | 2010-12-01 02:32:32 (GMT) |
commit | ed3a7d2d601ce1e65b0bacf24676440631158ec8 (patch) | |
tree | d8e7df73bc7d9aa2c3cfafd4adb9838dffcea230 /Lib/unittest/test | |
parent | f10c400b91e44c5c744f4ddc05d90933cba3a56b (diff) | |
download | cpython-ed3a7d2d601ce1e65b0bacf24676440631158ec8.zip cpython-ed3a7d2d601ce1e65b0bacf24676440631158ec8.tar.gz cpython-ed3a7d2d601ce1e65b0bacf24676440631158ec8.tar.bz2 |
#10273: Rename assertRegexpMatches and assertRaisesRegexp to assertRegex and assertRaisesRegex.
Diffstat (limited to 'Lib/unittest/test')
-rw-r--r-- | Lib/unittest/test/test_assertions.py | 14 | ||||
-rw-r--r-- | Lib/unittest/test/test_case.py | 72 | ||||
-rw-r--r-- | Lib/unittest/test/test_discovery.py | 2 | ||||
-rw-r--r-- | Lib/unittest/test/test_loader.py | 2 | ||||
-rw-r--r-- | Lib/unittest/test/test_setups.py | 2 |
5 files changed, 47 insertions, 45 deletions
diff --git a/Lib/unittest/test/test_assertions.py b/Lib/unittest/test/test_assertions.py index 6a30db6..0ee7edb 100644 --- a/Lib/unittest/test/test_assertions.py +++ b/Lib/unittest/test/test_assertions.py @@ -92,15 +92,15 @@ class Test_Assertions(unittest.TestCase): else: self.fail("assertRaises() didn't let exception pass through") - def testAssertNotRegexpMatches(self): - self.assertNotRegexpMatches('Ala ma kota', r'r+') + def testAssertNotRegexMatches(self): + self.assertNotRegexMatches('Ala ma kota', r'r+') try: - self.assertNotRegexpMatches('Ala ma kota', r'k.t', 'Message') + self.assertNotRegexMatches('Ala ma kota', r'k.t', 'Message') except self.failureException as e: self.assertIn("'kot'", e.args[0]) self.assertIn('Message', e.args[0]) else: - self.fail('assertNotRegexpMatches should have failed.') + self.fail('assertNotRegexMatches should have failed.') class TestLongMessage(unittest.TestCase): @@ -153,15 +153,15 @@ class TestLongMessage(unittest.TestCase): test = self.testableTrue return getattr(test, methodName) - for i, expected_regexp in enumerate(errors): + for i, expected_regex in enumerate(errors): testMethod = getMethod(i) kwargs = {} withMsg = i % 2 if withMsg: kwargs = {"msg": "oops"} - with self.assertRaisesRegexp(self.failureException, - expected_regexp=expected_regexp): + with self.assertRaisesRegex(self.failureException, + expected_regex=expected_regex): testMethod(*args, **kwargs) def testAssertTrue(self): diff --git a/Lib/unittest/test/test_case.py b/Lib/unittest/test/test_case.py index aa8cc37..a56baa1 100644 --- a/Lib/unittest/test/test_case.py +++ b/Lib/unittest/test/test_case.py @@ -872,44 +872,44 @@ test case self.assertIsNotNone('DjZoPloGears on Rails') self.assertRaises(self.failureException, self.assertIsNotNone, None) - def testAssertRegexpMatches(self): - self.assertRegexpMatches('asdfabasdf', r'ab+') - self.assertRaises(self.failureException, self.assertRegexpMatches, + def testAssertRegex(self): + self.assertRegex('asdfabasdf', r'ab+') + self.assertRaises(self.failureException, self.assertRegex, 'saaas', r'aaaa') - def testAssertRaisesRegexp(self): + def testAssertRaisesRegex(self): class ExceptionMock(Exception): pass def Stub(): raise ExceptionMock('We expect') - self.assertRaisesRegexp(ExceptionMock, re.compile('expect$'), Stub) - self.assertRaisesRegexp(ExceptionMock, 'expect$', Stub) + self.assertRaisesRegex(ExceptionMock, re.compile('expect$'), Stub) + self.assertRaisesRegex(ExceptionMock, 'expect$', Stub) - def testAssertNotRaisesRegexp(self): - self.assertRaisesRegexp( + def testAssertNotRaisesRegex(self): + self.assertRaisesRegex( self.failureException, '^Exception not raised by <lambda>$', - self.assertRaisesRegexp, Exception, re.compile('x'), + self.assertRaisesRegex, Exception, re.compile('x'), lambda: None) - self.assertRaisesRegexp( + self.assertRaisesRegex( self.failureException, '^Exception not raised by <lambda>$', - self.assertRaisesRegexp, Exception, 'x', + self.assertRaisesRegex, Exception, 'x', lambda: None) - def testAssertRaisesRegexpMismatch(self): + def testAssertRaisesRegexMismatch(self): def Stub(): raise Exception('Unexpected') - self.assertRaisesRegexp( + self.assertRaisesRegex( self.failureException, r'"\^Expected\$" does not match "Unexpected"', - self.assertRaisesRegexp, Exception, '^Expected$', + self.assertRaisesRegex, Exception, '^Expected$', Stub) - self.assertRaisesRegexp( + self.assertRaisesRegex( self.failureException, r'"\^Expected\$" does not match "Unexpected"', - self.assertRaisesRegexp, Exception, + self.assertRaisesRegex, Exception, re.compile('^Expected$'), Stub) def testAssertRaisesExcValue(self): @@ -993,26 +993,26 @@ test case with self.assertWarns(DeprecationWarning): _runtime_warn() - def testAssertWarnsRegexpCallable(self): + def testAssertWarnsRegexCallable(self): def _runtime_warn(msg): warnings.warn(msg, RuntimeWarning) - self.assertWarnsRegexp(RuntimeWarning, "o+", - _runtime_warn, "foox") + self.assertWarnsRegex(RuntimeWarning, "o+", + _runtime_warn, "foox") # Failure when no warning is triggered with self.assertRaises(self.failureException): - self.assertWarnsRegexp(RuntimeWarning, "o+", - lambda: 0) + self.assertWarnsRegex(RuntimeWarning, "o+", + lambda: 0) # Failure when another warning is triggered with warnings.catch_warnings(): # Force default filter (in case tests are run with -We) warnings.simplefilter("default", RuntimeWarning) with self.assertRaises(self.failureException): - self.assertWarnsRegexp(DeprecationWarning, "o+", - _runtime_warn, "foox") + self.assertWarnsRegex(DeprecationWarning, "o+", + _runtime_warn, "foox") # Failure when message doesn't match with self.assertRaises(self.failureException): - self.assertWarnsRegexp(RuntimeWarning, "o+", - _runtime_warn, "barz") + self.assertWarnsRegex(RuntimeWarning, "o+", + _runtime_warn, "barz") # A little trickier: we ask RuntimeWarnings to be raised, and then # check for some of them. It is implementation-defined whether # non-matching RuntimeWarnings are simply re-raised, or produce a @@ -1020,15 +1020,15 @@ test case with warnings.catch_warnings(): warnings.simplefilter("error", RuntimeWarning) with self.assertRaises((RuntimeWarning, self.failureException)): - self.assertWarnsRegexp(RuntimeWarning, "o+", - _runtime_warn, "barz") + self.assertWarnsRegex(RuntimeWarning, "o+", + _runtime_warn, "barz") - def testAssertWarnsRegexpContext(self): - # Same as above, but with assertWarnsRegexp as a context manager + def testAssertWarnsRegexContext(self): + # Same as above, but with assertWarnsRegex as a context manager def _runtime_warn(msg): warnings.warn(msg, RuntimeWarning) _runtime_warn_lineno = inspect.getsourcelines(_runtime_warn)[1] - with self.assertWarnsRegexp(RuntimeWarning, "o+") as cm: + with self.assertWarnsRegex(RuntimeWarning, "o+") as cm: _runtime_warn("foox") self.assertIsInstance(cm.warning, RuntimeWarning) self.assertEqual(cm.warning.args[0], "foox") @@ -1036,18 +1036,18 @@ test case self.assertEqual(cm.lineno, _runtime_warn_lineno + 1) # Failure when no warning is triggered with self.assertRaises(self.failureException): - with self.assertWarnsRegexp(RuntimeWarning, "o+"): + with self.assertWarnsRegex(RuntimeWarning, "o+"): pass # Failure when another warning is triggered with warnings.catch_warnings(): # Force default filter (in case tests are run with -We) warnings.simplefilter("default", RuntimeWarning) with self.assertRaises(self.failureException): - with self.assertWarnsRegexp(DeprecationWarning, "o+"): + with self.assertWarnsRegex(DeprecationWarning, "o+"): _runtime_warn("foox") # Failure when message doesn't match with self.assertRaises(self.failureException): - with self.assertWarnsRegexp(RuntimeWarning, "o+"): + with self.assertWarnsRegex(RuntimeWarning, "o+"): _runtime_warn("barz") # A little trickier: we ask RuntimeWarnings to be raised, and then # check for some of them. It is implementation-defined whether @@ -1056,7 +1056,7 @@ test case with warnings.catch_warnings(): warnings.simplefilter("error", RuntimeWarning) with self.assertRaises((RuntimeWarning, self.failureException)): - with self.assertWarnsRegexp(RuntimeWarning, "o+"): + with self.assertWarnsRegex(RuntimeWarning, "o+"): _runtime_warn("barz") def testDeprecatedMethodNames(self): @@ -1078,7 +1078,9 @@ test case (self.assert_, (True,)), (self.failUnlessRaises, (TypeError, lambda _: 3.14 + 'spam')), (self.failIf, (False,)), - (self.assertSameElements, ([1, 1, 2, 3], [1, 2, 3])) + (self.assertSameElements, ([1, 1, 2, 3], [1, 2, 3])), + (self.assertRaisesRegexp, (KeyError, 'foo', lambda: {}['foo'])), + (self.assertRegexpMatches, ('bar', 'bar')), ) for meth, args in old: with self.assertWarns(DeprecationWarning): diff --git a/Lib/unittest/test/test_discovery.py b/Lib/unittest/test/test_discovery.py index 5dcbda4..52a711a 100644 --- a/Lib/unittest/test/test_discovery.py +++ b/Lib/unittest/test/test_discovery.py @@ -354,7 +354,7 @@ class TestDiscovery(unittest.TestCase): expected_dir = os.path.abspath('foo') msg = re.escape(r"'foo' module incorrectly imported from %r. Expected %r. " "Is this module globally installed?" % (mod_dir, expected_dir)) - self.assertRaisesRegexp( + self.assertRaisesRegex( ImportError, '^%s$' % msg, loader.discover, start_dir='foo', pattern='foo.py' ) diff --git a/Lib/unittest/test/test_loader.py b/Lib/unittest/test/test_loader.py index 2fa1d50..f7e31a5 100644 --- a/Lib/unittest/test/test_loader.py +++ b/Lib/unittest/test/test_loader.py @@ -186,7 +186,7 @@ class Test_TestLoader(unittest.TestCase): self.assertEqual(suite.countTestCases(), 1) test = list(suite)[0] - self.assertRaisesRegexp(TypeError, "some failure", test.m) + self.assertRaisesRegex(TypeError, "some failure", test.m) ################################################################ ### /Tests for TestLoader.loadTestsFromModule() diff --git a/Lib/unittest/test/test_setups.py b/Lib/unittest/test/test_setups.py index eda3068..b8d5aa4 100644 --- a/Lib/unittest/test/test_setups.py +++ b/Lib/unittest/test/test_setups.py @@ -500,7 +500,7 @@ class TestSetups(unittest.TestCase): messages = ('setUpModule', 'tearDownModule', 'setUpClass', 'tearDownClass', 'test_something') for phase, msg in enumerate(messages): - with self.assertRaisesRegexp(Exception, msg): + with self.assertRaisesRegex(Exception, msg): suite.debug() if __name__ == '__main__': |