/test/headers/run.py

http://txt2tags.googlecode.com/ · Python · 68 lines · 46 code · 7 blank · 15 comment · 4 complexity · 086f12f0c107eb5e95f3f725ea9f5cba MD5 · raw file

  1. #
  2. # txt2tags headers tester (http://txt2tags.org)
  3. # See also: ../run.py ../lib.py
  4. #
  5. # Note: The .t2t files are generated dynamicaly, based on 'tests' data.
  6. # Each character is expanded to a 'txt' dict text.
  7. #
  8. import sys, os
  9. sys.path.insert(0, '..')
  10. import lib
  11. del sys.path[0]
  12. # sux
  13. lib.OK = lib.FAILED = 0
  14. lib.ERROR_FILES = []
  15. # text patterns to compose source files
  16. txt = {
  17. 'e': '', # Empty line
  18. '1': 'Header 1', # Header line 1
  19. '2': 'Header 2', # Header line 2
  20. '3': 'Header 3', # Header line 3
  21. 'c': '% comment', # Comment line
  22. 'k': '%%%\ncomment\n%%%', # Comment block
  23. 'b': 'Text.', # Body line
  24. 'f': '%!encoding: enc', # Config line
  25. # Macros
  26. 'm': '%%date(!)%%mtime(!)%%infile(!)%%outfile(!)%%currentfile(!)',
  27. }
  28. # the registered tests
  29. tests = """
  30. eb efb ecb
  31. 1ee 1ef 1ec 1eeb 1e3b 1c3b 1ccb
  32. 12e 12eb 12fb 12cb
  33. 123 123b 123eb 123fb 123cf 123cfb 123ecefeb
  34. 1 c 1e 12
  35. ce3b cc3b c2eb c2cb c23b
  36. ekb 123kb ek 123k ekkkb
  37. m mm mmm 1mm 12m
  38. """
  39. def run():
  40. for testid in tests.split():
  41. infile = testid + '.t2t'
  42. outfile = testid + '.html'
  43. cmdline = ['-t html --css-sugar -C test.conf', infile]
  44. if lib.initTest(testid, infile, outfile):
  45. # compose source file contents
  46. infile_txt = []
  47. for letter in testid:
  48. infile_txt.append(txt[letter])
  49. infile_txt = '\n'.join(infile_txt)
  50. # create the source file
  51. lib.WriteFile(infile, infile_txt)
  52. # convert and check results
  53. lib.convert(cmdline)
  54. lib.diff(outfile)
  55. lib.convert(cmdline, True)
  56. lib.diff(outfile)
  57. # remove the trash
  58. os.remove(infile)
  59. return lib.OK, lib.FAILED, lib.ERROR_FILES
  60. if __name__ == '__main__':
  61. print lib.MSG_RUN_ALONE