OpenStructure
testutils.py
Go to the documentation of this file.
1 import inspect
2 import sys
3 import unittest
4 
5 from ost import xmlrunner
6 from ost.conop import GetDefaultLib
7 
8 
9 def RunTests():
10  """
11  This function behaves as a custom TestLoader for python unittests.
12 
13  With no system arguments, the default unittest TestRunner is used.
14 
15  If the first system argument (sys.argv[1]) is set to 'xml', a XMLTestRunner
16  is used, which produces a JUnit compatible XML output file. Within the current
17  module, each function is identified which is a subclass of unittest.TestCase
18  and for each TestCase, a test suite is executed, producing an individual
19  output file for each TestCase. The output file has the name,
20  'PYTEST-<TestCaseName>.xml'.
21 
22  Example of a Python testcase:
23 
24  .. code-block:: python
25 
26  import unittest
27 
28  class TestRenumber(unittest.TestCase):
29 
30  def setUp(self):
31  # prepare stuff"
32  pass
33 
34  def testSomeFunction(self):
35  # do some asserts
36  pass
37 
38  if __name__ == "__main__":
39  from ost import testutils
40  testutils.RunTests()
41 
42  """
43  try:
44  if len(sys.argv) > 1 and sys.argv[1] == 'xml':
45  import __main__
46  for name, obj in inspect.getmembers(__main__):
47  if (isinstance(obj, type) and
48  issubclass(obj, unittest.TestCase)):
49  suite = unittest.TestLoader().loadTestsFromTestCase(obj)
50  stream = open('PYTEST-%s.xml' % name, 'w')
51  xmlrunner.XMLTestRunner(stream).run(suite)
52  stream.close()
53 
54  else:
55  unittest.main()
56  except Exception as e:
57  print(e)
58 
59 
61  """
62  This function checks if a default compound library is set.
63 
64  :return: True, if a compound library was found and set to be accessed with
65  :func:`ost.conop.GetDefaultLib`. False otherwise.
66  """
67  # check if already there
68  if GetDefaultLib():
69  return True
70  else:
71  return False
def GetDefaultLib()
Definition: __init__.py:41
def RunTests()
Definition: testutils.py:9
def DefaultCompoundLibIsSet()
Definition: testutils.py:60