/test/http/run.py

http://txt2tags.googlecode.com/ · Python · 66 lines · 52 code · 7 blank · 7 comment · 12 complexity · faad56714e81bf6e56a778ec10b3b984 MD5 · raw file

  1. #
  2. # txt2tags http loading 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. remote_root = 'http://txt2tags.org/test/'
  13. remote_infiles = [
  14. 'mtime.t2t',
  15. 'not-found.t2t',
  16. 'relative-path.t2t',
  17. ]
  18. remote_mapping = {
  19. 'remote-outfile': 'simple.t2t',
  20. 'stdout': 'simple.t2t',
  21. }
  22. def run():
  23. # test all OK files found
  24. for outfile in glob.glob("ok/*"):
  25. basename = re.sub('\..*?$', '', outfile.replace('ok/', ''))
  26. target = re.sub('.*\.', '', outfile)
  27. infile = basename + ".t2t"
  28. if infile in remote_infiles:
  29. infile = remote_root + infile
  30. if basename in remote_mapping:
  31. infile = remote_root + remote_mapping[basename]
  32. outfile = outfile.replace('ok/', '')
  33. if lib.initTest(basename, infile, outfile):
  34. cmdline = []
  35. cmdline.extend(['-i', infile])
  36. if infile.startswith(remote_root) \
  37. and basename != 'remote-outfile':
  38. cmdline.extend(['-o', outfile])
  39. if basename == 'not-found':
  40. cmdline.append('>' + outfile)
  41. cmdline.append('2>&1')
  42. elif basename == 'stdout':
  43. cmdline.extend(['-o', '-'])
  44. cmdline.append('>' + outfile)
  45. elif basename == 'remote-outfile':
  46. cmdline.append('2>' + outfile)
  47. elif basename == 'relative-path':
  48. cmdline.extend(['-t', 'html'])
  49. cmdline.append('--fix-path')
  50. lib.convert(cmdline)
  51. lib.diff(outfile)
  52. lib.convert(cmdline, True)
  53. lib.diff(outfile)
  54. # clean up
  55. if os.path.isfile(lib.CONFIG_FILE):
  56. os.remove(lib.CONFIG_FILE)
  57. return lib.OK, lib.FAILED, lib.ERROR_FILES
  58. if __name__ == '__main__':
  59. print lib.MSG_RUN_ALONE