summaryrefslogtreecommitdiff
path: root/testtools/testcase.py
diff options
context:
space:
mode:
authorJonathan Lange <jml@canonical.com>2012-01-29 14:03:59 +0000
committerJonathan Lange <jml@canonical.com>2012-01-29 14:03:59 +0000
commit761949fd14f02daf18a45e646a553c4df332caa6 (patch)
treece44144453ca0618d901bdea65002ba7a1556c1c /testtools/testcase.py
parent9a1d9356f93feafc6aaf962deb5fa9368eab1784 (diff)
downloadtesttools-761949fd14f02daf18a45e646a553c4df332caa6.tar.gz
Move to testcase so it doesn't appear in stack traces.
Diffstat (limited to 'testtools/testcase.py')
-rw-r--r--testtools/testcase.py20
1 files changed, 19 insertions, 1 deletions
diff --git a/testtools/testcase.py b/testtools/testcase.py
index 47e4fa0..17a6086 100644
--- a/testtools/testcase.py
+++ b/testtools/testcase.py
@@ -28,7 +28,6 @@ from testtools.compat import (
advance_iterator,
reraise,
)
-from testtools.helpers import Nullary
from testtools.matchers import (
Annotate,
Contains,
@@ -778,6 +777,25 @@ class ExpectedException:
return True
+class Nullary(object):
+ """Turn a callable into a nullary callable.
+
+ The advantage of this over ``lambda: f(*args, **kwargs)`` is that it
+ preserves the ``repr()`` of ``f``.
+ """
+
+ def __init__(self, callable_object, *args, **kwargs):
+ self._callable_object = callable_object
+ self._args = args
+ self._kwargs = kwargs
+
+ def __call__(self):
+ return self._callable_object(*self._args, **self._kwargs)
+
+ def __repr__(self):
+ return repr(self._callable_object)
+
+
# Signal that this is part of the testing framework, and that code from this
# should not normally appear in tracebacks.
__unittest = True