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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# -----------------------------------------------------------------------------
# Getting Things GNOME! - a personal organizer for the GNOME desktop
# Copyright (c) 2008-2013 - Lionel Dricot & Bertrand Rousseau
#
# This program is free software: you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation, either version 3 of the License, or (at your option) any later
# version.
#
# 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 General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# this program. If not, see <http://www.gnu.org/licenses/>.
# -----------------------------------------------------------------------------
"""Runs the GTG unit tests."""
import sys
import unittest
from GTG.tests import test_suite
from GTG.tools.testingmode import TestingMode
from GTG.tools.import_liblarch import import_liblarch
TEST_MODULE_PREFIX = "GTG.tests."
def main(args):
runner = unittest.TextTestRunner(
stream = sys.stdout,
descriptions = True,
verbosity = 1)
if "-h" in args:
print("USAGE:")
print("./run_tests to run all tests")
print("./run_tests [module_name ..] to run tests from the listed " + \
"modules")
print("./run_tests [function_path ..] to run the selected " + \
"functions as tests")
return
if "-l" in args:
args.remove("-l")
# fake modules that mimic the behaviour of external libraries ...
TestingMode().set_testing_mode(True)
if args:
#if we have specified the name of the test in the command line
suites = []
for arg in args:
#each arg can be a module name (as test_liblarch), or a module name
# "dot" a function name (as test_liblarch.test_something)
arg_content = arg.split(".")
module_name = arg_content[0]
#load the module
module_path = TEST_MODULE_PREFIX + module_name
module = __import__(module_path)
sys.modules[module_path] = module
globals()[module_path] = module
tests = getattr(module, "tests")
a_test = getattr(tests, module_name)
if len(arg_content) > 1:
path = TEST_MODULE_PREFIX + arg
suites.append(unittest.TestLoader().loadTestsFromName(path))
#NOTE: this can be done easily with pattern matching with
# unittest.TestLoader().discover(..), but that's only from
# python 2.7 on.
else:
suites.append(getattr(a_test, "test_suite")())
else:
#otherwise, run all tests
suites = [test_suite()]
#run the tests
tests_are_successful = True
for suite in suites:
result = runner.run(suite)
tests_are_successful &= result.wasSuccessful()
#show the aggregated result of all the tests
if tests_are_successful:
print("ALL TESTS ARE SUCCESSFUL")
return 0
else:
print("""
****************************************
SOME TESTS *FAILED*!
****************************************
""")
return 1
if __name__ == '__main__':
use_local = "-l" in sys.argv[1:] or "--local-liblarch" in sys.argv[1:]
if import_liblarch(use_local):
sys.exit(main(sys.argv[1:]))
|