root / trunk / breve / tests / lib.py

Revision 403, 1.1 kB (checked in by cliff, 9 months ago)

more tests

Line 
1import sys, os
2import difflib
3from pprint import pprint
4
5def diff ( actual, expected ):
6    print "\n=" * 80
7    print actual
8    print "-" * 80
9    d = difflib.Differ ( )
10    result = d.compare ( actual.splitlines ( ), expected.splitlines ( ) ) 
11    for l in result:
12        if not l.startswith ( ' ' ):
13            print l
14    print "=\n" * 80
15
16def log_output ( actual, expected ):
17    ''' not used '''
18    test_name = callers_name ( )
19    file ( 'tmp/%s-actual.html' % test_name, 'w' ).write ( actual )
20    file ( 'tmp/%s-expected.html' % test_name, 'w' ).write ( expected )   
21
22def my_name ( ):
23    return sys._getframe ( 1 ).f_code.co_name
24
25def callers_name ( ):
26    return sys._getframe ( 2 ).f_code.co_name
27
28def caller ( ):
29    return sys._getframe ( 2 )
30
31def test_root ( ):
32    return os.path.abspath ( os.path.dirname ( __file__ ) )
33
34def template_root ( ):
35    return os.path.join ( test_root ( ), 'templates', callers_name ( ) )
36
37def expected_output ( ):
38    return file ( os.path.join ( test_root ( ), 'output', '%s.html' % callers_name ( ) ) ).read ( ).strip ( )
Note: See TracBrowser for help on using the browser.