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