Skip to content
Browse files

Improved doctests to normalize long integers in compared output

git-svn-id: bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
1 parent 6f3f25e commit 8654a91e12e988b7be575364e3a791f2b4052fc1 @adrianholovaty adrianholovaty committed
Showing with 10 additions and 6 deletions.
  1. +10 −6 tests/
16 tests/
@@ -1,6 +1,6 @@
#!/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
# framework uses features only available in the Python 2.4 version of doctest,
@@ -43,14 +43,18 @@ def report_unexpected_exception(self, out, test, example, exc_info):
log_error(, "API test raised an exception",
"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):
def 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:
- return long(want.strip()) == long(got.strip())
- except ValueError:
- return False
+ # 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 TestRunner:

0 comments on commit 8654a91

Please sign in to comment.
Something went wrong with that request. Please try again.