From 7995103e4c0fa82ebe80175a61d836dc2b43aede Mon Sep 17 00:00:00 2001 From: Xavier Robin <xavalias-github@xavier.robin.name> Date: Thu, 11 May 2023 17:01:46 +0200 Subject: [PATCH] test: SCHWED-5913 compound lib is now set testutils.SetDefaultCompoundLib no longer needs to set the default compound lib explicitly, as this is handled by import ost. The method is still needed to check if a compound lib is available, and was accordingly renamed to DefaultCompoundLibIsSet. --- modules/base/doc/testutils.rst | 2 +- modules/base/pymod/testutils.py | 48 ++----------------- modules/conop/tests/test_cleanup.py | 2 +- modules/conop/tests/test_complib.py | 2 +- modules/conop/tests/test_compound.py | 2 +- modules/io/tests/test_io_omf.py | 2 +- modules/mol/alg/tests/test_chain_mapping.py | 2 +- modules/mol/alg/tests/test_lddt.py | 2 +- modules/mol/alg/tests/test_ligand_scoring.py | 2 +- modules/mol/alg/tests/test_nonstandard.py | 2 +- modules/mol/alg/tests/test_qsscore.py | 2 +- modules/mol/alg/tests/test_qsscoring.py | 2 +- modules/mol/alg/tests/test_stereochemistry.py | 2 +- modules/seq/alg/tests/test_aaindex.py | 2 +- modules/seq/alg/tests/test_aligntoseqres.py | 2 +- 15 files changed, 19 insertions(+), 57 deletions(-) diff --git a/modules/base/doc/testutils.rst b/modules/base/doc/testutils.rst index df61f56e7..dabf827e6 100644 --- a/modules/base/doc/testutils.rst +++ b/modules/base/doc/testutils.rst @@ -6,4 +6,4 @@ .. autofunction:: ost.testutils.RunTests -.. autofunction:: ost.testutils.SetDefaultCompoundLib +.. autofunction:: ost.testutils.DefaultCompoundLibIsSet diff --git a/modules/base/pymod/testutils.py b/modules/base/pymod/testutils.py index 4b701fe08..af5f7b66c 100644 --- a/modules/base/pymod/testutils.py +++ b/modules/base/pymod/testutils.py @@ -54,54 +54,16 @@ def RunTests(): print(e) -def SetDefaultCompoundLib(): +def DefaultCompoundLibIsSet(): ''' - 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.' + This function checks if a default compound library is set. :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 + from ost. conop import GetDefaultLib # check if already there - if conop.GetDefaultLib(): + if GetDefaultLib(): return True else: - # try to get the shared data path? - try: - shared_data_path = GetSharedDataPath() - except Exception as 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 + return False diff --git a/modules/conop/tests/test_cleanup.py b/modules/conop/tests/test_cleanup.py index 54d33a8bc..3abc1f5ff 100644 --- a/modules/conop/tests/test_cleanup.py +++ b/modules/conop/tests/test_cleanup.py @@ -160,7 +160,7 @@ class TestCleanUp(unittest.TestCase): if __name__ == "__main__": from ost import testutils - if testutils.SetDefaultCompoundLib(): + if testutils.DefaultCompoundLibIsSet(): testutils.RunTests() else: print('No compound library available. Ignoring test_cleanup.py tests.') diff --git a/modules/conop/tests/test_complib.py b/modules/conop/tests/test_complib.py index dca8dc3e9..2c3e3f812 100644 --- a/modules/conop/tests/test_complib.py +++ b/modules/conop/tests/test_complib.py @@ -31,7 +31,7 @@ class TestCompLib(unittest.TestCase): if __name__ == "__main__": from ost import testutils - if testutils.SetDefaultCompoundLib(): + if testutils.DefaultCompoundLibIsSet(): testutils.RunTests() else: print('No compound lib available. Ignoring test_complib tests.') \ No newline at end of file diff --git a/modules/conop/tests/test_compound.py b/modules/conop/tests/test_compound.py index 01c59a233..a6c704d40 100644 --- a/modules/conop/tests/test_compound.py +++ b/modules/conop/tests/test_compound.py @@ -25,7 +25,7 @@ class TestCompound(unittest.TestCase): if __name__=='__main__': from ost import testutils - if testutils.SetDefaultCompoundLib(): + if testutils.DefaultCompoundLibIsSet(): testutils.RunTests() else: print('No compound library available. Ignoring test_compound.py tests.') \ No newline at end of file diff --git a/modules/io/tests/test_io_omf.py b/modules/io/tests/test_io_omf.py index 1ed14044a..8d519c508 100644 --- a/modules/io/tests/test_io_omf.py +++ b/modules/io/tests/test_io_omf.py @@ -248,7 +248,7 @@ class TestOMF(unittest.TestCase): if __name__== '__main__': from ost import testutils - if testutils.SetDefaultCompoundLib(): + if testutils.DefaultCompoundLibIsSet(): testutils.RunTests() else: print('No compound library available. Ignoring test_stereochemistry.py tests.') diff --git a/modules/mol/alg/tests/test_chain_mapping.py b/modules/mol/alg/tests/test_chain_mapping.py index 8c8846aba..16fd363e5 100644 --- a/modules/mol/alg/tests/test_chain_mapping.py +++ b/modules/mol/alg/tests/test_chain_mapping.py @@ -362,7 +362,7 @@ class TestChainMapper(unittest.TestCase): if __name__ == "__main__": from ost import testutils - if testutils.SetDefaultCompoundLib(): + if testutils.DefaultCompoundLibIsSet(): testutils.RunTests() else: print('No compound lib available. Ignoring test_chain_mapping.py tests.') diff --git a/modules/mol/alg/tests/test_lddt.py b/modules/mol/alg/tests/test_lddt.py index cb8f1d28a..6cfe9d5b6 100644 --- a/modules/mol/alg/tests/test_lddt.py +++ b/modules/mol/alg/tests/test_lddt.py @@ -276,7 +276,7 @@ class TestlDDTBS(unittest.TestCase): if __name__ == "__main__": from ost import testutils - if testutils.SetDefaultCompoundLib(): + if testutils.DefaultCompoundLibIsSet(): testutils.RunTests() else: print('No compound library available. Ignoring test_lddt.py tests.') diff --git a/modules/mol/alg/tests/test_ligand_scoring.py b/modules/mol/alg/tests/test_ligand_scoring.py index b23de7b9c..a1de22761 100644 --- a/modules/mol/alg/tests/test_ligand_scoring.py +++ b/modules/mol/alg/tests/test_ligand_scoring.py @@ -341,7 +341,7 @@ class TestLigandScoring(unittest.TestCase): if __name__ == "__main__": from ost import testutils - if testutils.SetDefaultCompoundLib(): + if testutils.DefaultCompoundLibIsSet(): testutils.RunTests() else: print('No compound lib available. Ignoring test_ligand_scoring.py tests.') diff --git a/modules/mol/alg/tests/test_nonstandard.py b/modules/mol/alg/tests/test_nonstandard.py index c7f49215e..99bf7fdd0 100644 --- a/modules/mol/alg/tests/test_nonstandard.py +++ b/modules/mol/alg/tests/test_nonstandard.py @@ -163,7 +163,7 @@ class TestNonStandard(unittest.TestCase): if __name__ == "__main__": from ost import testutils - if testutils.SetDefaultCompoundLib(): + if testutils.DefaultCompoundLibIsSet(): testutils.RunTests() else: print('No compound library available. Ignoring test_nonstandard.py tests.') diff --git a/modules/mol/alg/tests/test_qsscore.py b/modules/mol/alg/tests/test_qsscore.py index 34ba726ad..5aed15ee8 100644 --- a/modules/mol/alg/tests/test_qsscore.py +++ b/modules/mol/alg/tests/test_qsscore.py @@ -264,7 +264,7 @@ class TestQSScore(unittest.TestCase): if __name__ == "__main__": from ost import testutils - if testutils.SetDefaultCompoundLib(): + if testutils.DefaultCompoundLibIsSet(): testutils.RunTests() else: print('No compound lib available. Ignoring test_qsscore.py tests.') diff --git a/modules/mol/alg/tests/test_qsscoring.py b/modules/mol/alg/tests/test_qsscoring.py index 31daffe56..fc73c72d6 100644 --- a/modules/mol/alg/tests/test_qsscoring.py +++ b/modules/mol/alg/tests/test_qsscoring.py @@ -706,7 +706,7 @@ if __name__ == "__main__": print("Could not find ClustalW. Ignoring test_qsscoring.py tests.") sys.exit(0) from ost import testutils - if testutils.SetDefaultCompoundLib(): + if testutils.DefaultCompoundLibIsSet(): testutils.RunTests() else: print('No compound library available. Ignoring test_qsscoring.py tests.') diff --git a/modules/mol/alg/tests/test_stereochemistry.py b/modules/mol/alg/tests/test_stereochemistry.py index ae458d4b5..b449c669b 100644 --- a/modules/mol/alg/tests/test_stereochemistry.py +++ b/modules/mol/alg/tests/test_stereochemistry.py @@ -209,7 +209,7 @@ class TestStereochemistry(unittest.TestCase): if __name__ == "__main__": from ost import testutils - if testutils.SetDefaultCompoundLib(): + if testutils.DefaultCompoundLibIsSet(): testutils.RunTests() else: print('No compound library available. Ignoring test_stereochemistry.py tests.') diff --git a/modules/seq/alg/tests/test_aaindex.py b/modules/seq/alg/tests/test_aaindex.py index a1915e28e..2fcd8002c 100644 --- a/modules/seq/alg/tests/test_aaindex.py +++ b/modules/seq/alg/tests/test_aaindex.py @@ -45,5 +45,5 @@ if __name__ == "__main__": from ost import testutils # the function below indirectly enables GetSharedDataPath when # calling stuff from python which is the case in unit tests - testutils.SetDefaultCompoundLib() + testutils.DefaultCompoundLibIsSet() testutils.RunTests() diff --git a/modules/seq/alg/tests/test_aligntoseqres.py b/modules/seq/alg/tests/test_aligntoseqres.py index 5664ff837..642edb805 100644 --- a/modules/seq/alg/tests/test_aligntoseqres.py +++ b/modules/seq/alg/tests/test_aligntoseqres.py @@ -68,7 +68,7 @@ class TestAlignToSeqRes(unittest.TestCase): if __name__ == "__main__": from ost import testutils - if testutils.SetDefaultCompoundLib(): + if testutils.DefaultCompoundLibIsSet(): testutils.RunTests() else: print('No compound library available. Ignoring test_aligntoseqres.py tests.') -- GitLab