~widelands-dev/widelands-website/trunk

« back to all changes in this revision

Viewing changes to mainpage/tests.py

  • Committer: franku
  • Date: 2016-12-13 18:28:51 UTC
  • mto: This revision was merged to the branch mainline in revision 443.
  • Revision ID: somal@arcor.de-20161213182851-bo5ebf8pdvw5beua
run the script

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#!/usr/bin/python -tt
2
2
 
3
3
# Load and runs the test from the utest subdirectory
4
 
# your unittests should append ".." to their path to 
 
4
# your unittests should append ".." to their path to
5
5
# find the files relative to this directory
6
6
 
7
7
import unittest
9
9
import os
10
10
import sys
11
11
 
12
 
prefix = ""
 
12
prefix = ''
13
13
append_path = False
14
 
if __name__ != "__main__":
 
14
if __name__ != '__main__':
15
15
    prefix = __name__[:-5]
16
16
    append_path = True
17
17
 
18
 
def suite( ):
 
18
 
 
19
def suite():
19
20
    # If we are not called directly, we have
20
21
    # to append this path to sys.path so our
21
22
    # subtests will find their files
22
23
    this_dir = os.path.dirname(__file__)
23
24
    if append_path:
24
 
        sys.path.append( this_dir )
 
25
        sys.path.append(this_dir)
25
26
 
26
27
    suite = unittest.TestSuite()
27
28
    l = unittest.TestLoader()
28
 
    
 
29
 
29
30
    dname = os.path.dirname(__file__)
30
31
 
31
 
    for f in glob("%s/utest/*.py" % dname):
 
32
    for f in glob('%s/utest/*.py' % dname):
32
33
        if os.path.basename(f) == '__init__.py':
33
34
            continue
34
 
       
35
 
        modname = "%sutest.%s" % (prefix,os.path.basename(f)[:-3])
 
35
 
 
36
        modname = '%sutest.%s' % (prefix, os.path.basename(f)[:-3])
36
37
 
37
38
        # Load tests
38
 
        tests = l.loadTestsFromName( modname )
 
39
        tests = l.loadTestsFromName(modname)
39
40
        suite.addTests(tests)
40
 
    
 
41
 
41
42
    if append_path:
42
 
        sys.path.remove( this_dir )
 
43
        sys.path.remove(this_dir)
43
44
 
44
45
    return suite
45
 
  
46
 
def main( ):
 
46
 
 
47
 
 
48
def main():
47
49
    tsuite = suite()
48
50
    runner = unittest.TextTestRunner()
49
51
    runner.run(tsuite)
50
52
    return unittest.TestResult()
51
53
 
52
54
 
53
 
 
54
55
if __name__ == '__main__':
55
56
    main()
56
 
 
57