Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
a04c7a0f
Commit
a04c7a0f
authored
Apr 02, 2010
by
Michael Foord
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #8038: Addition of unittest.TestCase.assertNotRegexpMatches
parent
25d79760
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
27 additions
and
0 deletions
+27
-0
Lib/unittest/case.py
Lib/unittest/case.py
+12
-0
Lib/unittest/test/test_assertions.py
Lib/unittest/test/test_assertions.py
+10
-0
Misc/NEWS
Misc/NEWS
+5
-0
No files found.
Lib/unittest/case.py
View file @
a04c7a0f
...
...
@@ -952,6 +952,18 @@ class TestCase(object):
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.
...
...
Lib/unittest/test/test_assertions.py
View file @
a04c7a0f
...
...
@@ -91,6 +91,16 @@ 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+'
)
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.
...
...
Misc/NEWS
View file @
a04c7a0f
...
...
@@ -148,6 +148,11 @@ Library
- 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
-----------------
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment