FreeCAD

Форк
0
/
TestApp.py 
112 строк · 4.1 Кб
1
# ***************************************************************************
2
# *   Copyright (c) 2002 Juergen Riegel <juergen.riegel@web.de>             *
3
# *                                                                         *
4
# *   This file is part of the FreeCAD CAx development system.              *
5
# *                                                                         *
6
# *   This program is free software; you can redistribute it and/or modify  *
7
# *   it under the terms of the GNU Lesser General Public License (LGPL)    *
8
# *   as published by the Free Software Foundation; either version 2 of     *
9
# *   the License, or (at your option) any later version.                   *
10
# *   for detail see the LICENCE text file.                                 *
11
# *                                                                         *
12
# *   FreeCAD is distributed in the hope that it will be useful,            *
13
# *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
14
# *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
15
# *   GNU Library General Public License for more details.                  *
16
# *                                                                         *
17
# *   You should have received a copy of the GNU Library General Public     *
18
# *   License along with FreeCAD; if not, write to the Free Software        *
19
# *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  *
20
# *   USA                                                                   *
21
# *                                                                         *
22
# ***************************************************************************/
23

24
import FreeCAD
25
import sys
26
import unittest
27

28

29
# ---------------------------------------------------------------------------
30
# define the functions to test the FreeCAD base code
31
# ---------------------------------------------------------------------------
32

33

34
def tryLoadingTest(testName):
35
    "Loads and returns testName, or a failing TestCase if unsuccessful."
36

37
    try:
38
        return unittest.defaultTestLoader.loadTestsFromName(testName)
39

40
    except ImportError:
41

42
        class LoadFailed(unittest.TestCase):
43
            def __init__(self, testName):
44
                # setattr() first, because TestCase ctor checks for methodName.
45
                setattr(self, "failed_to_load_" + testName, self._runTest)
46
                super(LoadFailed, self).__init__("failed_to_load_" + testName)
47
                self.testName = testName
48

49
            def __name__(self):
50
                return "Loading " + self.testName
51

52
            def _runTest(self):
53
                self.fail("Couldn't load " + self.testName)
54

55
        return LoadFailed(testName)
56

57

58
def All():
59
    # Registered tests
60
    tests = FreeCAD.__unit_test__
61

62
    suite = unittest.TestSuite()
63

64
    for test in tests:
65
        suite.addTest(tryLoadingTest(test))
66

67
    return suite
68

69

70
def PrintAll():
71
    # Registered tests
72
    tests = FreeCAD.__unit_test__
73

74
    suite = unittest.TestSuite()
75

76
    FreeCAD.Console.PrintMessage("\nRegistered test units:\n\n")
77
    for test in tests:
78
        FreeCAD.Console.PrintMessage(("%s\n" % test))
79
    FreeCAD.Console.PrintMessage("\nPlease choose one or use 0 for all\n")
80

81
    return suite
82

83

84
def TestText(s):
85
    s = unittest.defaultTestLoader.loadTestsFromName(s)
86
    r = unittest.TextTestRunner(stream=sys.stdout, verbosity=2)
87
    retval = r.run(s)
88
    # Flushing to make sure the stream is written to the console
89
    # before the wrapping process stops executing. Without this line
90
    # executing the tests from command line did not show stats
91
    # and proper traceback in some cases.
92
    sys.stdout.flush()
93
    return retval
94

95

96
def Test(s):
97
    TestText(s)
98

99

100
def testAll():
101
    r = unittest.TextTestRunner(stream=sys.stdout, verbosity=2)
102
    return r.run(All())
103

104

105
def testUnit():
106
    TestText(unittest.TestLoader().loadTestsFromName("UnitTests"))
107

108

109
def testDocument():
110
    suite = unittest.TestSuite()
111
    suite.addTest(unittest.defaultTestLoader.loadTestsFromName("Document"))
112
    TestText(suite)
113

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.