diff options
author | Ezio Melotti <ezio.melotti@gmail.com> | 2010-01-25 12:20:04 (GMT) |
---|---|---|
committer | Ezio Melotti <ezio.melotti@gmail.com> | 2010-01-25 12:20:04 (GMT) |
commit | 2aef4b8110b54a38c08a17bbb00badc0eacc45dc (patch) | |
tree | 05f197bed2de9210a42dacae9cd84566554979aa /Lib/test | |
parent | 4c81fbb118247ae6cecbdce11b7bc37dd98e060c (diff) | |
download | cpython-2aef4b8110b54a38c08a17bbb00badc0eacc45dc.zip cpython-2aef4b8110b54a38c08a17bbb00badc0eacc45dc.tar.gz cpython-2aef4b8110b54a38c08a17bbb00badc0eacc45dc.tar.bz2 |
Revert r77732 and add back verify and vereq in case other projects use them, but leave the changes in test_pprint and string_tests.
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/support.py | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/Lib/test/support.py b/Lib/test/support.py index fc9a61a..18fb391 100644 --- a/Lib/test/support.py +++ b/Lib/test/support.py @@ -21,8 +21,8 @@ __all__ = ["Error", "TestFailed", "ResourceDenied", "import_module", "verbose", "use_resources", "max_memuse", "record_original_stdout", "get_original_stdout", "unload", "unlink", "rmtree", "forget", "is_resource_enabled", "requires", "find_unused_port", "bind_port", - "fcmp", "is_jython", "TESTFN", "HOST", "FUZZ", "findfile", - "sortdict", "check_syntax_error", "open_urlresource", + "fcmp", "is_jython", "TESTFN", "HOST", "FUZZ", "findfile", "verify", + "vereq", "sortdict", "check_syntax_error", "open_urlresource", "check_warnings", "CleanImport", "EnvironmentVarGuard", "TransientResource", "captured_output", "captured_stdout", "time_out", "socket_peer_reset", "ioerror_peer_reset", @@ -396,6 +396,30 @@ def findfile(file, here=__file__): if os.path.exists(fn): return fn return file +def verify(condition, reason='test failed'): + """Verify that condition is true. If not, raise TestFailed. + + The optional argument reason can be given to provide + a better error text. + """ + + if not condition: + raise TestFailed(reason) + +def vereq(a, b): + """Raise TestFailed if a == b is false. + + This is better than verify(a == b) because, in case of failure, the + error message incorporates repr(a) and repr(b) so you can see the + inputs. + + Note that "not (a == b)" isn't necessarily the same as "a != b"; the + former is tested. + """ + + if not (a == b): + raise TestFailed("%r == %r" % (a, b)) + def sortdict(dict): "Like repr(dict), but in sorted order." items = sorted(dict.items()) |