PageRenderTime 9ms CodeModel.GetById 1ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/test/include/run.py

http://txt2tags.googlecode.com/
Python | 48 lines | 38 code | 4 blank | 6 comment | 2 complexity | c28b83496ad682b004b49ed6627caf78 MD5 | raw file
 1#
 2# txt2tags %!include 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
16def run():
17    # test all OK files found
18    for outfile in glob.glob("ok/*"):
19        stderr = 0
20        basename = re.sub('\..*?$', '', outfile.replace('ok/', ''))
21        target = re.sub('.*\.', '', outfile)
22        if target == 'out':
23            target = 'txt'
24            stderr = 1
25        infile = basename + ".t2t"
26        outfile = outfile.replace('ok/', '')
27        if lib.initTest(basename, infile, outfile):
28            cmdline = ['-H']
29            cmdline.extend(['-t', target])
30            cmdline.extend(['-i', infile])
31            if basename in ('include-image-path', 'include-imagelink-path'):
32                cmdline.append('--fix-path')
33            if stderr:
34                cmdline.extend(['-o', '-'])
35                cmdline.append('>' + outfile)
36                cmdline.append('2>&1')
37            lib.convert(cmdline)
38            lib.diff(outfile)
39            lib.convert(cmdline, True)
40            lib.diff(outfile)
41    # clean up
42    if os.path.isfile(lib.CONFIG_FILE):
43        os.remove(lib.CONFIG_FILE)
44    
45    return lib.OK, lib.FAILED, lib.ERROR_FILES
46
47if __name__ == '__main__':
48    print lib.MSG_RUN_ALONE