Initial Commit.

Sun Feb 22 23:25:04 2009 +0900

author
hattori@www.hexacosa.net
date
Sun Feb 22 23:25:04 2009 +0900
changeset 0
daf698e1c5bc
child 1
012c9a005e84

Initial Commit.

Makefile file | annotate | diff | revisions
pyunitdiff.py file | annotate | diff | revisions
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/Makefile	Sun Feb 22 23:25:04 2009 +0900
     1.3 @@ -0,0 +1,4 @@
     1.4 +
     1.5 +install:
     1.6 +	cp -p pyunitdiff.py /usr/local/bin/pyunitdiff && chmod 755 /usr/local/bin/pyunitdiff
     1.7 +
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/pyunitdiff.py	Sun Feb 22 23:25:04 2009 +0900
     2.3 @@ -0,0 +1,68 @@
     2.4 +#!/usr/bin/env python
     2.5 +import re
     2.6 +from difflib import Differ
     2.7 +
     2.8 +__version__ = '0.1.0'
     2.9 +__author__ = 'Hideo Hattroi <syobosyobo@gmail.com>'
    2.10 +__license__ = 'NewBSDLicense'
    2.11 +
    2.12 +
    2.13 +MAX_COL = 80
    2.14 +
    2.15 +def split_linecol(bom):
    2.16 +    o = []
    2.17 +    maxbom = (len(bom)-1) / MAX_COL
    2.18 +    for i in range(maxbom):
    2.19 +        o.append(bom[MAX_COL*i:MAX_COL*(i+1)] + '\n')
    2.20 +    o.append(bom[MAX_COL*maxbom:] + '\n')
    2.21 +    return o
    2.22 +
    2.23 +def parse_objecttype(line):
    2.24 +    OBJECT_MAP = {
    2.25 +        '[' : type([]),
    2.26 +        '{' : type({}),
    2.27 +        "'" : type('s'),
    2.28 +        'T' : type(True),
    2.29 +        'F' : type(False),
    2.30 +    }
    2.31 +    line = line.strip()
    2.32 +    result = line.split('AssertionError: ')[1]
    2.33 +    first = result.split(' != ')[0]
    2.34 +    second = result.split(' != ')[1]
    2.35 +    firsttype = OBJECT_MAP[first[0]]
    2.36 +    secondtype = OBJECT_MAP[second[0]]
    2.37 +    return first, firsttype, second, secondtype
    2.38 +
    2.39 +def parse_unittest_result(lines):
    2.40 +    d = Differ()
    2.41 +    ass = re.compile('AssertionError')
    2.42 +    for line in lines:
    2.43 +        if ass.match(line):
    2.44 +            print line,
    2.45 +            print '-'*5
    2.46 +            first, firsttype, second, secondtype = parse_objecttype(line)
    2.47 +            if firsttype != secondtype:
    2.48 +                print "[diff]inval type:"
    2.49 +                print firsttype, secondtype
    2.50 +                continue
    2.51 +            print "[diff]unified print:"
    2.52 +            first = split_linecol(first)
    2.53 +            second = split_linecol(second)
    2.54 +            for i in d.compare(first, second):
    2.55 +                print i,
    2.56 +        else:
    2.57 +            print line,
    2.58 +
    2.59 +def main():
    2.60 +    import sys
    2.61 +    if sys.argv[1:]:
    2.62 +        p = Popen(['python', sys.argv[1]], stdout=PIPE, stderr=PIPE)
    2.63 +        r = p.communicate()[1]
    2.64 +        print parse_unittest_result(r.split('\n'))
    2.65 +    else:
    2.66 +        print parse_unittest_result(sys.stdin.readlines())
    2.67 +
    2.68 +
    2.69 +if __name__ == '__main__':
    2.70 +    main()
    2.71 +

mercurial