[Python-checkins] r79632 - in python/trunk: Lib/unittest/case.py Lib/unittest/test/test_assertions.py Misc/NEWS
michael.foord
python-checkins at python.org
Sat Apr 3 00:55:59 CEST 2010
Author: michael.foord
Date: Sat Apr 3 00:55:59 2010
New Revision: 79632
Log:
Issue #8038: Addition of unittest.TestCase.assertNotRegexpMatches
Modified:
python/trunk/Lib/unittest/case.py
python/trunk/Lib/unittest/test/test_assertions.py
python/trunk/Misc/NEWS
Modified: python/trunk/Lib/unittest/case.py
==============================================================================
--- python/trunk/Lib/unittest/case.py (original)
+++ python/trunk/Lib/unittest/case.py Sat Apr 3 00:55:59 2010
@@ -952,6 +952,18 @@
msg = '%s: %r not found in %r' % (msg, expected_regexp.pattern, text)
raise self.failureException(msg)
+ def assertNotRegexpMatches(self, text, unexpected_regexp, msg=None):
+ if isinstance(unexpected_regexp, basestring):
+ unexpected_regexp = re.compile(unexpected_regexp)
+ match = unexpected_regexp.search(text)
+ if match:
+ msg = msg or "Regexp matched"
+ msg = '%s: %r matches %r in %r' % (msg,
+ text[match.start():match.end()],
+ unexpected_regexp.pattern,
+ text)
+ raise self.failureException(msg)
+
class FunctionTestCase(TestCase):
"""A test case that wraps a test function.
Modified: python/trunk/Lib/unittest/test/test_assertions.py
==============================================================================
--- python/trunk/Lib/unittest/test/test_assertions.py (original)
+++ python/trunk/Lib/unittest/test/test_assertions.py Sat Apr 3 00:55:59 2010
@@ -91,6 +91,16 @@
else:
self.fail("assertRaises() didn't let exception pass through")
+ def testAssertNotRegexpMatches(self):
+ self.assertNotRegexpMatches('Ala ma kota', r'r+')
+ try:
+ self.assertNotRegexpMatches('Ala ma kota', r'k.t', 'Message')
+ except self.failureException, e:
+ self.assertIn("'kot'", e.args[0])
+ self.assertIn('Message', e.args[0])
+ else:
+ self.fail('assertNotRegexpMatches should have failed.')
+
class TestLongMessage(unittest.TestCase):
"""Test that the individual asserts honour longMessage.
Modified: python/trunk/Misc/NEWS
==============================================================================
--- python/trunk/Misc/NEWS (original)
+++ python/trunk/Misc/NEWS Sat Apr 3 00:55:59 2010
@@ -148,6 +148,11 @@
- Issue #8235: _socket: Add the constant ``SO_SETFIB``. SO_SETFIB is
a socket option available on FreeBSD 7.1 and newer.
+- Issue #8038: unittest.TestCase.assertNotRegexpMatches
+
+- Addition of -b command line option to unittest for buffering stdout / stderr
+ during test runs.
+
Extension Modules
-----------------
More information about the Python-checkins
mailing list