/test/include/run.py

http://txt2tags.googlecode.com/ · Python · 48 lines · 35 code · 6 blank · 7 comment · 7 complexity · c28b83496ad682b004b49ed6627caf78 MD5 · raw file

  1. #
  2. # txt2tags %!include command tester (http://txt2tags.org)
  3. # See also: ../run.py ../lib.py
  4. #
  5. import os, sys, re, glob
  6. sys.path.insert(0, '..')
  7. import lib
  8. del sys.path[0]
  9. # sux
  10. lib.OK = lib.FAILED = 0
  11. lib.ERROR_FILES = []
  12. def run():
  13. # test all OK files found
  14. for outfile in glob.glob("ok/*"):
  15. stderr = 0
  16. basename = re.sub('\..*?$', '', outfile.replace('ok/', ''))
  17. target = re.sub('.*\.', '', outfile)
  18. if target == 'out':
  19. target = 'txt'
  20. stderr = 1
  21. infile = basename + ".t2t"
  22. outfile = outfile.replace('ok/', '')
  23. if lib.initTest(basename, infile, outfile):
  24. cmdline = ['-H']
  25. cmdline.extend(['-t', target])
  26. cmdline.extend(['-i', infile])
  27. if basename in ('include-image-path', 'include-imagelink-path'):
  28. cmdline.append('--fix-path')
  29. if stderr:
  30. cmdline.extend(['-o', '-'])
  31. cmdline.append('>' + outfile)
  32. cmdline.append('2>&1')
  33. lib.convert(cmdline)
  34. lib.diff(outfile)
  35. lib.convert(cmdline, True)
  36. lib.diff(outfile)
  37. # clean up
  38. if os.path.isfile(lib.CONFIG_FILE):
  39. os.remove(lib.CONFIG_FILE)
  40. return lib.OK, lib.FAILED, lib.ERROR_FILES
  41. if __name__ == '__main__':
  42. print lib.MSG_RUN_ALONE