|
Revision 403, 1.1 kB
(checked in by cliff, 9 months ago)
|
|
more tests
|
| Line | |
|---|
| 1 | import sys, os |
|---|
| 2 | import difflib |
|---|
| 3 | from pprint import pprint |
|---|
| 4 | |
|---|
| 5 | def 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 | |
|---|
| 16 | def 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 | |
|---|
| 22 | def my_name ( ): |
|---|
| 23 | return sys._getframe ( 1 ).f_code.co_name |
|---|
| 24 | |
|---|
| 25 | def callers_name ( ): |
|---|
| 26 | return sys._getframe ( 2 ).f_code.co_name |
|---|
| 27 | |
|---|
| 28 | def caller ( ): |
|---|
| 29 | return sys._getframe ( 2 ) |
|---|
| 30 | |
|---|
| 31 | def test_root ( ): |
|---|
| 32 | return os.path.abspath ( os.path.dirname ( __file__ ) ) |
|---|
| 33 | |
|---|
| 34 | def template_root ( ): |
|---|
| 35 | return os.path.join ( test_root ( ), 'templates', callers_name ( ) ) |
|---|
| 36 | |
|---|
| 37 | def expected_output ( ): |
|---|
| 38 | return file ( os.path.join ( test_root ( ), 'output', '%s.html' % callers_name ( ) ) ).read ( ).strip ( ) |
|---|