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