summaryrefslogtreecommitdiff
path: root/test/testlib/testing.py
diff options
context:
space:
mode:
authorJason Kirtland <jek@discorporate.us>2008-01-21 23:19:39 +0000
committerJason Kirtland <jek@discorporate.us>2008-01-21 23:19:39 +0000
commit412c80dd6c5d6b940e86e7e142aa1fdd6ee4466d (patch)
tree2a5bfa8185dd888d52b31bfb26ada56c7db89139 /test/testlib/testing.py
parent08bbc3dfd84234c3cd691e43ff17ed36e2396d76 (diff)
downloadsqlalchemy-412c80dd6c5d6b940e86e7e142aa1fdd6ee4466d.tar.gz
- 2.3 fixup, part two: 100% passing for sqlite
- added 2.4-style binops to util.Set on 2.3 - OrderedSets pickle on 2.3 - more lib/sqlalchemy set vs Set corrections - fixed InstrumentedSet.discard for 2.3 - set, sorted compatibility for test suite - added testing.fails_if decorator
Diffstat (limited to 'test/testlib/testing.py')
-rw-r--r--test/testlib/testing.py31
1 files changed, 31 insertions, 0 deletions
diff --git a/test/testlib/testing.py b/test/testlib/testing.py
index b05795efd..8b64ce7db 100644
--- a/test/testlib/testing.py
+++ b/test/testlib/testing.py
@@ -25,6 +25,37 @@ _ops = { '<': operator.lt,
# sugar ('testing.db'); set here by config() at runtime
db = None
+def fails_if(callable_):
+ """Mark a test as expected to fail if callable_ returns True.
+
+ If the callable returns false, the test is run and reported as normal.
+ However if the callable returns true, the test is expected to fail and the
+ unit test logic is inverted: if the test fails, a success is reported. If
+ the test succeeds, a failure is reported.
+ """
+
+ docstring = getattr(callable_, '__doc__', callable_.__name__)
+ description = docstring.split('\n')[0]
+
+ def decorate(fn):
+ fn_name = fn.__name__
+ def maybe(*args, **kw):
+ if not callable_():
+ return fn(*args, **kw)
+ else:
+ try:
+ fn(*args, **kw)
+ except Exception, ex:
+ print ("'%s' failed as expected (condition: %s): %s " % (
+ fn_name, description, str(ex)))
+ return True
+ else:
+ raise AssertionError(
+ "Unexpected success for '%s' (condition: %s)" %
+ (fn_name, description))
+ return _function_named(maybe, fn_name)
+ return decorate
+
def fails_on(*dbs):
"""Mark a test as expected to fail on one or more database implementations.