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

/test/crossing/run.py

http://txt2tags.googlecode.com/
Python | 100 lines | 84 code | 7 blank | 9 comment | 7 complexity | 07b6a828f1c7bdb0b1a0172c498964b8 MD5 | raw file
  1#
  2# txt2tags crossing marks tester (http://txt2tags.org)
  3# See also: ../run.py ../lib.py
  4#
  5
  6import os, sys, 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# left files are generated from right ones (using smart filters)
 17ALIASES = {
 18    'numlist' : 'list',
 19    'deflist' : 'list',
 20    'bar2'    : 'bar',
 21}
 22
 23# smart filters to allow source inheritance and macros normalization
 24FILTERS = {
 25    'deflist' : [ ('pre', '^-( |$)', r':\1') ],
 26    'numlist' : [ ('pre', '^-( |$)', r'+\1') ],
 27    'bar2'    : [ ('pre', '--'     , r'==' ) ],
 28}
 29
 30# convert FILTERS tuples to txt2tags pre/postproc rules
 31def addFilters(filters):
 32    if not filters: return []
 33    config = []
 34    cmdline = []
 35    for filter in filters:
 36        config.append("%%!%sproc: '%s' '%s'"%filter)
 37    if config:
 38        lib.WriteFile(lib.CONFIG_FILE, '\n'.join(config))
 39        cmdline = ['-C', lib.CONFIG_FILE]
 40    return cmdline
 41
 42def run():
 43    # test all .t2t files found
 44    for infile in glob.glob("*.t2t"):
 45        basename = infile.replace('.t2t', '')
 46        outfile = basename + '.html'
 47        if lib.initTest(basename, infile, outfile):
 48            cmdline = [infile]
 49            lib.convert(cmdline)
 50            lib.diff(outfile)
 51            lib.convert(cmdline, True)
 52            lib.diff(outfile)
 53
 54    # extra: bar.t2t as TXT
 55    infile = 'bar.t2t'
 56    basename = 'bar'
 57    outfile = basename + '.txt'
 58    if lib.initTest(basename, infile, outfile):
 59        cmdline = ['-t', 'txt', '-i', infile]
 60        cmdline.extend(['--width', '150'])  # to avoid wrapping
 61        lib.convert(cmdline)
 62        lib.diff(outfile)
 63        lib.convert(cmdline, True)
 64        lib.diff(outfile)
 65
 66    # using smart filters, same files generate more than one output
 67    for alias in ALIASES.keys():
 68        infile = ALIASES[alias] + '.t2t'
 69        outfile = alias + '.html'
 70        if lib.initTest(alias, infile, outfile):
 71            cmdline = addFilters(FILTERS.get(alias))
 72            cmdline.append('-H')
 73            cmdline.extend(['-o', outfile, infile])
 74            lib.convert(cmdline)
 75            lib.diff(outfile)
 76            lib.convert(cmdline, True)
 77            lib.diff(outfile)
 78
 79    # extra: bar2.t2t as TXT
 80    alias = 'bar2'
 81    infile = ALIASES[alias] + '.t2t'
 82    outfile = alias + '.txt'
 83    if lib.initTest(alias, infile, outfile):
 84        cmdline = addFilters(FILTERS.get(alias))
 85        cmdline.append('-H')
 86        cmdline.extend(['--width', '150'])  # to avoid wrapping
 87        cmdline.extend(['-t', 'txt', '-o', outfile, infile])
 88        lib.convert(cmdline)
 89        lib.diff(outfile)
 90        lib.convert(cmdline, True)
 91        lib.diff(outfile)
 92
 93    # clean up
 94    if os.path.isfile(lib.CONFIG_FILE):
 95        os.remove(lib.CONFIG_FILE)
 96
 97    return lib.OK, lib.FAILED, lib.ERROR_FILES
 98
 99if __name__ == '__main__':
100    print lib.MSG_RUN_ALONE