TestCenter Reference
UnitTestSupport.py
Go to the documentation of this file.
1 #
2 # Copyright 2018, 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 import unittest
12 import inspect
13 import os
14 
15 # This module contains methods that are handy when using the python unittest framework within the TestCenter.
16 
17 class TestCaseWithSupportData(unittest.TestCase):
18  """
19  This is a helper class that can be used instead of TestSupport.Base.getDataDirectory()
20  It allows you to access the Tests Data directory from a unittest, no matter whether it's wrapped in a TestCenter test
21  or whether you call it directly from python.
22  In the latter case, the Data directory is expected to be in the folder where your python TestCase is defined.
23  To access the folder, use self.getTestSupportDataDirectory() or self.getFileInTestSupportDataDirectory("example.txt")
24 
25  E.g.:
26  MyTestCase
27  - MyTestCase.def
28  - MyTestCase.py
29  - Data
30  - exampleInput.txt
31  """
32 
33  @classmethod
35  return _getDataDirectory(cls)
36 
37  @classmethod
39  return os.path.join(cls.getTestSupportDataDirectorygetTestSupportDataDirectory(), filename)
40 
41 
42 def _isTestHelperAvailable():
43  try:
44  from TestSupport.Base import TestHelper
45  TestHelper()
46  return True
47  except (ImportError, Exception):
48  return False
49 
50 if _isTestHelperAvailable():
51  from TestSupport.Base import getDataDirectory as getTestSupportDataDirectory
52 
53  def _getDataDirectory(testCaseClass):
54  # inspect.getfile() would not work inside MeVisLab, therefore rely on the TestSupport function:
56 else:
57  def _getDataDirectory(testCaseClass):
58  sourcePath = inspect.getfile(testCaseClass)
59  return os.path.join(os.path.dirname(sourcePath), "Data")
A singleton to provide important data for the testing process.
Basic support functions.
Definition: Base.py:1