Skip to content
Snippets Groups Projects
Commit 5df51d99 authored by Gerardo Tauriello's avatar Gerardo Tauriello
Browse files

Unified handling for compound lib dependent python unittests.

This also enabled test_cleanup, test_nonstandard and test_aligntoseqres which
were previously skipped with 'make check' indep. of compound lib availability
(simply because unittests are launched with 'python' and not with 'ost').
parent d378d67d
No related branches found
No related tags found
No related merge requests found
......@@ -4,4 +4,6 @@
.. module:: ost.testutils
:synopsis: Helper Functions to Run Python Unittests
.. autofunction:: ost.testutils.RunTests
\ No newline at end of file
.. autofunction:: ost.testutils.RunTests
.. autofunction:: ost.testutils.SetDefaultCompoundLib
......@@ -51,4 +51,57 @@ def RunTests():
else:
unittest.main()
except Exception, e:
print e
\ No newline at end of file
print e
def SetDefaultCompoundLib():
'''
This function tries to ensure that a default compound library is set.
When calling scripts with ``ost`` this is not needed, but since unit tests are
called with ``python`` we need to ensure that it is set. The function is only
expected to succeed (and return True) if ``COMPOUND_LIB`` was set when
:ref:`configuring the compilation <cmake-flags>`.
It tries the following:
- get it with :func:`ost.conop.GetDefaultLib`
- look for ``compounds.chemlib`` in ``$OST_ROOT/share/openstructure``
- if ``OST_ROOT`` not set in the above, try to guess it based on the path of
the ``conop`` module
To use this check modify the :func:`RunTests` call to read:
.. code-block:: python
if __name__ == "__main__":
from ost import testutils
if testutils.SetDefaultCompoundLib():
testutils.RunTests()
else:
print 'No compound library available. Ignoring test_XXX.py tests.'
:return: True, if a compound library was found and set to be accessed with
:func:`ost.conop.GetDefaultLib`. False otherwise.
'''
import os
from ost import conop, GetSharedDataPath, SetPrefixPath
# check if already there
if conop.GetDefaultLib():
return True
else:
# try to get the shared data path?
try:
shared_data_path = GetSharedDataPath()
except Exception, e:
SetPrefixPath(os.path.abspath(os.path.join(conop.__path__[0], os.pardir,
os.pardir, os.pardir,
os.pardir, os.pardir)))
shared_data_path = GetSharedDataPath()
# look for compounds.chemlib in there
compound_lib_path = os.path.join(shared_data_path, 'compounds.chemlib')
if os.path.exists(compound_lib_path):
compound_lib = conop.CompoundLib.Load(compound_lib_path)
conop.SetDefaultLib(compound_lib)
return True
else:
return False
......@@ -25,7 +25,7 @@ build the compound library manually.
OpenStructure as a bundle or you :ref:`compiled <cmake-flags>` it
with a specified ``COMPOUND_LIB`` flag, this will return a compound
library when executing scripts with ``ost``.
:rtype: :class:`CompoundLib`
:rtype: :class:`CompoundLib` or None if no library set
.. function:: SetDefaultLib(lib)
......
......@@ -4,13 +4,13 @@ set(OST_CONOP_UNIT_TESTS
tests.cc
test_rule_based_conop.cc
helper.cc
test_cleanup.py
test_processor.py
test_nonstandard.py
)
if (COMPOUND_LIB)
list(APPEND OST_CONOP_UNIT_TESTS test_compound.py)
list(APPEND OST_CONOP_UNIT_TESTS test_compound.py
test_cleanup.py
test_nonstandard.py)
endif()
ost_unittest(MODULE conop
......
import sys
import unittest
from ost import geom, conop
from ost import geom, conop, io
from ost.conop import cleanup
class TestCleanUp(unittest.TestCase):
def setUp(self):
self.comp_lib=conop.GetDefaultLib()
self.comp_lib = conop.GetDefaultLib()
io.profiles['DEFAULT'].processor = conop.RuleBasedProcessor(self.comp_lib)
self.ent = io.LoadPDB("sample_test_cleanup.pdb")
self.ent_no_wat = io.LoadPDB("sample_nowater.pdb")
self.ent_no_lig = io.LoadPDB("sample_noligands.pdb")
......@@ -156,10 +157,10 @@ class TestCleanUp(unittest.TestCase):
self.assertFalse(self.new_ent.residues[6].IsPeptideLinking()) # here assertFalse instead of assertTrue
self.assertTrue(self.new_ent.residues[6].atoms[0].is_hetatom)
if not conop.GetDefaultLib():
print 'No compound library available. Ignoring test_cleanup.py tests'
sys.exit()
if __name__== '__main__':
if __name__ == "__main__":
from ost import testutils
testutils.RunTests()
if testutils.SetDefaultCompoundLib():
testutils.RunTests()
else:
print 'No compound library available. Ignoring test_cleanup.py tests.'
import unittest
import os
from ost import GetSharedDataPath, SetPrefixPath
from ost import mol
from ost import conop
from ost import mol, conop
def setUpModule():
SetPrefixPath(os.path.abspath(os.path.join(conop.__path__[0], os.pardir,
os.pardir, os.pardir,
os.pardir, os.pardir)))
compound_lib_path = os.path.join(GetSharedDataPath(),
'compounds.chemlib')
compound_lib = conop.CompoundLib.Load(compound_lib_path)
conop.SetDefaultLib(compound_lib)
class TestCompound(unittest.TestCase):
def setUp(self):
......@@ -36,5 +25,7 @@ class TestCompound(unittest.TestCase):
if __name__=='__main__':
from ost import testutils
testutils.RunTests()
if testutils.SetDefaultCompoundLib():
testutils.RunTests()
else:
print 'No compound library available. Ignoring test_compound.py tests.'
\ No newline at end of file
import unittest
from ost import conop
from ost import conop, io, mol
class TestNonStandard(unittest.TestCase):
......@@ -117,10 +117,8 @@ class TestNonStandard(unittest.TestCase):
if __name__ == "__main__":
if not conop.GetDefaultLib():
print 'No compound library available. Ignoring unit tests'
else:
from ost import testutils
from ost import testutils
if testutils.SetDefaultCompoundLib():
testutils.RunTests()
else:
print 'No compound library available. Ignoring test_nonstandard.py tests.'
import unittest
import ost, os
from ost import io, conop
from ost import GetSharedDataPath, SetPrefixPath
import unittest, os
from ost import io
from ost.mol.alg.qsscoring import *
def _LoadFile(file_name):
"""Helper to avoid repeating input path over and over."""
return io.LoadPDB(os.path.join('testfiles', file_name))
def setUpModule():
"""Called once by unittest: ensures that we have a compound library."""
if not conop.GetDefaultLib():
SetPrefixPath(os.path.abspath(os.path.join(conop.__path__[0], os.pardir,
os.pardir, os.pardir,
os.pardir, os.pardir)))
compound_lib_path = os.path.join(GetSharedDataPath(),
'compounds.chemlib')
compound_lib = conop.CompoundLib.Load(compound_lib_path)
conop.SetDefaultLib(compound_lib)
class TestQSscore(unittest.TestCase):
......@@ -192,6 +180,9 @@ class TestQSscore(unittest.TestCase):
self.assertAlmostEqual(qs_scorer.best_score, 0.975, 2)
if __name__== '__main__':
if __name__ == "__main__":
from ost import testutils
testutils.RunTests()
if testutils.SetDefaultCompoundLib():
testutils.RunTests()
else:
print 'No compound library available. Ignoring test_qsscoring.py tests.'
......@@ -8,9 +8,12 @@ set(OST_SEQ_ALG_UNIT_TESTS
test_global_align.py
test_semiglobal_align.py
test_weight_matrix.py
test_aligntoseqres.py
)
if (COMPOUND_LIB)
list(APPEND OST_SEQ_ALG_UNIT_TESTS test_aligntoseqres.py)
endif()
ost_unittest(MODULE seq_alg SOURCES "${OST_SEQ_ALG_UNIT_TESTS}"
LINK ost_mol ost_io)
import unittest
from ost import *
from ost import settings
from ost import seq
from ost import io
import ost
from ost import seq, io, mol
class TestAlignToSeqRes(unittest.TestCase):
def testAlignWorking(self):
......@@ -67,9 +65,10 @@ class TestAlignToSeqRes(unittest.TestCase):
validate = False)
self.assertEqual(seq.alg.ValidateSEQRESAlignment(seqres_aln, chain), False)
if __name__ == "__main__":
if not conop.GetDefaultLib():
print 'No compound library available. Ignoring unit tests'
else:
from ost import testutils
from ost import testutils
if testutils.SetDefaultCompoundLib():
testutils.RunTests()
else:
print 'No compound library available. Ignoring test_aligntoseqres.py tests.'
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment