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

/test/csv/run.py

http://txt2tags.googlecode.com/
Python | 48 lines | 37 code | 4 blank | 7 comment | 2 complexity | acbb8c607daced67faedca3dcd4de6aa MD5 | raw file
 1#
 2# txt2tags %!csv 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    # Note: txt target is to test the table-to-verbatim mapping
19    for outfile in glob.glob("ok/*"):
20        stderr = 0
21        basename = re.sub('\..*?$', '', outfile.replace('ok/', ''))
22        target = re.sub('.*\.', '', outfile)
23        outfilelite = basename + '.' + (lib.EXTENSION.get(target) or target)
24        if target == 'out':
25            target = 'txt'
26            stderr = 1
27        infile = basename + ".t2t"
28        outfile = outfile.replace('ok/', '')
29        if lib.initTest(basename, infile, outfile):
30            cmdline = ['-H']
31            cmdline.extend(['-t', target])
32            cmdline.extend(['-i', infile])
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(outfilelite, os.path.join(lib.DIR_OK, 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