summaryrefslogtreecommitdiff
path: root/django/test/testcases.py
diff options
context:
space:
mode:
authorRussell Keith-Magee <russell@keith-magee.com>2006-08-27 12:24:59 +0000
committerRussell Keith-Magee <russell@keith-magee.com>2006-08-27 12:24:59 +0000
commit7dce86ce0220ffb9f3f579cbd1e881e988764c9d (patch)
tree87faf4ebeeb10495163dc84c006dab201ec486bf /django/test/testcases.py
parent1a1fb70c9f7c6c286a424710e2a496e79b4b6484 (diff)
Refs #2333 - Added test framework. This includes doctest and unittest finders, Django-specific doctest and unittest wrappers, and a pseudo-client that can be used to stimulate and test views.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@3658 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/test/testcases.py')
-rw-r--r--django/test/testcases.py30
1 files changed, 30 insertions, 0 deletions
diff --git a/django/test/testcases.py b/django/test/testcases.py
new file mode 100644
index 0000000000..1cfef6f19e
--- /dev/null
+++ b/django/test/testcases.py
@@ -0,0 +1,30 @@
+import re, doctest, unittest
+from django.db import transaction
+
+normalize_long_ints = lambda s: re.sub(r'(?<![\w])(\d+)L(?![\w])', '\\1', s)
+
+class OutputChecker(doctest.OutputChecker):
+ def check_output(self, want, got, optionflags):
+ ok = doctest.OutputChecker.check_output(self, want, got, optionflags)
+
+ # Doctest does an exact string comparison of output, which means long
+ # integers aren't equal to normal integers ("22L" vs. "22"). The
+ # following code normalizes long integers so that they equal normal
+ # integers.
+ if not ok:
+ return normalize_long_ints(want) == normalize_long_ints(got)
+ return ok
+
+class DocTestRunner(doctest.DocTestRunner):
+ def __init__(self, *args, **kwargs):
+ doctest.DocTestRunner.__init__(self, *args, **kwargs)
+ self.optionflags = doctest.ELLIPSIS
+
+ def report_unexpected_exception(self, out, test, example, exc_info):
+ doctest.DocTestRunner.report_unexpected_exception(self,out,test,example,exc_info)
+
+ # Rollback, in case of database errors. Otherwise they'd have
+ # side effects on other tests.
+ from django.db import transaction
+ transaction.rollback_unless_managed()
+