-
Notifications
You must be signed in to change notification settings - Fork 30
/
run_tests
executable file
·83 lines (74 loc) · 3.55 KB
/
run_tests
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
#
# ScratchToCatrobat: A tool for converting Scratch projects into Catrobat programs.
# Copyright (C) 2013-2017 The Catrobat Team
# (<http://developer.catrobat.org/credits>)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# An additional term exception under section 7 of the GNU Affero
# General Public License, version 3, is available at
# http://developer.catrobat.org/license_additional_term
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from __future__ import print_function
import os
import platform
import subprocess
import sys
sys.path.append(os.path.join(os.path.realpath(os.path.dirname(__file__)), "src"))
from scratchtocatrobat.tools import helpers
data_dirs = helpers.config.get("PATHS", ["data", "logging", "output", "web_output", "tmp"])
helpers.make_dir_if_not_exists(data_dirs)
[jython_home_dir, jython_exec_path, jython_path] = helpers.config.get("PATHS", ["jython_home", "jython_exec", "jython"])
env = os.environ
env['JYTHONPATH'] = jython_path if sys.platform != 'win32' else jython_path.replace(":", ";")
if not os.path.isdir(jython_home_dir):
helpers.error("Invalid jython home path given. No valid directory. Please update 'jython_home' in the config file.")
if not os.path.isfile(jython_exec_path):
helpers.error("Jython script path '%s' must exist." % jython_exec_path.replace(".bat", "[.bat]"))
modules_under_test = set()
normalized_src_path = os.path.normpath(helpers.SRC_PATH)
for subdir, dirs, files in os.walk(helpers.SRC_PATH):
for file in files:
if file.startswith("test_") and file.endswith(".py"):
relative_subdir_path = os.path.normpath(subdir).replace(normalized_src_path, "")
if relative_subdir_path.startswith(os.sep):
relative_subdir_path = relative_subdir_path[1:]
if relative_subdir_path.endswith(os.sep):
relative_subdir_path = relative_subdir_path[:-1]
test_module_name = relative_subdir_path.replace(os.sep, ".") + "." + file
modules_under_test.add(test_module_name)
if len(sys.argv) >= 2 and sys.argv[1] != "all":
if (isinstance(sys.argv[1], str) or isinstance(sys.argv[1], unicode)) and sys.argv[1].startswith("test_"):
argument = sys.argv[1] if sys.argv[1].endswith('.py') else sys.argv[1] + ".py"
modules_under_test = filter(lambda m: m.endswith(argument), modules_under_test)
if len(modules_under_test) == 0:
helpers.error("Module %s not found" % argument)
else:
helpers.error("Invalid input given! Module name must always start with 'test_' (e.g. 'test_scratch')")
else:
print("Testing all modules!")
for module in modules_under_test:
print("-"*80)
print("Testing '%s':" % module)
print("-"*80)
exec_args = [jython_exec_path, "-m", module[:-3]]
if len(sys.argv) >= 3:
exec_args += [sys.argv[2]]
exit_code = subprocess.call(exec_args, env=env)
if exit_code != 0:
sys.exit(exit_code)
print()
print()
sys.exit(helpers.ExitCode.SUCCESS)