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

/test/macro/run.py

http://txt2tags.googlecode.com/
Python | 77 lines | 63 code | 6 blank | 8 comment | 5 complexity | fea7d1ef1322eb71cffb45befbb310e7 MD5 | raw file
 1#
 2# txt2tags %%macro command tester (http://txt2tags.org)
 3# See also: ../run.py ../lib.py
 4#
 5
 6import os, sys, re, glob
 7
 8sys.path.insert(0, '..')
 9import lib
10del sys.path[0]
11
12# sux
13lib.OK = lib.FAILED = 0
14lib.ERROR_FILES = []
15
16# smart filters to perform macros normalization
17FILTERS = [
18    ('post', os.path.abspath('..'), '/ABSOLUTE-PATH-TO-TEST-FOLDER'),
19    ('post', lib.getFileMtime('macro/syntax.t2t'), '@MTIME@'),
20    ('post', lib.getCurrentDate(), '@DATE@'),
21    ('post', '^(Date.*)@MTIME@', r'\1@DATE@'),
22    ('post', '^(Date.*)@MTIME@', r'\1@DATE@'),
23    ('post', '^(..appversion +"\d\.\d+)\.\d+', r'\1'),  # Remove SVN release
24]
25
26# convert FILTERS tuples to txt2tags pre/postproc rules
27def addFilters(filters):
28    config = []
29    cmdline = []
30    for filter_ in filters:
31        config.append("%%!%sproc: '%s' %s" % filter_)
32    if config:
33        lib.WriteFile(lib.CONFIG_FILE, '\n'.join(config))
34        cmdline = ['-C', lib.CONFIG_FILE]
35    return cmdline
36
37def run():
38    # test all OK files found
39    for outfile in glob.glob("ok/*"):
40        stderr = 0
41        basename = re.sub('\..*?$', '', outfile.replace('ok/', ''))
42        target = re.sub('.*\.', '', outfile)
43        if target == 'out':
44            target = 'txt'
45            stderr = 1
46        infile = basename + ".t2t"
47        # Using filename -H suffix to run new tests using -H option
48        if basename.endswith('-H'):
49            infile = basename.replace('-H', '') + ".t2t"
50        outfile = outfile.replace('ok/', '')
51
52        if lib.initTest(basename, infile, outfile):
53            cmdline = []
54            cmdline = addFilters(FILTERS)
55            if basename == 'path':
56                cmdline.extend(['--width', '200'])
57            if basename.endswith('-H'):
58                cmdline.append('-H')
59                cmdline.extend(['-o', outfile])
60            cmdline.extend(['-t', target])
61            cmdline.extend(['-i', infile])
62            if stderr:
63                cmdline.extend(['-o', '-'])
64                cmdline.append('>' + outfile)
65                cmdline.append('2>&1')
66            lib.convert(cmdline)
67            lib.diff(outfile)
68            lib.convert(cmdline, True)
69            lib.diff(outfile)
70    # clean up
71    if os.path.isfile(lib.CONFIG_FILE):
72        os.remove(lib.CONFIG_FILE)
73
74    return lib.OK, lib.FAILED, lib.ERROR_FILES
75
76if __name__ == '__main__':
77    print lib.MSG_RUN_ALONE