summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEzio Melotti <ezio.melotti@gmail.com>2010-01-25 12:13:02 (GMT)
committerEzio Melotti <ezio.melotti@gmail.com>2010-01-25 12:13:02 (GMT)
commitdd62b4d0495c8ab9ef369a3696e7ff3ec4ba9bcd (patch)
tree06a943deb167cf810d1dfd77900959f78ab52ef7
parentdabb5f7db93578de4657ae57dc0ade33f4f534aa (diff)
downloadcpython-dd62b4d0495c8ab9ef369a3696e7ff3ec4ba9bcd.zip
cpython-dd62b4d0495c8ab9ef369a3696e7ff3ec4ba9bcd.tar.gz
cpython-dd62b4d0495c8ab9ef369a3696e7ff3ec4ba9bcd.tar.bz2
Revert r77730 and add back verify and vereq in case other projects use them, but leave the changes in test_pprint and string_tests.
-rw-r--r--Lib/test/test_support.py26
1 files changed, 25 insertions, 1 deletions
diff --git a/Lib/test/test_support.py b/Lib/test/test_support.py
index 71b187a..d4b891e 100644
--- a/Lib/test/test_support.py
+++ b/Lib/test/test_support.py
@@ -17,7 +17,7 @@ __all__ = ["Error", "TestFailed", "TestSkipped", "ResourceDenied", "import_modul
"get_original_stdout", "unload", "unlink", "rmtree", "forget",
"is_resource_enabled", "requires", "find_unused_port", "bind_port",
"fcmp", "have_unicode", "is_jython", "TESTFN", "HOST", "FUZZ",
- "findfile", "sortdict", "check_syntax_error",
+ "findfile", "verify", "vereq", "sortdict", "check_syntax_error",
"open_urlresource", "check_warnings", "CleanImport",
"EnvironmentVarGuard", "captured_output",
"captured_stdout", "TransientResource", "transient_internet",
@@ -325,6 +325,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 = dict.items()