From 75c977b5da010f34998b3218b86f978912a781b2 Mon Sep 17 00:00:00 2001 From: Andreas Schenk <andreas_schenk@hms.harvard.edu> Date: Sun, 11 Nov 2012 23:57:50 -0500 Subject: [PATCH] removed import of geom,io,mol,seq,gfx and img from ost base __init__.py changed python unit tests to run with python instead of ost Remarks ------- Python unit tests using blast, clustalw or the compound lib where skipped on my system. There might be still some missing imports in these tests. --- cmake_support/OST.cmake | 11 ++++++-- modules/base/pymod/CMakeLists.txt | 25 ++++++++++++++++++- .../pymod/{__init__.py => __init__.py.in} | 21 +++------------- modules/base/tests/test_log.py | 1 + modules/bindings/tests/test_blast.py | 1 + modules/bindings/tests/test_clustalw.py | 1 + modules/conop/tests/test_cleanup.py | 1 + modules/gui/pymod/dng/init.py | 3 +++ modules/io/tests/test_io_mmcif.py | 1 + .../alg/tests/test_convenient_superpose.py | 1 + modules/seq/alg/tests/test_renumber.py | 1 + scripts/init_cl.py | 6 +++++ 12 files changed, 52 insertions(+), 21 deletions(-) rename modules/base/pymod/{__init__.py => __init__.py.in} (67%) diff --git a/cmake_support/OST.cmake b/cmake_support/OST.cmake index fb478ec08..1145f5cdb 100644 --- a/cmake_support/OST.cmake +++ b/cmake_support/OST.cmake @@ -423,6 +423,7 @@ macro(script) if (NOT _ARG_INPUT) message(FATAL_ERROR "script() can only substitute when INPUT is present.") endif() + substitute(IN_FILE "${CMAKE_CURRENT_SOURCE_DIR}/${_INPUT}" OUT_FILE ${_ARG_NAME} DICT ${_ARG_SUBSTITUTE}) endif() @@ -687,15 +688,21 @@ macro(ost_unittest) set_target_properties("${_test_name}_run" PROPERTIES EXCLUDE_FROM_ALL "1") endif() endif() + foreach(py_test ${PY_TESTS}) if(WIN32) - set (PY_TESTS_CMD "${EXECUTABLE_OUTPUT_PATH}/ost.bat") + set (PY_TESTS_CMD "${PYTHON_BINARY}") add_custom_target("${py_test}_run" CALL "${PY_TESTS_CMD} ${CMAKE_CURRENT_SOURCE_DIR}/${py_test} || echo" WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} COMMENT "running checks ${py_test}" VERBATIM) else() - set (PY_TESTS_CMD "${EXECUTABLE_OUTPUT_PATH}/ost") + set(python_path $ENV{PYTHONPATH}) + if(python_path) + set(python_path "${python_path}:") + endif(python_path) + set(python_path "${python_path}${LIB_STAGE_PATH}/python${PYTHON_VERSION}/site-packages") + set (PY_TESTS_CMD "PYTHONPATH=${python_path} ${PYTHON_BINARY}") add_custom_target("${py_test}_run" sh -c "${PY_TESTS_CMD} ${CMAKE_CURRENT_SOURCE_DIR}/${py_test} || echo" WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} diff --git a/modules/base/pymod/CMakeLists.txt b/modules/base/pymod/CMakeLists.txt index 6a011018f..433dfeb9f 100644 --- a/modules/base/pymod/CMakeLists.txt +++ b/modules/base/pymod/CMakeLists.txt @@ -7,5 +7,28 @@ set(OST_BASE_PYMOD_SOURCES if (NOT ENABLE_STATIC) pymod(NAME base OUTPUT_DIR ost CPP ${OST_BASE_PYMOD_SOURCES} - PY __init__.py settings.py stutil.py table.py xmlrunner.py testutils.py) + PY settings.py stutil.py table.py xmlrunner.py testutils.py) endif() + +set(SQ "\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\'") +set(SUBST_DICT "ALL_ADDITIONAL_MODULES=") +if(ENABLE_GUI) + set(SUBST_DICT "${SUBST_DICT},${SQ}gui${SQ}") +endif(ENABLE_GUI) +if(ENABLE_GFX) + set(SUBST_DICT "${SUBST_DICT},${SQ}gfx${SQ}") +endif(ENABLE_GFX) +if(ENABLE_IMG) + set(SUBST_DICT "${SUBST_DICT},${SQ}img${SQ}") +endif(ENABLE_IMG) +if(ENABLE_INFO) + set(SUBST_DICT ${SUBST_DICT},${SQ}info${SQ}) +endif(ENABLE_INFO) + + +script(NAME __init__.py + INPUT __init__.py.in + SUBSTITUTE "${SUBST_DICT}" + TARGET ost_base_pymod + OUTPUT_DIR "${LIB_DIR}/python${PYTHON_VERSION}/site-packages/ost") + diff --git a/modules/base/pymod/__init__.py b/modules/base/pymod/__init__.py.in similarity index 67% rename from modules/base/pymod/__init__.py rename to modules/base/pymod/__init__.py.in index 8ecfacd79..4b1be9f6c 100644 --- a/modules/base/pymod/__init__.py +++ b/modules/base/pymod/__init__.py.in @@ -16,27 +16,12 @@ # along with this library; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA #------------------------------------------------------------------------------ -from _ost_base import * -from stutil import * -from ost import geom -from ost import io -from ost import mol -from ost import seq -try: - from ost import gfx - scene = gfx.Scene() - scene.Stereo=gfx.Stereo -except ImportError: - pass - - -try: - from ost import img -except ImportError: - pass +__all__=['Correl', 'FileLogSink', 'FloatList', 'GetCurrentLogSink', 'GetPrefixPath', 'GetSharedDataPath', 'GetVerbosityLevel', 'Histogram', 'IntList', 'LogDebug', 'LogError', 'LogInfo', 'LogScript', 'LogSink', 'LogTrace', 'LogVerbose', 'LogWarning', 'Max', 'Mean', 'Median', 'Min', 'MultiLogSink', 'PopLogSink', 'PopVerbosityLevel', 'PushLogSink', 'PushVerbosityLevel', 'Range', 'SetPrefixPath', 'StdDev', 'StreamLogSink', 'StringList', 'StringLogSink', 'Units', 'VERSION', 'VERSION_MAJOR', 'VERSION_MINOR', 'VERSION_PATCH', 'WITH_NUMPY', 'conop', 'geom', 'io', 'mol', 'seq', 'stutil' @ALL_ADDITIONAL_MODULES@] +from _ost_base import * +from stutil import * class StreamLogSink(LogSink): def __init__(self, stream): diff --git a/modules/base/tests/test_log.py b/modules/base/tests/test_log.py index cec9378ed..2527159d4 100644 --- a/modules/base/tests/test_log.py +++ b/modules/base/tests/test_log.py @@ -30,6 +30,7 @@ class TestLog(unittest.TestCase): self.severity=severity ost.PushLogSink(ls) ls=CapturingLogSink() + ost.PushVerbosityLevel(1) ost.PushLogSink(ls) ost.LogError('error message') self.assertEqual(ls.message, 'error message\n') diff --git a/modules/bindings/tests/test_blast.py b/modules/bindings/tests/test_blast.py index 54a5c4ef8..85a65ea24 100644 --- a/modules/bindings/tests/test_blast.py +++ b/modules/bindings/tests/test_blast.py @@ -1,3 +1,4 @@ +import sys import unittest from ost import * from ost import settings diff --git a/modules/bindings/tests/test_clustalw.py b/modules/bindings/tests/test_clustalw.py index fa5a5e6b5..9aaf210f8 100644 --- a/modules/bindings/tests/test_clustalw.py +++ b/modules/bindings/tests/test_clustalw.py @@ -1,3 +1,4 @@ +import sys import unittest from ost import * from ost import settings diff --git a/modules/conop/tests/test_cleanup.py b/modules/conop/tests/test_cleanup.py index 1dc280f4f..11df64187 100644 --- a/modules/conop/tests/test_cleanup.py +++ b/modules/conop/tests/test_cleanup.py @@ -1,3 +1,4 @@ +import sys import unittest from ost import geom, conop from ost.conop import cleanup diff --git a/modules/gui/pymod/dng/init.py b/modules/gui/pymod/dng/init.py index d46af73d8..ef122cd97 100644 --- a/modules/gui/pymod/dng/init.py +++ b/modules/gui/pymod/dng/init.py @@ -12,6 +12,9 @@ try: except ImportError: _img_present=False pass +ost.scene = gfx.Scene() +ost.scene.Stereo=gfx.Stereo + import httplib from PyQt4 import QtGui, QtCore diff --git a/modules/io/tests/test_io_mmcif.py b/modules/io/tests/test_io_mmcif.py index 94eb06330..46eda067e 100644 --- a/modules/io/tests/test_io_mmcif.py +++ b/modules/io/tests/test_io_mmcif.py @@ -1,4 +1,5 @@ import unittest +import ost from ost import * class TestMMCifInfo(unittest.TestCase): diff --git a/modules/mol/alg/tests/test_convenient_superpose.py b/modules/mol/alg/tests/test_convenient_superpose.py index eb4331ca3..728f315de 100644 --- a/modules/mol/alg/tests/test_convenient_superpose.py +++ b/modules/mol/alg/tests/test_convenient_superpose.py @@ -1,3 +1,4 @@ +from ost import io,mol,geom import unittest import os import random diff --git a/modules/seq/alg/tests/test_renumber.py b/modules/seq/alg/tests/test_renumber.py index 51e4727d3..8f234f859 100644 --- a/modules/seq/alg/tests/test_renumber.py +++ b/modules/seq/alg/tests/test_renumber.py @@ -1,3 +1,4 @@ +import sys import unittest from ost import * from ost import settings diff --git a/scripts/init_cl.py b/scripts/init_cl.py index bb8090b5e..2c7a04810 100644 --- a/scripts/init_cl.py +++ b/scripts/init_cl.py @@ -34,6 +34,12 @@ else: from ost import * import ost +try: + from ost import gfx + ost.scene = gfx.Scene() + ost.scene.Stereo=gfx.Stereo +except ImportError: + pass ost.SetPrefixPath(os.getenv('DNG_ROOT')) def _InitRuleBasedBuilder(): -- GitLab