PageRenderTime 63ms CodeModel.GetById 54ms app.highlight 6ms RepoModel.GetById 2ms app.codeStats 0ms

/test/run.py

http://txt2tags.googlecode.com/
Python | 83 lines | 49 code | 12 blank | 22 comment | 10 complexity | bb2318340cae8c540ead5d00a3eccb76 MD5 | raw file
 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
18import os, sys
19import lib
20
21MODULES = 'headers marks options nesting crossing gotchas bugs include csv db fen includeconf macro table module settings'.split()
22MODULES.append('http')  # should always be the last, requires internet connection
23SCRIPT_DIR = os.path.dirname(os.path.abspath(sys.argv[0]))
24TOTAL_OK = TOTAL_FAILED = 0
25ERRORS = []
26
27if len(sys.argv) > 1:
28    MODULES = sys.argv[1:]
29
30# Show which version is being tested
31os.system(lib.TXT2TAGS + " -V")
32os.system(lib.TXT2TAGSLITE + " -V")
33print
34print 'Base commands used for all tests:\n  ' + lib.TXT2TAGS + '\n  ' +  lib.TXT2TAGSLITE
35print
36
37for module in MODULES:
38    print 'Entering on module', module
39
40    # loading test module
41    os.chdir(SCRIPT_DIR)
42    sys.path.insert(0, module)
43    import run
44
45    # do what you have to do
46    if not os.path.isdir(module):
47        print 'ERROR: Invalid module %s' % module
48        sys.exit()
49    os.chdir(module)
50    ok, failed, errors = run.run()
51
52    # update count
53    TOTAL_OK = TOTAL_OK + ok
54    TOTAL_FAILED = TOTAL_FAILED + failed
55    for err in errors:
56        ERRORS.append(os.path.join(module, lib.DIR_ERROR, err))
57
58    # cleaning the house
59    del sys.path[0]
60    del run
61    del sys.modules['run']
62
63# show report at the end
64if TOTAL_FAILED:
65    stats = "%d ok / %d failed" % (TOTAL_OK, TOTAL_FAILED)
66else:
67    stats = "100% ok"
68print
69print "Totals: %d tests (%s)" % (TOTAL_OK + TOTAL_FAILED, stats)
70
71if ERRORS:
72    print
73    print "Check out the files with errors:"
74    print '\n'.join(ERRORS)
75    sys.exit(1)
76
77if len(sys.argv) == 1:
78    print
79    print "Don't forget to run the extra tests:"
80    print 'sample/run.sh'
81    print 'art/run.sh'
82    print 'path/run.sh'
83    print 'outfile/run.sh'