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 try:
12  # Python 3.x
13  from unittest.mock import *
14 except ImportError:
15  # Python 2.x
16  from mock import *
17 import unittest
18 
19 from TestSupport.Generic import *
20 import Meta
21 import Formal
22 import FormalMacroModule
23 
24 class SharedTest(unittest.TestCase):
25 
26  def testOmitBoth(self):
27  with patch('mevis.MLAB.moduleInfo') as moduleInfoMock:
28  moduleName = "dummyModuleName"
29  moduleInfoMock.return_value = {TESTS_TO_OMIT_TAG: " ".join([FORMAL_TEST_IDENTIFIER, META_TEST_IDENTIFIER])}
30  omittedTests = getTestsToOmit(moduleName)
31 
32  self.assertListEqual([FORMAL_TEST_IDENTIFIER, META_TEST_IDENTIFIER], omittedTests)
33  moduleInfoMock.assert_called_once_with(moduleName)
34 
35  def testOmitNothing(self):
36  with patch('mevis.MLAB.moduleInfo') as moduleInfoMock:
37  moduleName = "dummyModuleName"
38  moduleInfoMock.return_value = {}
39  omittedTests = getTestsToOmit(moduleName)
40 
41  self.assertListEqual([], omittedTests)
42  moduleInfoMock.assert_called_once_with(moduleName)
43 
44  def testOmitAll(self):
45  with patch('mevis.MLAB.moduleInfo') as moduleInfoMock:
46  moduleName = "dummyModuleName"
47  moduleInfoMock.return_value = {TESTS_TO_OMIT_TAG: ALL_TESTS_IDENTIFIER}
48  omittedTests = getTestsToOmit(moduleName)
49 
50  self.assertIn(ALL_TESTS_IDENTIFIER, omittedTests)
51  moduleInfoMock.assert_called_once_with(moduleName)
52 
53  def testIsOmitted(self):
54  with patch('TestSupport.Generic.getTestsToOmit') as omitMock:
55  moduleName = "DummyModuleName"
56  #recognize if in list
57  omitMock.return_value = [FORMAL_TEST_IDENTIFIER, META_TEST_IDENTIFIER]
58  omitted = isTestOmitted(moduleName, FORMAL_TEST_IDENTIFIER)
59  self.assertTrue(omitted)
60  #counter-check if method in tests works as well
61  self.assertFalse(Formal.testModule(moduleName))
62  self.assertFalse(FormalMacroModule.testModule(moduleName))
63  self.assertFalse(Meta.testModule(moduleName))
64 
65  #skip also if all tests should be skipped
66  omitMock.return_value = [ALL_TESTS_IDENTIFIER]
67  omitted = isTestOmitted(moduleName, FORMAL_TEST_IDENTIFIER)
68  self.assertTrue(omitted)
69  #counter-check if method in tests works as well
70  self.assertFalse(Formal.testModule(moduleName))
71  self.assertFalse(FormalMacroModule.testModule(moduleName))
72  self.assertFalse(Meta.testModule(moduleName))
73 
74  #skip not if not in list
75  omitMock.return_value = []
76  omitted = isTestOmitted(moduleName, FORMAL_TEST_IDENTIFIER)
77  self.assertFalse(omitted)
78  #counter-check if method in tests works as well
79  self.assertTrue(Formal.testModule(moduleName))
80  self.assertTrue(FormalMacroModule.testModule(moduleName))
81  self.assertTrue(Meta.testModule(moduleName))
82 
83  if __name__ == "__main__":
84  #import sys;sys.argv = ['', 'Test.testName']
85  unittest.main()
def testOmitNothing(self)
Definition: GenericTest.py:35
def getTestsToOmit(moduleName)
Definition: Generic.py:24
def isTestOmitted(moduleName, testIdentifier)
Definition: Generic.py:49