magic-removal: Merged to [2034]

git-svn-id: http://code.djangoproject.com/svn/django/branches/magic-removal@2035 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Adrian Holovaty 2006-01-17 17:57:27 +00:00
parent f1cf65c7bc
commit 6074e49daa
1 changed files with 10 additions and 6 deletions

View File

@ -1,6 +1,6 @@
#!/usr/bin/env python #!/usr/bin/env python
import os, sys, time, traceback import os, re, sys, time, traceback
# doctest is included in the same package as this module, because this testing # doctest is included in the same package as this module, because this testing
# framework uses features only available in the Python 2.4 version of doctest, # framework uses features only available in the Python 2.4 version of doctest,
@ -43,14 +43,18 @@ class DjangoDoctestRunner(doctest.DocTestRunner):
log_error(test.name, "API test raised an exception", log_error(test.name, "API test raised an exception",
"Code: %r\nLine: %s\nException: %s" % (example.source.strip(), example.lineno, tb)) "Code: %r\nLine: %s\nException: %s" % (example.source.strip(), example.lineno, tb))
normalize_long_ints = lambda s: re.sub(r'(?<![\w])(\d+)L(?![\w])', '\\1', s)
class DjangoDoctestOutputChecker(doctest.OutputChecker): class DjangoDoctestOutputChecker(doctest.OutputChecker):
def check_output(self, want, got, optionflags): def check_output(self, want, got, optionflags):
ok = doctest.OutputChecker.check_output(self, want, got, optionflags) ok = doctest.OutputChecker.check_output(self, want, got, optionflags)
if not ok and (want.strip().endswith("L") or got.strip().endswith("L")):
try: # Doctest does an exact string comparison of output, which means long
return long(want.strip()) == long(got.strip()) # integers aren't equal to normal integers ("22L" vs. "22"). The
except ValueError: # following code normalizes long integers so that they equal normal
return False # integers.
if not ok:
return normalize_long_ints(want) == normalize_long_ints(got)
return ok return ok
class TestRunner: class TestRunner: