diff --git a/python/mochi/flock/__init__.py b/python/mochi/flock/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/python/mochi/flock/test_client.py b/python/mochi/flock/test_client.py new file mode 100644 index 0000000..4535fb5 --- /dev/null +++ b/python/mochi/flock/test_client.py @@ -0,0 +1,17 @@ +import unittest +import mochi.flock.client as mfc +from pymargo.core import Engine + +class TestClient(unittest.TestCase): + + def test_init_client_from_address(self): + client = mfc.Client("na+sm") + + def test_init_client_from_engine(self): + with Engine("na+sm") as engine: + client = mfc.Client(engine) + del client + + +if __name__ == '__main__': + unittest.main() diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index d1417a5..8e7a9fa 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -15,3 +15,28 @@ foreach (test-source ${test-sources}) add_test (NAME ${name} COMMAND ./${name}) endif () endforeach () + +if (ENABLE_PYTHON) + # Set the path to the python directory + set (PYTHON_MODULE_DIR ${CMAKE_SOURCE_DIR}/python) + # Use file(GLOB_RECURSE ...) to find all files matching the test_*.py pattern + file (GLOB_RECURSE PYTHON_TEST_FILES "${PYTHON_MODULE_DIR}/test_*.py") + + foreach (PYTHON_TEST_FILE ${PYTHON_TEST_FILES}) + # Remove the directory part + file (RELATIVE_PATH PYTHON_TEST_FILE_REL ${PYTHON_MODULE_DIR} ${PYTHON_TEST_FILE}) + # Remove the file extension + string (REPLACE ".py" "" PYTHON_TEST_FILE_BASE ${PYTHON_TEST_FILE_REL}) + # Replace slashes with dots + string (REPLACE "/" "." PYTHON_TEST_NAME ${PYTHON_TEST_FILE_BASE}) + # Add the test + if (${ENABLE_COVERAGE}) + message (STATUS "${PYTHON_TEST_NAME} test will run with code coverage") + add_test (NAME ${PYTHON_TEST_NAME} COMMAND coverage run -a -m unittest ${PYTHON_TEST_NAME}) + else () + add_test (NAME ${PYTHON_TEST_NAME} COMMAND python -m unittest ${PYTHON_TEST_NAME}) + endif () + set_property (TEST ${PYTHON_TEST_NAME} PROPERTY ENVIRONMENT + PYTHONPATH=${CMAKE_SOURCE_DIR}/python/:${CMAKE_BINARY_DIR}/python:$ENV{PYTHONPATH}) + endforeach () +endif () diff --git a/tests/spack.yaml b/tests/spack.yaml index de35b49..3477a46 100644 --- a/tests/spack.yaml +++ b/tests/spack.yaml @@ -9,6 +9,7 @@ spack: - mpich - py-pybind11 - py-mochi-margo + - py-coverage concretizer: unify: true reuse: true