1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 """The relax software verification tests.
24
25 For a description of verification tests, please see U{Wikipedia<https://en.wikipedia.org/wiki/Verification_and_validation_%28software%29>}.
26 """
27
28
29 from re import search
30 from unittest import TestSuite
31
32
33 from lib.errors import RelaxError
34
35
36 from test_suite.formatting import format_test_name
37 from test_suite.relax_test_loader import RelaxTestLoader as TestLoader
38 from test_suite.verification_tests.library import Library
39 from test_suite.verification_tests.status_object import Status_object
40
41
42 __all__ = [
43 'library',
44 'status_object'
45 ]
46
47
49 """Class for executing all of the software verification tests."""
50
51 - def run(self, tests=None, runner=None, list_tests=False):
52 """Run the software verification tests.
53
54 @keyword tests: The list of system tests to preform.
55 @type tests: list of str
56 @keyword runner: A test runner such as TextTestRunner. For an example of how to write a test runner see the python documentation for TextTestRunner in the python source.
57 @type runner: Test runner instance (TextTestRunner, BaseGUITestRunner subclass, etc.)
58 @keyword list_tests: A flag which if True will cause the tests to be listed rather than executed.
59 @type list_tests: bool
60 """
61
62
63 suite_array = []
64
65
66 for test in tests:
67
68 if not search(r'\.', test):
69
70 if test not in globals():
71 raise RelaxError("The system test class '%s' does not exist." % test)
72
73
74 obj = globals()[test]
75
76
77 suite_array.append(TestLoader().loadTestsFromTestCase(obj))
78
79
80 else:
81
82 row = test.split('.')
83
84
85 if len(row) != 2:
86 raise RelaxError("The test '%s' is not in the correct format. It should consist of the test case class, a dot, and the specific test." % test)
87
88
89 class_name, test_name = row
90
91
92 obj = globals()[class_name]
93
94
95 suite_array.append(TestLoader().loadTestsFromNames([test_name], obj))
96
97
98 if not tests:
99 suite_array.append(TestLoader().loadTestsFromTestCase(Library))
100 suite_array.append(TestLoader().loadTestsFromTestCase(Status_object))
101
102
103 full_suite = TestSuite(suite_array)
104
105
106 if list_tests:
107 for suite in full_suite._tests:
108 for test in suite:
109 print(format_test_name(test.id()))
110 return True
111
112
113 results = runner.run(full_suite)
114
115
116 return results.wasSuccessful()
117