3 This function behaves as a custom TestLoader for python unittests.
5 With no system arguments, the default unittest TestRunner is used.
7 If the first system argument (sys.argv[1]) is set to 'xml', a XMLTestRunner
8 is used, which produces a JUnit compatible XML output file. Within the current
9 module, each function is identified which is a subclass of unittest.TestCase
10 and for each TestCase, a test suite is executed, producing an individual
11 output file for each TestCase. The output file has the name,
12 'PYTEST-<TestCaseName>.xml'.
14 Example of a Python testcase:
16 .. code-block:: python
20 class TestRenumber(unittest.TestCase):
26 def testSomeFunction(self):
30 if __name__ == "__main__":
31 from ost import testutils
38 if len(sys.argv)>1
and sys.argv[1]==
'xml':
42 from ost
import xmlrunner
43 for name, obj
in inspect.getmembers(__main__):
44 if (isinstance(obj, (type, types.ClassType))
and
45 issubclass(obj, unittest.TestCase)):
46 suite = unittest.TestLoader().loadTestsFromTestCase(obj)
47 stream = open(
'PYTEST-%s.xml'%name,
'w')
59 This function tries to ensure that a default compound library is set.
60 When calling scripts with ``ost`` this is not needed, but since unit tests are
61 called with ``python`` we need to ensure that it is set. The function is only
62 expected to succeed (and return True) if ``COMPOUND_LIB`` was set when
63 :ref:`configuring the compilation <cmake-flags>`.
65 It tries the following:
67 - get it with :func:`ost.conop.GetDefaultLib`
68 - look for ``compounds.chemlib`` in ``$OST_ROOT/share/openstructure``
69 - if ``OST_ROOT`` not set in the above, try to guess it based on the path of
72 To use this check modify the :func:`RunTests` call to read:
74 .. code-block:: python
76 if __name__ == "__main__":
77 from ost import testutils
78 if testutils.SetDefaultCompoundLib():
81 print 'No compound library available. Ignoring test_XXX.py tests.'
83 :return: True, if a compound library was found and set to be accessed with
84 :func:`ost.conop.GetDefaultLib`. False otherwise.
87 from ost
import conop, GetSharedDataPath, SetPrefixPath
89 if conop.GetDefaultLib():
96 SetPrefixPath(os.path.abspath(os.path.join(conop.__path__[0], os.pardir,
98 os.pardir, os.pardir)))
101 compound_lib_path = os.path.join(shared_data_path,
'compounds.chemlib')
102 if os.path.exists(compound_lib_path):
103 compound_lib = conop.CompoundLib.Load(compound_lib_path)
104 conop.SetDefaultLib(compound_lib)
void DLLEXPORT_OST_BASE SetPrefixPath(const String &prefix)
set path prefix
String DLLEXPORT_OST_BASE GetSharedDataPath()
def SetDefaultCompoundLib