/test/includeconf/run.py
Python | 153 lines | 126 code | 9 blank | 18 comment | 2 complexity | 1370bffa72d4444e9024135035c8cfc3 MD5 | raw file
1# 2# txt2tags %!includeconf command 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# Tests for the command line option -C 17# Note: --config-file is also tested automatically from these tests 18tests = [ 19 { 20 'name' : 'C', 21 'cmdline': ["-C _config.inc"], 22 'not-numbered': True, 23 }, { 24 'name' : 'C-C', 25 'cmdline': ["-C _config.inc -C _config.inc"], 26 'not-numbered': True, 27 }, { 28 'name' : 'C-C2', 29 'cmdline': ["-C _config.inc -C _config2.inc"], 30 }, { 31 'name' : 'C-default', 32 'cmdline': ["-t html -C _config2.inc"], 33 }, { 34 'name' : 'C-empty', 35 'cmdline': ["-t html -C _empty.inc"], 36 'not-numbered': True, 37 }, { 38 'name' : 'C-not-found', 39 'cmdline': ["-t html -C XXX.inc"], 40 'not-numbered': True, 41 }, { 42 'name' : 'C-text', 43 'cmdline': ["-t html -C _text.inc"], 44 'not-numbered': True, 45 }, { 46 'name' : 'C-targeted-inside', 47 'cmdline': ["-t html -C _targeted.inc"], 48 }, { 49 'name' : 'C-nesting', 50 'cmdline': ["-C _sub_include.inc"], 51 }, { 52 'name' : 'C-nesting-folder', 53 'cmdline': ["-C folder/_folder.inc"], 54 }, { 55 'name' : 'C-nesting-folder-back', 56 'cmdline': ["-C folder/subfolder/_folder-back.inc"], 57 58 # This checking is never made because the infile may not be known without 59 # reading the config file. In other words, you can set %!options: -i foo.t2t 60 # inside the config file and just call: txt2tags -C config.t2t 61 # Because of this feature, we can't compare config file and infile names 62 # before reading the full config. But it will not loop, since the first body 63 # line of the infile will raise a config error. 64 # }, { 65 # 'name' : 'C-itself', # t2t -C foo.t2t -i foo.t2t 66 # 'cmdline': ["-C body-only"], 67 } 68] 69 70def run(): 71 72 ### First test the %!includeconf command 73 74 errors = [ 75 'includeconf-itself', 76 'includeconf-not-found', 77 'includeconf-targeted', 78 'includeconf-text', 79 ] 80 unnumbered = [ 81 'includeconf-empty', 82 ] 83 84 # test all t2t files found 85 for infile in glob.glob("includeconf-*.t2t"): 86 basename = infile.replace('.t2t', '') 87 outfile = basename + '.html' 88 89 if basename in unnumbered: 90 okfile = 'ok/not-numbered.html' 91 else: 92 okfile = 'ok/numbered.html' 93 94 if basename in errors: 95 outfile = basename + '.out' 96 okfile = 'ok/' + outfile 97 cmdline = ['-H', '-i', infile, '-o- >', outfile, '2>&1'] 98 else: 99 cmdline = ['-H', '-i', infile, '-o', outfile] 100 101 if lib.initTest(basename, infile, outfile, okfile): 102 lib.convert(cmdline) 103 lib.diff(outfile, okfile) 104 lib.convert(cmdline, True) 105 lib.diff(outfile, okfile) 106 107 ### Now test -C and --config-file command line options 108 109 errors = ['C-not-found', 'C-text'] 110 default_cmdline = ['-H -i body-only.t2t'] 111 infile = 'body-only.t2t' 112 for test in tests: 113 114 # --enum-title is used by this test? 115 if test.get('not-numbered'): 116 okfile = 'ok/not-numbered.html' 117 else: 118 okfile = 'ok/numbered.html' 119 120 # 1st turn (-C), 2nd turn (--config-file) 121 for i in (1, 2): 122 123 if i == 1: 124 name = test['name'] 125 cmdline = test['cmdline'] 126 else: 127 name = test['name'].replace('C', 'config-file') 128 cmdline = map(lambda x: x.replace('-C', '--config-file'), test['cmdline']) 129 130 outfile = name + '.html' 131 132 if test['name'] in errors: 133 outfile = name + '.out' 134 okfile = 'ok/' + outfile 135 cmdline = default_cmdline + cmdline + ['-o- >', outfile, '2>&1'] 136 else: 137 cmdline = default_cmdline + cmdline + ['-o', outfile] 138 139 # convert and check results 140 if lib.initTest(name, infile, outfile, okfile): 141 lib.convert(cmdline) 142 lib.diff(outfile, okfile) 143 lib.convert(cmdline, True) 144 lib.diff(outfile, okfile) 145 146 # clean up 147 if os.path.isfile(lib.CONFIG_FILE): 148 os.remove(lib.CONFIG_FILE) 149 150 return lib.OK, lib.FAILED, lib.ERROR_FILES 151 152if __name__ == '__main__': 153 print lib.MSG_RUN_ALONE