| … | … | @@ -6,27 +6,6 @@ |
| 6 | 6 | # the CogServer network server. |
| 7 | 7 | # |
| 8 | 8 | |
| 9 | import ctypes | |
| 10 | import os | |
| 11 | ||
| 12 | # Load the servernode library to register CogServerNode type | |
| 13 | # This must happen before we can use types.CogServerNode | |
| 14 | _lib_paths = [ | |
| 15 | # Build directory (for testing without install) | |
| 16 | os.path.join(os.path.dirname(__file__), "../../../../build/opencog/cogserver/atoms/libservernode.so"), | |
| 17 | # Installed locations | |
| 18 | "/usr/local/lib/opencog/libservernode.so", | |
| 19 | "/usr/lib/opencog/libservernode.so", | |
| 20 | ] | |
| 21 | _servernode_lib = None | |
| 22 | for _path in _lib_paths: | |
| 23 | if os.path.exists(_path): | |
| 24 | _servernode_lib = ctypes.CDLL(_path, mode=ctypes.RTLD_GLOBAL) | |
| 25 | break | |
| 26 | ||
| 27 | if _servernode_lib is None: | |
| 28 | raise ImportError("Could not find libservernode.so - is cogserver installed?") | |
| 29 | ||
| 30 | 9 | from opencog.type_constructors import get_thread_atomspace, FloatValue, VoidValue, Predicate |
| 31 | 10 | from opencog.atomspace import types |
| 32 | 11 |
| … | … | @@ -15,7 +15,7 @@ TARGET_LINK_LIBRARIES(PyEvalUTest |
| 15 | 15 | |
| 16 | 16 | # Set COGSERVER_MODULE_PATH so modules can be found in the build directory |
| 17 | 17 | SET(COGSERVER_TEST_MODULE_PATH |
| 18 | "COGSERVER_MODULE_PATH=${PROJECT_BINARY_DIR}/opencog/cogserver/modules:${PROJECT_BINARY_DIR}/opencog/cogserver/shell") | |
| 18 | "COGSERVER_MODULE_PATH=${PROJECT_BINARY_DIR}/opencog/cogserver/atoms:${PROJECT_BINARY_DIR}/opencog/cogserver/modules:${PROJECT_BINARY_DIR}/opencog/cogserver/shell") | |
| 19 | 19 | SET_PROPERTY(TEST PyEvalUTest APPEND PROPERTY ENVIRONMENT ${COGSERVER_TEST_MODULE_PATH}) |
| 20 | 20 | |
| 21 | 21 | # -------------------------- |
| … | … | @@ -27,14 +27,9 @@ ADD_TEST(NAME CogServerPythonTest |
| 27 | 27 | |
| 28 | 28 | SET_PROPERTY(TEST CogServerPythonTest |
| 29 | 29 | PROPERTY ENVIRONMENT |
| 30 | "PYTHONPATH=${CMAKE_BINARY_DIR}/opencog/cython:${PYTHON_ROOT}:$ENV{PYTHONPATH}" | |
| 31 | "LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/opencog/cogserver/server:${CMAKE_BINARY_DIR}/opencog/cython/opencog:$ENV{LD_LIBRARY_PATH}" | |
| 30 | "PYTHONPATH=${PROJECT_SOURCE_DIR}/opencog/cogserver/python:${PYTHON_ROOT}:$ENV{PYTHONPATH}" | |
| 31 | "LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/opencog/cogserver/server:$ENV{LD_LIBRARY_PATH}" | |
| 32 | 32 | ${COGSERVER_TEST_MODULE_PATH} |
| 33 | 33 | ) |
| 34 | 34 | |
| 35 | # Mark test to run after the cogserver_cython target is built | |
| 36 | SET_PROPERTY(TEST CogServerPythonTest | |
| 37 | PROPERTY DEPENDS cogserver_cython | |
| 38 | ) | |
| 39 | ||
| 40 | 35 | # -------------------------- |
| … | … | @@ -9,10 +9,25 @@ import unittest |
| 9 | 9 | import time |
| 10 | 10 | import sys |
| 11 | 11 | import os |
| 12 | import ctypes | |
| 12 | 13 | |
| 13 | 14 | # Add the source directory to Python path for the pure Python cogserver module |
| 14 | 15 | sys.path.insert(0, os.path.join(os.path.dirname(__file__), '../../opencog/cogserver/python')) |
| 15 | 16 | |
| 17 | # Load the servernode library to register CogServerNode type. | |
| 18 | # Uses COGSERVER_MODULE_PATH set by CMake for build directory testing. | |
| 19 | def _load_servernode_lib(): | |
| 20 | lib_name = "libservernode.so" | |
| 21 | module_path = os.environ.get("COGSERVER_MODULE_PATH", "") | |
| 22 | for directory in module_path.split(":"): | |
| 23 | if directory: | |
| 24 | path = os.path.join(directory, lib_name) | |
| 25 | if os.path.exists(path): | |
| 26 | return ctypes.CDLL(path, mode=ctypes.RTLD_GLOBAL) | |
| 27 | raise ImportError(f"Could not find {lib_name} - set COGSERVER_MODULE_PATH") | |
| 28 | ||
| 29 | _servernode_lib = _load_servernode_lib() | |
| 30 | ||
| 16 | 31 | try: |
| 17 | 32 | from opencog.atomspace import AtomSpace |
| 18 | 33 | from opencog.type_constructors import get_thread_atomspace, Predicate |