PageRenderTime 25ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/test/run.py

http://txt2tags.googlecode.com/
Python | 83 lines | 49 code | 12 blank | 22 comment | 8 complexity | bb2318340cae8c540ead5d00a3eccb76 MD5 | raw file
Possible License(s): GPL-2.0, GPL-3.0, WTFPL
  1. #!/usr/bin/env python
  2. #
  3. # txt2tags test-suite (http://txt2tags.org)
  4. # See also: lib.py, */run.py
  5. #
  6. # Just run this file without parameters at it will perform
  7. # all the tests. At the end a report will be printed, and
  8. # if any error is found, the program will tell you.
  9. #
  10. # Inside each test module (the subdirs) there is a run.py
  11. # script, that will make the tests. The expected results
  12. # are on the module's "ok" subdir. If any error is found,
  13. # it will be stored on the "error" subdir.
  14. #
  15. # TIP: To quickly check the errors, run:
  16. # for f in */error/*; do diff -u ${f/error/ok} $f; done
  17. import os, sys
  18. import lib
  19. MODULES = 'headers marks options nesting crossing gotchas bugs include csv db fen includeconf macro table module settings'.split()
  20. MODULES.append('http') # should always be the last, requires internet connection
  21. SCRIPT_DIR = os.path.dirname(os.path.abspath(sys.argv[0]))
  22. TOTAL_OK = TOTAL_FAILED = 0
  23. ERRORS = []
  24. if len(sys.argv) > 1:
  25. MODULES = sys.argv[1:]
  26. # Show which version is being tested
  27. os.system(lib.TXT2TAGS + " -V")
  28. os.system(lib.TXT2TAGSLITE + " -V")
  29. print
  30. print 'Base commands used for all tests:\n ' + lib.TXT2TAGS + '\n ' + lib.TXT2TAGSLITE
  31. print
  32. for module in MODULES:
  33. print 'Entering on module', module
  34. # loading test module
  35. os.chdir(SCRIPT_DIR)
  36. sys.path.insert(0, module)
  37. import run
  38. # do what you have to do
  39. if not os.path.isdir(module):
  40. print 'ERROR: Invalid module %s' % module
  41. sys.exit()
  42. os.chdir(module)
  43. ok, failed, errors = run.run()
  44. # update count
  45. TOTAL_OK = TOTAL_OK + ok
  46. TOTAL_FAILED = TOTAL_FAILED + failed
  47. for err in errors:
  48. ERRORS.append(os.path.join(module, lib.DIR_ERROR, err))
  49. # cleaning the house
  50. del sys.path[0]
  51. del run
  52. del sys.modules['run']
  53. # show report at the end
  54. if TOTAL_FAILED:
  55. stats = "%d ok / %d failed" % (TOTAL_OK, TOTAL_FAILED)
  56. else:
  57. stats = "100% ok"
  58. print
  59. print "Totals: %d tests (%s)" % (TOTAL_OK + TOTAL_FAILED, stats)
  60. if ERRORS:
  61. print
  62. print "Check out the files with errors:"
  63. print '\n'.join(ERRORS)
  64. sys.exit(1)
  65. if len(sys.argv) == 1:
  66. print
  67. print "Don't forget to run the extra tests:"
  68. print 'sample/run.sh'
  69. print 'art/run.sh'
  70. print 'path/run.sh'
  71. print 'outfile/run.sh'