PageRenderTime 23ms CodeModel.GetById 1ms app.highlight 16ms RepoModel.GetById 1ms app.codeStats 0ms

/test/http/run.py

http://txt2tags.googlecode.com/
Python | 66 lines | 55 code | 5 blank | 6 comment | 2 complexity | faad56714e81bf6e56a778ec10b3b984 MD5 | raw file
 1#
 2# txt2tags http loading 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
16remote_root = 'http://txt2tags.org/test/'
17remote_infiles = [
18    'mtime.t2t',
19    'not-found.t2t',
20    'relative-path.t2t',
21    ]
22remote_mapping = {
23    'remote-outfile': 'simple.t2t',
24    'stdout': 'simple.t2t',
25    }
26
27def run():
28    # test all OK files found
29    for outfile in glob.glob("ok/*"):
30        basename = re.sub('\..*?$', '', outfile.replace('ok/', ''))
31        target = re.sub('.*\.', '', outfile)
32        infile = basename + ".t2t"
33        if infile in remote_infiles:
34            infile = remote_root + infile
35        if basename in remote_mapping:
36            infile = remote_root + remote_mapping[basename]
37        outfile = outfile.replace('ok/', '')
38        if lib.initTest(basename, infile, outfile):
39            cmdline = []
40            cmdline.extend(['-i', infile])
41            if infile.startswith(remote_root) \
42                and basename != 'remote-outfile':
43                cmdline.extend(['-o', outfile])
44            if basename == 'not-found':
45                cmdline.append('>' + outfile)
46                cmdline.append('2>&1')
47            elif basename == 'stdout':
48                cmdline.extend(['-o', '-'])
49                cmdline.append('>' + outfile)
50            elif basename == 'remote-outfile':
51                cmdline.append('2>' + outfile)
52            elif basename == 'relative-path':
53                cmdline.extend(['-t', 'html'])
54                cmdline.append('--fix-path')
55            lib.convert(cmdline)
56            lib.diff(outfile)
57            lib.convert(cmdline, True)
58            lib.diff(outfile)
59    # clean up
60    if os.path.isfile(lib.CONFIG_FILE):
61        os.remove(lib.CONFIG_FILE)
62
63    return lib.OK, lib.FAILED, lib.ERROR_FILES
64
65if __name__ == '__main__':
66    print lib.MSG_RUN_ALONE