Skip to content

Commit

Permalink
started adding unit tests for python module
Browse files Browse the repository at this point in the history
  • Loading branch information
mdorier committed Jun 10, 2024
1 parent fc55d5a commit a89ce9e
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 0 deletions.
Empty file added python/mochi/flock/__init__.py
Empty file.
17 changes: 17 additions & 0 deletions python/mochi/flock/test_client.py
Original file line number Diff line number Diff line change
@@ -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()
25 changes: 25 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 ()
1 change: 1 addition & 0 deletions tests/spack.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ spack:
- mpich
- py-pybind11
- py-mochi-margo
- py-coverage
concretizer:
unify: true
reuse: true
Expand Down

0 comments on commit a89ce9e

Please sign in to comment.