diff --git a/python/lammps.py b/python/lammps.py index 534559a75b..f4fe23dd4d 100644 --- a/python/lammps.py +++ b/python/lammps.py @@ -2388,7 +2388,7 @@ class IPyLammps(PyLammps): :type zoom: float :param background_color: background color of scene :type background_color: string - + :return: Image instance used to display image in notebook :rtype: :py:class:`IPython.core.display.Image` """ diff --git a/unittest/python/CMakeLists.txt b/unittest/python/CMakeLists.txt index a01f3cdb0a..dd9d3a54c5 100644 --- a/unittest/python/CMakeLists.txt +++ b/unittest/python/CMakeLists.txt @@ -30,7 +30,7 @@ if (Python_EXECUTABLE) if(ENABLE_COVERAGE) find_program(COVERAGE_BINARY coverage) find_package_handle_standard_args(COVERAGE DEFAULT_MSG COVERAGE_BINARY) - + if(COVERAGE_FOUND) set(PYTHON_TEST_RUNNER ${Python_EXECUTABLE} ${COVERAGE_BINARY} run --parallel-mode --include=${LAMMPS_PYTHON_DIR}/lammps.py --omit=${LAMMPS_PYTHON_DIR}/install.py) else() @@ -59,6 +59,11 @@ if (Python_EXECUTABLE) COMMAND ${PYTHON_TEST_RUNNER} ${CMAKE_CURRENT_SOURCE_DIR}/python-capabilities.py -v WORKING_DIRECTORY ${EXECUTABLE_OUTPUT_PATH}) set_tests_properties(PythonCapabilities PROPERTIES ENVIRONMENT "${PYTHON_TEST_ENVIRONMENT}") + + add_test(NAME PythonPyLammps + COMMAND ${PYTHON_TEST_RUNNER} ${CMAKE_CURRENT_SOURCE_DIR}/python-pylammps.py -v + WORKING_DIRECTORY ${EXECUTABLE_OUTPUT_PATH}) + set_tests_properties(PythonPyLammps PROPERTIES ENVIRONMENT "${PYTHON_TEST_ENVIRONMENT}") else() message(STATUS "Skipping Tests for the LAMMPS Python Module: no suitable Python interpreter") endif() diff --git a/unittest/python/python-capabilities.py b/unittest/python/python-capabilities.py index 7055557d76..27bdc9c561 100644 --- a/unittest/python/python-capabilities.py +++ b/unittest/python/python-capabilities.py @@ -28,6 +28,9 @@ class PythonCapabilities(unittest.TestCase): def tearDown(self): del self.lmp + def test_version(self): + self.assertGreaterEqual(self.lmp.version(), 20200824) + def test_has_gzip_support(self): self.assertEqual(self.lmp.has_gzip_support, self.cmake_cache['WITH_GZIP']) diff --git a/unittest/python/python-pylammps.py b/unittest/python/python-pylammps.py new file mode 100644 index 0000000000..7fb4165ced --- /dev/null +++ b/unittest/python/python-pylammps.py @@ -0,0 +1,49 @@ +import sys,os,unittest +from lammps import PyLammps + +class PythonPyLammps(unittest.TestCase): + def setUp(self): + machine = None + if 'LAMMPS_MACHINE_NAME' in os.environ: + machine=os.environ['LAMMPS_MACHINE_NAME'] + self.pylmp = PyLammps(name=machine, cmdargs=['-nocite', '-log','none', '-echo','screen']) + + if 'LAMMPS_CMAKE_CACHE' in os.environ: + self.cmake_cache = {} + + with open(os.environ['LAMMPS_CMAKE_CACHE'], 'r') as f: + for line in f: + line = line.strip() + if not line or line.startswith('#') or line.startswith('//'): continue + parts = line.split('=') + key, value_type = parts[0].split(':') + if len(parts) > 1: + value = parts[1] + if value_type == "BOOL": + value = (value.upper() == "ON") + else: + value = None + self.cmake_cache[key] = value + + def tearDown(self): + self.pylmp.close() + del self.pylmp + + def test_version(self): + self.assertGreaterEqual(self.pylmp.version(), 20200824) + + def test_create_box(self): + self.pylmp.region("box block", 0, 2, 0, 2, 0, 2) + self.pylmp.create_box(1, "box") + + x = [ + 1.0, 1.0, 1.0, + 1.0, 1.0, 1.5 + ] + + types = [1, 1] + + self.assertEqual(self.pylmp.lmp.create_atoms(2, id=None, type=types, x=x), 2) + +if __name__ == "__main__": + unittest.main()