~parthpanchl/gtg/design-prototype

« back to all changes in this revision

Viewing changes to run-tests

  • Committer: Nimit Shah
  • Date: 2014-03-10 03:37:32 UTC
  • mfrom: (1360.2.18 test-cleanup)
  • Revision ID: nimit.svnit@gmail.com-20140310033732-n4od1z8npybs4ooc
Rework of test-suite, by Izidor Matušov

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
6
6
#
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
# -----------------------------------------------------------------------------
20
20
 
21
 
"""Runs the GTG unit tests."""
22
 
 
23
21
import sys
24
 
import unittest
25
 
 
26
 
from GTG.tests import test_suite
27
 
from GTG.tools.testingmode import TestingMode
28
 
from GTG.tools.import_liblarch import import_liblarch
29
 
 
30
 
TEST_MODULE_PREFIX = "GTG.tests."
31
 
 
32
 
def main(args):
33
 
    runner = unittest.TextTestRunner(
34
 
                    stream = sys.stdout,
35
 
                    descriptions = True,
36
 
                    verbosity = 1)
37
 
    if "-h" in args:
38
 
        print("USAGE:")
39
 
        print("./run_tests  to run all tests")
40
 
        print("./run_tests  [module_name ..] to run tests from the listed " + \
41
 
              "modules")
42
 
        print("./run_tests  [function_path ..] to run the selected " + \
43
 
              "functions as tests")
44
 
        return
45
 
    if "-l" in args:
46
 
        args.remove("-l")
47
 
    # fake modules that mimic the behaviour of external libraries ...
48
 
    TestingMode().set_testing_mode(True)
49
 
    if args:
50
 
        #if we have specified the name of the test in the command line
51
 
        suites = []
52
 
        for arg in args:
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]
57
 
            #load the module
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 
69
 
                #      python 2.7 on. 
70
 
            else:
71
 
                suites.append(getattr(a_test, "test_suite")())
72
 
    else:
73
 
        #otherwise, run all tests
74
 
        suites = [test_suite()]
75
 
 
76
 
    #run the tests
77
 
    tests_are_successful = True
78
 
    for suite in suites:
79
 
        result = runner.run(suite)
80
 
        tests_are_successful &= result.wasSuccessful()
81
 
 
82
 
    #show the aggregated result of all the tests
83
 
    if tests_are_successful:
84
 
        print("ALL TESTS ARE SUCCESSFUL")
85
 
        return 0
86
 
    else:
87
 
        print("""
88
 
        ****************************************
89
 
        SOME TESTS *FAILED*!
90
 
        ****************************************
91
 
        """)
92
 
        return 1
93
 
 
94
 
if __name__ == '__main__':
95
 
    use_local = "-l" in sys.argv[1:] or "--local-liblarch" in sys.argv[1:]
96
 
 
97
 
    if import_liblarch(use_local):
98
 
        sys.exit(main(sys.argv[1:]))
 
22
import nose
 
23
 
 
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')
 
29
 
 
30
    nose.main()