/test/macro/run.py

http://txt2tags.googlecode.com/ · Python · 77 lines · 58 code · 9 blank · 10 comment · 11 complexity · fea7d1ef1322eb71cffb45befbb310e7 MD5 · raw file

  1. #
  2. # txt2tags %%macro 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. # smart filters to perform macros normalization
  13. FILTERS = [
  14. ('post', os.path.abspath('..'), '/ABSOLUTE-PATH-TO-TEST-FOLDER'),
  15. ('post', lib.getFileMtime('macro/syntax.t2t'), '@MTIME@'),
  16. ('post', lib.getCurrentDate(), '@DATE@'),
  17. ('post', '^(Date.*)@MTIME@', r'\1@DATE@'),
  18. ('post', '^(Date.*)@MTIME@', r'\1@DATE@'),
  19. ('post', '^(..appversion +"\d\.\d+)\.\d+', r'\1'), # Remove SVN release
  20. ]
  21. # convert FILTERS tuples to txt2tags pre/postproc rules
  22. def addFilters(filters):
  23. config = []
  24. cmdline = []
  25. for filter_ in filters:
  26. config.append("%%!%sproc: '%s' %s" % filter_)
  27. if config:
  28. lib.WriteFile(lib.CONFIG_FILE, '\n'.join(config))
  29. cmdline = ['-C', lib.CONFIG_FILE]
  30. return cmdline
  31. def run():
  32. # test all OK files found
  33. for outfile in glob.glob("ok/*"):
  34. stderr = 0
  35. basename = re.sub('\..*?$', '', outfile.replace('ok/', ''))
  36. target = re.sub('.*\.', '', outfile)
  37. if target == 'out':
  38. target = 'txt'
  39. stderr = 1
  40. infile = basename + ".t2t"
  41. # Using filename -H suffix to run new tests using -H option
  42. if basename.endswith('-H'):
  43. infile = basename.replace('-H', '') + ".t2t"
  44. outfile = outfile.replace('ok/', '')
  45. if lib.initTest(basename, infile, outfile):
  46. cmdline = []
  47. cmdline = addFilters(FILTERS)
  48. if basename == 'path':
  49. cmdline.extend(['--width', '200'])
  50. if basename.endswith('-H'):
  51. cmdline.append('-H')
  52. cmdline.extend(['-o', outfile])
  53. cmdline.extend(['-t', target])
  54. cmdline.extend(['-i', infile])
  55. if stderr:
  56. cmdline.extend(['-o', '-'])
  57. cmdline.append('>' + outfile)
  58. cmdline.append('2>&1')
  59. lib.convert(cmdline)
  60. lib.diff(outfile)
  61. lib.convert(cmdline, True)
  62. lib.diff(outfile)
  63. # clean up
  64. if os.path.isfile(lib.CONFIG_FILE):
  65. os.remove(lib.CONFIG_FILE)
  66. return lib.OK, lib.FAILED, lib.ERROR_FILES
  67. if __name__ == '__main__':
  68. print lib.MSG_RUN_ALONE