def run(): # test all OK files found # Note: txt target is to test the table-to-verbatim mapping for outfile in glob.glob("ok/*"): stderr = 0 basename = re.sub('\..*?$', '', outfile.replace('ok/', '')) target = re.sub('.*\.', '', outfile) outfilelite = basename + '.' + (lib.EXTENSION.get(target) or target) if target == 'out': target = 'txt' stderr = 1 infile = basename + ".t2t" outfile = outfile.replace('ok/', '') if lib.initTest(basename, infile, outfile): cmdline = ['-H'] cmdline.extend(['-t', target]) cmdline.extend(['-i', infile]) if stderr: cmdline.extend(['-o', '-']) cmdline.append('>' + outfile) cmdline.append('2>&1') lib.convert(cmdline) lib.diff(outfile) lib.convert(cmdline, True) lib.diff(outfilelite, os.path.join(lib.DIR_OK, outfile)) # clean up if os.path.isfile(lib.CONFIG_FILE): os.remove(lib.CONFIG_FILE) return lib.OK, lib.FAILED, lib.ERROR_FILES
def run(): for test in tests: infile = test['name'] + '.t2t' outfile = test['name'] + '.' + (test.get('target') or 'out') extra = test.get('extra') or [] cmdline = test['cmdline'] if not 'noinfile' in extra: cmdline = test['cmdline'] + [infile] if lib.initTest(test['name'], infile, outfile): # create the extra files (if needed for this test) if 'config' in extra: lib.WriteFile(lib.CONFIG_FILE, CONFIG_FILE_TXT) if 'css' in extra: lib.WriteFile(lib.CSS_FILE, CSS_FILE_TXT) # may I add the -t target automatically? if not 'notarget' in extra: cmdline = ['-t', test['target']] + cmdline # may I redirect the output to a file? if test.get('redir'): cmdline = cmdline + test['redir'] # always catch the error output cmdline = cmdline + ['2>&1'] # create the source file lib.WriteFile(infile, test['content']) # convert and check results lib.convert(cmdline) lib.diff(outfile) # remove the trash os.remove(infile) if os.path.isfile(lib.CSS_FILE): os.remove(lib.CSS_FILE) if os.path.isfile(lib.CONFIG_FILE): os.remove(lib.CONFIG_FILE) return lib.OK, lib.FAILED, lib.ERROR_FILES
def run(): # test all .t2t files found for infile in glob.glob("*.t2t"): basename = infile.replace('.t2t', '') # Choose targets targets = all_targets if basename == 'table': targets = tableable for target in targets: outfile = basename + '.' + target outfilelite = basename + '.' + (lib.EXTENSION.get(target) or target) testname = '%s in %s' % (basename, target) if lib.initTest(testname, infile, outfile): cmdline = [] cmdline.extend(['-i', infile]) cmdline.extend(['-t', target]) if target == 'aap': cmdline.extend(['--width', '80']) lib.convert(cmdline) lib.diff(outfile) lib.convert(cmdline, True) lib.diff(outfilelite, os.path.join(lib.DIR_OK, outfile)) return lib.OK, lib.FAILED, lib.ERROR_FILES
def run(): for test in tests: infile = test['name'] + '.t2t' outfile = test['name'] + '.' + (test.get('target') or 'out') cmdline = test['cmdline'] + [infile] extra = test.get('extra') or [] if lib.initTest(test['name'], infile, outfile): # create the extra files (if needed for this test) if 'config' in extra: lib.WriteFile(lib.CONFIG_FILE, CONFIG_FILE_TXT) if 'css' in extra: lib.WriteFile(lib.CSS_FILE, CSS_FILE_TXT) if not 'notarget' in extra: cmdline = ['-t', test['target']] + cmdline if test.get('redir'): cmdline = cmdline + test['redir'] # create the source file lib.WriteFile(infile, test['content']) # convert and check results lib.convert(cmdline) lib.diff(outfile) # remove the trash os.remove(infile) if os.path.isfile(lib.CSS_FILE): os.remove(lib.CSS_FILE) if os.path.isfile(lib.CONFIG_FILE): os.remove(lib.CONFIG_FILE) return lib.OK, lib.FAILED, lib.ERROR_FILES
def run(): # test all OK files found for outfile in glob.glob("ok/*"): stderr = 0 basename = re.sub('\..*?$', '', outfile.replace('ok/', '')) target = re.sub('.*\.', '', outfile) if target == 'out': target = 'txt' stderr = 1 infile = basename + ".t2t" outfile = outfile.replace('ok/', '') if lib.initTest(basename, infile, outfile): cmdline = ['-H'] cmdline.extend(['-t', target]) cmdline.extend(['-i', infile]) if stderr: cmdline.extend(['-o', '-']) cmdline.append('>' + outfile) cmdline.append('2>&1') lib.convert(cmdline) lib.diff(outfile) # clean up if os.path.isfile(lib.CONFIG_FILE): os.remove(lib.CONFIG_FILE) return lib.OK, lib.FAILED, lib.ERROR_FILES
def run(): # test all .t2t files found for infile in glob.glob("*.t2t"): basename = infile.replace('.t2t', '') outfile = basename + '.html' if lib.initTest(basename, infile, outfile): cmdline = [infile] lib.convert(cmdline) lib.diff(outfile) lib.convert(cmdline, True) lib.diff(outfile) # using smart filters, same files generate more than one output for alias in ALIASES.keys(): infile = ALIASES[alias] + '.t2t' outfile = alias + '.html' if lib.initTest(alias, infile, outfile): cmdline = addFilters(FILTERS.get(alias)) cmdline.append('-H') cmdline.extend(['-o', outfile, infile]) lib.convert(cmdline) lib.diff(outfile) lib.convert(cmdline, True) lib.diff(outfile) # clean up if os.path.isfile(lib.CONFIG_FILE): os.remove(lib.CONFIG_FILE) return lib.OK, lib.FAILED, lib.ERROR_FILES
def run(): # test all .t2t files found for infile in glob.glob("*.t2t"): basename = infile.replace('.t2t', '') outfile = basename + '.html' if lib.initTest(basename, infile, outfile): cmdline = addFilters(FILTERS.get(basename)) cmdline.append(infile) lib.convert(cmdline) lib.diff(outfile) lib.convert(cmdline, True) lib.diff(outfile) # using smart filters, same files generate more than one output for alias in ALIASES.keys(): infile = ALIASES[alias] + '.t2t' outfile = alias + '.html' if lib.initTest(alias, infile, outfile): cmdline = addFilters(FILTERS.get(alias)) cmdline.extend(['-o', outfile, infile]) lib.convert(cmdline) lib.diff(outfile) lib.convert(cmdline, True) lib.diff(outfile) # clean up if os.path.isfile(lib.CONFIG_FILE): os.remove(lib.CONFIG_FILE) return lib.OK, lib.FAILED, lib.ERROR_FILES
def statistics(path, exception=False): filename = path.as_posix() print(filename) im_in = cv2.imread(filename) h, w, _ = im_in.shape im_gray = cv2.cvtColor(im_in, cv2.COLOR_BGR2GRAY) im = cv2.GaussianBlur(im_gray, (5, 5), 0) yoko = (im.sum(0) / w).tolist() tate = (im.sum(1) / h).tolist() xs = determine(diff(yoko)) ys = determine(diff(tate)) if not exception and len(ys) == 8 and len(xs) == 4: # xs, ys = estimate(xs, ys, h) store(xs, ys)
def run(): for testid in tests.split(): infile = testid + '.t2t' outfile = testid + '.html' cmdline = ['-t html --css-sugar -C test.conf', infile] if lib.initTest(testid, infile, outfile): # compose source file contents infile_txt = [] for letter in testid: infile_txt.append(txt[letter]) infile_txt = '\n'.join(infile_txt) # create the source file lib.WriteFile(infile, infile_txt) # convert and check results lib.convert(cmdline) lib.diff(outfile) # remove the trash os.remove(infile) return lib.OK, lib.FAILED, lib.ERROR_FILES
def crop(path, exception=False, firstpath=False): filename = path.as_posix() print(filename) im_in = cv2.imread(filename) h, w, _ = im_in.shape im_gray = cv2.cvtColor(im_in, cv2.COLOR_BGR2GRAY) im_out = cv2.imread(filename) im = cv2.GaussianBlur(im_gray, (5, 5), 0) yoko = (im.sum(0) / w).tolist() tate = (im.sum(1) / h).tolist() xs = determine(diff(yoko)) ys = determine(diff(tate)) if not exception: xs, ys = estimate(xs, ys, h) # debug # DEBUG = True DEBUG = False if DEBUG: for x in xs: cv2.line(im_out, (x, 0), (x, h), (0, 0, 255), 2) for y in ys: cv2.line(im_out, (0, y), (w, y), (0, 0, 255), 2) new_path = path.parent / "test{0}".format(path.name) cv2.imwrite(new_path.as_posix(), im_out) return name, ext = path.stem, path.suffix new_dir = path.parent / "output" new_suffix = "{0}_{1}".format(path.parent.name, name) cnt = 0 for i in reversed(range(len(xs) - 1)): for j in range(len(ys) - 1): x1, x2 = xs[i], xs[i + 1] y1, y2 = ys[j], ys[j + 1] if 50000 < (x2 - x1) * (y2 - y1) and x2 < w and y2 < h: im_trim = im_out[y1:y2, x1:x2] new_path = new_dir / "{0}_{1}{2}".format(new_suffix, cnt, ext) cv2.imwrite(new_path.as_posix(), im_trim) cnt += 1
def run(): for test in tests: target = test.get('target') or 'txt' infile = test['name'] + '.t2t' outfile = test.get('outfile') or test['name'] + '.' + target extra = test.get('extra') or [] cmdline = ['-i', infile] + test.get('cmdline', []) content = test['content'] if 'noversion' in extra: content = VERSION_GOTCHA + content if 'error' in extra: outfile = test['name'] + '.out' if lib.initTest(test['name'], infile, outfile): # create the extra files (if needed for this test) if 'config' in extra: lib.WriteFile(lib.CONFIG_FILE, CONFIG_FILE_TXT) if 'css' in extra: lib.WriteFile(lib.CSS_FILE, CSS_FILE_TXT) # may I add the -t target automatically? if not 'notarget' in extra: cmdline = ['-t', target] + cmdline # may I redirect the output to a file? if test.get('redir'): cmdline.extend(test['redir']) elif 'error' in extra: cmdline.append('> %s.out' % test['name']) # always catch the error output cmdline.append('2>&1') # create the source file lib.WriteFile(infile, EMPTY_HEADER + content + '\n' + SIMPLE_BODY) # convert and check results lib.convert(cmdline) lib.diff(outfile) lib.convert(cmdline, True) lib.diff(outfile) # remove the trash os.remove(infile) if os.path.isfile(lib.CSS_FILE): os.remove(lib.CSS_FILE) if os.path.isfile(lib.CONFIG_FILE): os.remove(lib.CONFIG_FILE) return lib.OK, lib.FAILED, lib.ERROR_FILES
def run(): # test all OK files found for outfile in glob.glob("ok/*"): basename = re.sub('\..*?$', '', outfile.replace('ok/', '')) target = re.sub('.*\.', '', outfile) infile = basename + ".t2t" outfile = outfile.replace('ok/', '') if lib.initTest(basename, infile, outfile): cmdline = ['-H'] cmdline.extend(['-t', target]) cmdline.append(infile) lib.convert(cmdline) lib.diff(outfile) lib.convert(cmdline, True) lib.diff(outfile) # clean up if os.path.isfile(lib.CONFIG_FILE): os.remove(lib.CONFIG_FILE) return lib.OK, lib.FAILED, lib.ERROR_FILES
def run(): for testid in tests.split(): infile = testid + '.t2t' outfile = testid + '.html' cmdline = ['-t html --css-sugar -C test.conf', infile] if lib.initTest(testid, infile, outfile): # compose source file contents infile_txt = [] for letter in testid: infile_txt.append(txt[letter]) infile_txt = '\n'.join(infile_txt) # create the source file lib.WriteFile(infile, infile_txt) # convert and check results lib.convert(cmdline) lib.diff(outfile) lib.convert(cmdline, True) lib.diff(outfile) # remove the trash os.remove(infile) return lib.OK, lib.FAILED, lib.ERROR_FILES
def run(): for test in tests: infile = test['name'] + '.t2t' outfile = test['name'] + '.' + (test.get('target') or 'out') extra = test.get('extra') or [] cmdline = test['cmdline'] if not 'noinfile' in extra: cmdline = test['cmdline'] + [infile] if lib.initTest(test['name'], infile, outfile): # create the extra files (if needed for this test) if 'config' in extra: lib.WriteFile(lib.CONFIG_FILE, CONFIG_FILE_TXT) if 'css' in extra: lib.WriteFile(lib.CSS_FILE, CSS_FILE_TXT) # may I add the -t target automatically? if not 'notarget' in extra: cmdline = ['-t', test['target']] + cmdline # may I remove the SVN revision number? if 'norevision' in extra: cmdline.append(' | sed "%s;%s"' % (SED_NO_REVISION1, SED_NO_REVISION2)) # may I redirect the output to a file? if test.get('redir'): cmdline.extend(test['redir']) # always catch the error output cmdline.append('2>&1') # create the source file lib.WriteFile(infile, test['content']) # convert and check results lib.convert(cmdline) lib.diff(outfile) lib.convert(cmdline, True) lib.diff(outfile) # remove the trash os.remove(infile) if os.path.isfile(lib.CSS_FILE): os.remove(lib.CSS_FILE) if os.path.isfile(lib.CONFIG_FILE): os.remove(lib.CONFIG_FILE) return lib.OK, lib.FAILED, lib.ERROR_FILES
def run(): # test all OK files found for outfile in glob.glob("ok/*"): stderr = 0 basename = re.sub('\..*?$', '', outfile.replace('ok/', '')) target = re.sub('.*\.', '', outfile) if target == 'out': target = 'txt' stderr = 1 infile = basename + ".t2t" # Using filename -H suffix to run new tests using -H option if basename.endswith('-H'): infile = basename.replace('-H', '') + ".t2t" outfile = outfile.replace('ok/', '') if lib.initTest(basename, infile, outfile): cmdline = [] cmdline = addFilters(FILTERS) if basename == 'path': cmdline.extend(['--width', '200']) if basename.endswith('-H'): cmdline.append('-H') cmdline.extend(['-o', outfile]) cmdline.extend(['-t', target]) cmdline.extend(['-i', infile]) if stderr: cmdline.extend(['-o', '-']) cmdline.append('>' + outfile) cmdline.append('2>&1') lib.convert(cmdline) lib.diff(outfile) lib.convert(cmdline, True) lib.diff(outfile) # clean up if os.path.isfile(lib.CONFIG_FILE): os.remove(lib.CONFIG_FILE) return lib.OK, lib.FAILED, lib.ERROR_FILES
def run(): # test all OK files found for outfile in glob.glob("ok/*"): basename = re.sub('\..*?$', '', outfile.replace('ok/', '')) target = re.sub('.*\.', '', outfile) infile = basename + ".t2t" if infile in remote_infiles: infile = remote_root + infile if basename in remote_mapping: infile = remote_root + remote_mapping[basename] outfile = outfile.replace('ok/', '') if lib.initTest(basename, infile, outfile): cmdline = [] cmdline.extend(['-i', infile]) if infile.startswith(remote_root) \ and basename != 'remote-outfile': cmdline.extend(['-o', outfile]) if basename == 'not-found': cmdline.append('>' + outfile) cmdline.append('2>&1') elif basename == 'stdout': cmdline.extend(['-o', '-']) cmdline.append('>' + outfile) elif basename == 'remote-outfile': cmdline.append('2>' + outfile) elif basename == 'relative-path': cmdline.extend(['-t', 'html']) cmdline.append('--fix-path') lib.convert(cmdline) lib.diff(outfile) lib.convert(cmdline, True) lib.diff(outfile) # clean up if os.path.isfile(lib.CONFIG_FILE): os.remove(lib.CONFIG_FILE) return lib.OK, lib.FAILED, lib.ERROR_FILES
def run(): ### First test the %!includeconf command errors = [ 'includeconf-itself', 'includeconf-not-found', 'includeconf-targeted', 'includeconf-text', ] unnumbered = [ 'includeconf-empty', ] # test all t2t files found for infile in glob.glob("includeconf-*.t2t"): basename = infile.replace('.t2t', '') outfile = basename + '.html' if basename in unnumbered: okfile = 'ok/not-numbered.html' else: okfile = 'ok/numbered.html' if basename in errors: outfile = basename + '.out' okfile = 'ok/' + outfile cmdline = ['-H', '-i', infile, '-o- >', outfile, '2>&1'] else: cmdline = ['-H', '-i', infile, '-o', outfile] if lib.initTest(basename, infile, outfile, okfile): lib.convert(cmdline) lib.diff(outfile, okfile) lib.convert(cmdline, True) lib.diff(outfile, okfile) ### Now test -C and --config-file command line options errors = ['C-not-found', 'C-text'] default_cmdline = ['-H -i body-only.t2t'] infile = 'body-only.t2t' for test in tests: # --enum-title is used by this test? if test.get('not-numbered'): okfile = 'ok/not-numbered.html' else: okfile = 'ok/numbered.html' # 1st turn (-C), 2nd turn (--config-file) for i in (1, 2): if i == 1: name = test['name'] cmdline = test['cmdline'] else: name = test['name'].replace('C', 'config-file') cmdline = map(lambda x: x.replace('-C', '--config-file'), test['cmdline']) outfile = name + '.html' if test['name'] in errors: outfile = name + '.out' okfile = 'ok/' + outfile cmdline = default_cmdline + cmdline + ['-o- >', outfile, '2>&1'] else: cmdline = default_cmdline + cmdline + ['-o', outfile] # convert and check results if lib.initTest(name, infile, outfile, okfile): lib.convert(cmdline) lib.diff(outfile, okfile) lib.convert(cmdline, True) lib.diff(outfile, okfile) # clean up if os.path.isfile(lib.CONFIG_FILE): os.remove(lib.CONFIG_FILE) return lib.OK, lib.FAILED, lib.ERROR_FILES
def run(): # test all .t2t files found for infile in glob.glob("*.t2t"): basename = infile.replace('.t2t', '') outfile = basename + '.html' if lib.initTest(basename, infile, outfile): cmdline = [infile] lib.convert(cmdline) lib.diff(outfile) lib.convert(cmdline, True) lib.diff(outfile) # extra: bar.t2t as TXT infile = 'bar.t2t' basename = 'bar' outfile = basename + '.txt' if lib.initTest(basename, infile, outfile): cmdline = ['-t', 'txt', '-i', infile] cmdline.extend(['--width', '150']) # to avoid wrapping lib.convert(cmdline) lib.diff(outfile) lib.convert(cmdline, True) lib.diff(outfile) # using smart filters, same files generate more than one output for alias in ALIASES.keys(): infile = ALIASES[alias] + '.t2t' outfile = alias + '.html' if lib.initTest(alias, infile, outfile): cmdline = addFilters(FILTERS.get(alias)) cmdline.append('-H') cmdline.extend(['-o', outfile, infile]) lib.convert(cmdline) lib.diff(outfile) lib.convert(cmdline, True) lib.diff(outfile) # extra: bar2.t2t as TXT alias = 'bar2' infile = ALIASES[alias] + '.t2t' outfile = alias + '.txt' if lib.initTest(alias, infile, outfile): cmdline = addFilters(FILTERS.get(alias)) cmdline.append('-H') cmdline.extend(['--width', '150']) # to avoid wrapping cmdline.extend(['-t', 'txt', '-o', outfile, infile]) lib.convert(cmdline) lib.diff(outfile) lib.convert(cmdline, True) lib.diff(outfile) # clean up if os.path.isfile(lib.CONFIG_FILE): os.remove(lib.CONFIG_FILE) return lib.OK, lib.FAILED, lib.ERROR_FILES
def test_diff(): assert diff(1, 1) == 0