[Python-checkins] r77747 - python/branches/release26-maint/Lib/test/test_support.py
ezio.melotti
python-checkins at python.org
Mon Jan 25 13:13:03 CET 2010
Author: ezio.melotti
Date: Mon Jan 25 13:13:02 2010
New Revision: 77747
Log:
Revert r77730 and add back verify and vereq in case other projects use them, but leave the changes in test_pprint and string_tests.
Modified:
python/branches/release26-maint/Lib/test/test_support.py
Modified: python/branches/release26-maint/Lib/test/test_support.py
==============================================================================
--- python/branches/release26-maint/Lib/test/test_support.py (original)
+++ python/branches/release26-maint/Lib/test/test_support.py Mon Jan 25 13:13:02 2010
@@ -17,7 +17,7 @@
"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 @@
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()
More information about the Python-checkins
mailing list