/test/csv/run.py

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

  1. #
  2. # txt2tags %!csv 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. # Note: txt target is to test the table-to-verbatim mapping
  15. for outfile in glob.glob("ok/*"):
  16. stderr = 0
  17. basename = re.sub('\..*?$', '', outfile.replace('ok/', ''))
  18. target = re.sub('.*\.', '', outfile)
  19. outfilelite = basename + '.' + (lib.EXTENSION.get(target) or target)
  20. if target == 'out':
  21. target = 'txt'
  22. stderr = 1
  23. infile = basename + ".t2t"
  24. outfile = outfile.replace('ok/', '')
  25. if lib.initTest(basename, infile, outfile):
  26. cmdline = ['-H']
  27. cmdline.extend(['-t', target])
  28. cmdline.extend(['-i', infile])
  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(outfilelite, os.path.join(lib.DIR_OK, 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