Django

Code

Changeset 2034

Show
Ignore:
Timestamp:
01/17/06 11:56:33 (2 years ago)
Author:
adrian
Message:

Improved doctests to normalize long integers in compared output

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/tests/runtests.py

    r1811 r2034  
    11#!/usr/bin/env python 
    22 
    3 import os, sys, time, traceback 
     3import os, re, sys, time, traceback 
    44 
    55# doctest is included in the same package as this module, because this testing 
     
    4444            "Code: %r\nLine: %s\nException: %s" % (example.source.strip(), example.lineno, tb)) 
    4545 
     46normalize_long_ints = lambda s: re.sub(r'(?<![\w])(\d+)L(?![\w])', '\\1', s) 
     47 
    4648class DjangoDoctestOutputChecker(doctest.OutputChecker): 
    4749    def check_output(self, want, got, optionflags): 
    4850        ok = doctest.OutputChecker.check_output(self, want, got, optionflags) 
    49         if not ok and (want.strip().endswith("L") or got.strip().endswith("L")): 
    50             try: 
    51                 return long(want.strip()) == long(got.strip()) 
    52             except ValueError: 
    53                 return False 
     51 
     52        # Doctest does an exact string comparison of output, which means long 
     53        # integers aren't equal to normal integers ("22L" vs. "22"). The 
     54        # following code normalizes long integers so that they equal normal 
     55        # integers. 
     56        if not ok: 
     57            return normalize_long_ints(want) == normalize_long_ints(got) 
    5458        return ok 
    5559