PageRenderTime 17ms CodeModel.GetById 2ms app.highlight 11ms RepoModel.GetById 1ms app.codeStats 0ms

/test/headers/run.py

http://txt2tags.googlecode.com/
Python | 68 lines | 55 code | 4 blank | 9 comment | 0 complexity | 086f12f0c107eb5e95f3f725ea9f5cba MD5 | raw file
 1#
 2# txt2tags headers tester (http://txt2tags.org)
 3# See also: ../run.py ../lib.py
 4#
 5# Note: The .t2t files are generated dynamicaly, based on 'tests' data.
 6#       Each character is expanded to a 'txt' dict text.
 7#
 8
 9import sys, os
10
11sys.path.insert(0, '..')
12import lib
13del sys.path[0]
14
15# sux
16lib.OK = lib.FAILED = 0
17lib.ERROR_FILES = []
18
19# text patterns to compose source files
20txt = {
21    'e': '',                                           # Empty line
22    '1': 'Header 1',                                   # Header line 1
23    '2': 'Header 2',                                   # Header line 2
24    '3': 'Header 3',                                   # Header line 3
25    'c': '% comment',                                  # Comment line
26    'k': '%%%\ncomment\n%%%',                          # Comment block
27    'b': 'Text.',                                      # Body line
28    'f': '%!encoding: enc',                            # Config line
29    # Macros
30    'm': '%%date(!)%%mtime(!)%%infile(!)%%outfile(!)%%currentfile(!)',
31}
32
33# the registered tests
34tests = """
35eb    efb   ecb
361ee   1ef   1ec    1eeb   1e3b   1c3b    1ccb
3712e   12eb  12fb   12cb
38123   123b  123eb  123fb  123cf  123cfb  123ecefeb
391     c     1e     12
40ce3b  cc3b  c2eb   c2cb   c23b
41ekb   123kb ek     123k   ekkkb
42m     mm    mmm    1mm    12m
43"""
44
45def run():
46    for testid in tests.split():
47        infile  = testid + '.t2t'
48        outfile = testid + '.html'
49        cmdline = ['-t html --css-sugar -C test.conf', infile]
50        if lib.initTest(testid, infile, outfile):
51            # compose source file contents
52            infile_txt = []
53            for letter in testid:
54                infile_txt.append(txt[letter])
55            infile_txt = '\n'.join(infile_txt)
56            # create the source file
57            lib.WriteFile(infile, infile_txt)
58            # convert and check results
59            lib.convert(cmdline)
60            lib.diff(outfile)
61            lib.convert(cmdline, True)
62            lib.diff(outfile)
63            # remove the trash
64            os.remove(infile)
65    return lib.OK, lib.FAILED, lib.ERROR_FILES
66
67if __name__ == '__main__':
68    print lib.MSG_RUN_ALONE