forked from alialo/Shoreditch-Gamerunner
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
46 lines (35 loc) · 1.24 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
##########
#### Run the test suite for Shoreditch Gamerunner
##########
import unittest
import os, sys
import argparse
import test
def list_modules(dir, module_path = ''):
modules = []
for f in os.listdir(dir):
module_name, ext = os.path.splitext(f) # Handles no-extension files, etc.
if os.path.isdir('test/' + module_name):
modules.extend(list_modules(dir + '/' + module_name, module_path + module_name + '.'))
elif ext == '.py' and not module_name == '__init__': # Important, ignore .pyc/other files.
__import__(module_path + module_name)
modules.append(sys.modules[module_path + module_name])
return modules
def run_tests(scope = None):
suite = unittest.TestSuite()
import test
modules = []
if scope:
suite.addTests(unittest.TestLoader().loadTestsFromName(scope))
else:
for module in list_modules(os.path.dirname(test.__file__), 'test.'):
suite.addTests(unittest.TestLoader().loadTestsFromModule(module))
res = unittest.TextTestRunner(verbosity=2).run(suite)
return len(res.failures)
parser = argparse.ArgumentParser(description='Test the Settlers of Shoreditch game')
parser.add_argument('--test_scope')
args = parser.parse_args()
if args.test_scope:
sys.exit(run_tests(args.test_scope))
else:
sys.exit(run_tests())