TestCenter Reference
GenericTest.py
Go to the documentation of this file.
1 #
2 # Copyright 2013, MeVis Medical Solutions AG
3 #
4 # The user may use this file in accordance with the license agreement provided with
5 # the Software or, alternatively, in accordance with the terms contained in a
6 # written agreement between the user and MeVis Medical Solutions AG.
7 #
8 # For further information use the contact form at https://www.mevislab.de/contact
9 #
10 
11 from unittest.mock import patch
12 import unittest
13 
14 from TestSupport.Generic import *
15 import Meta
16 import Formal
17 import FormalMacroModule
18 
19 
20 class SharedTest(unittest.TestCase):
21 
22  def testOmitBoth(self):
23  with patch("mevis.MLAB.moduleInfo") as moduleInfoMock:
24  moduleName = "dummyModuleName"
25  moduleInfoMock.return_value = {TESTS_TO_OMIT_TAG: " ".join([FORMAL_TEST_IDENTIFIER, META_TEST_IDENTIFIER])}
26  omittedTests = getTestsToOmit(moduleName)
27 
28  self.assertListEqual([FORMAL_TEST_IDENTIFIER, META_TEST_IDENTIFIER], omittedTests)
29  moduleInfoMock.assert_called_once_with(moduleName)
30 
31  def testOmitNothing(self):
32  with patch("mevis.MLAB.moduleInfo") as moduleInfoMock:
33  moduleName = "dummyModuleName"
34  moduleInfoMock.return_value = {}
35  omittedTests = getTestsToOmit(moduleName)
36 
37  self.assertListEqual([], omittedTests)
38  moduleInfoMock.assert_called_once_with(moduleName)
39 
40  def testOmitAll(self):
41  with patch("mevis.MLAB.moduleInfo") as moduleInfoMock:
42  moduleName = "dummyModuleName"
43  moduleInfoMock.return_value = {TESTS_TO_OMIT_TAG: ALL_TESTS_IDENTIFIER}
44  omittedTests = getTestsToOmit(moduleName)
45 
46  self.assertIn(ALL_TESTS_IDENTIFIER, omittedTests)
47  moduleInfoMock.assert_called_once_with(moduleName)
48 
49  def testIsOmitted(self):
50  with patch("TestSupport.Generic.getTestsToOmit") as omitMock:
51  moduleName = "DummyModuleName"
52  # recognize if in list
53  omitMock.return_value = [FORMAL_TEST_IDENTIFIER, META_TEST_IDENTIFIER]
54  omitted = isTestOmitted(moduleName, FORMAL_TEST_IDENTIFIER)
55  self.assertTrue(omitted)
56  # counter-check if method in tests works as well
57  self.assertFalse(Formal.testModule(moduleName))
58  self.assertFalse(FormalMacroModule.testModule(moduleName))
59  self.assertFalse(Meta.testModule(moduleName))
60 
61  # skip also if all tests should be skipped
62  omitMock.return_value = [ALL_TESTS_IDENTIFIER]
63  omitted = isTestOmitted(moduleName, FORMAL_TEST_IDENTIFIER)
64  self.assertTrue(omitted)
65  # counter-check if method in tests works as well
66  self.assertFalse(Formal.testModule(moduleName))
67  self.assertFalse(FormalMacroModule.testModule(moduleName))
68  self.assertFalse(Meta.testModule(moduleName))
69 
70  # skip not if not in list
71  omitMock.return_value = []
72  omitted = isTestOmitted(moduleName, FORMAL_TEST_IDENTIFIER)
73  self.assertFalse(omitted)
74  # counter-check if method in tests works as well
75  self.assertTrue(Formal.testModule(moduleName))
76  self.assertTrue(FormalMacroModule.testModule(moduleName))
77  self.assertTrue(Meta.testModule(moduleName))
78 
79  if __name__ == "__main__":
80  # import sys;sys.argv = ['', 'Test.testName']
81  unittest.main()
def testOmitNothing(self)
Definition: GenericTest.py:31
def getTestsToOmit(moduleName)
Definition: Generic.py:25
def isTestOmitted(moduleName, testIdentifier)
Definition: Generic.py:53