2
2
# -*- coding: utf-8 -*-
3
3
# -----------------------------------------------------------------------------
4
4
# Getting Things GNOME! - a personal organizer for the GNOME desktop
5
# Copyright (c) 2008-2013 - Lionel Dricot & Bertrand Rousseau
5
# Copyright (c) 2008-2014 - Lionel Dricot & Bertrand Rousseau
7
7
# This program is free software: you can redistribute it and/or modify it under
8
8
# the terms of the GNU General Public License as published by the Free Software
18
18
# this program. If not, see <http://www.gnu.org/licenses/>.
19
19
# -----------------------------------------------------------------------------
21
"""Runs the GTG unit tests."""
26
from GTG.tests import test_suite
27
from GTG.tools.testingmode import TestingMode
28
from GTG.tools.import_liblarch import import_liblarch
30
TEST_MODULE_PREFIX = "GTG.tests."
33
runner = unittest.TextTestRunner(
39
print("./run_tests to run all tests")
40
print("./run_tests [module_name ..] to run tests from the listed " + \
42
print("./run_tests [function_path ..] to run the selected " + \
47
# fake modules that mimic the behaviour of external libraries ...
48
TestingMode().set_testing_mode(True)
50
#if we have specified the name of the test in the command line
53
#each arg can be a module name (as test_liblarch), or a module name
54
# "dot" a function name (as test_liblarch.test_something)
55
arg_content = arg.split(".")
56
module_name = arg_content[0]
58
module_path = TEST_MODULE_PREFIX + module_name
59
module = __import__(module_path)
60
sys.modules[module_path] = module
61
globals()[module_path] = module
62
tests = getattr(module, "tests")
63
a_test = getattr(tests, module_name)
64
if len(arg_content) > 1:
65
path = TEST_MODULE_PREFIX + arg
66
suites.append(unittest.TestLoader().loadTestsFromName(path))
67
#NOTE: this can be done easily with pattern matching with
68
# unittest.TestLoader().discover(..), but that's only from
71
suites.append(getattr(a_test, "test_suite")())
73
#otherwise, run all tests
74
suites = [test_suite()]
77
tests_are_successful = True
79
result = runner.run(suite)
80
tests_are_successful &= result.wasSuccessful()
82
#show the aggregated result of all the tests
83
if tests_are_successful:
84
print("ALL TESTS ARE SUCCESSFUL")
88
****************************************
90
****************************************
94
if __name__ == '__main__':
95
use_local = "-l" in sys.argv[1:] or "--local-liblarch" in sys.argv[1:]
97
if import_liblarch(use_local):
98
sys.exit(main(sys.argv[1:]))
24
if __name__ == "__main__":
25
# By default, use spec plugin on tests folder
26
if len(sys.argv) == 1:
27
sys.argv.append('tests')
28
sys.argv.append('--with-specplugin')