implement a test prototype for the LAMMPS shell
This commit is contained in:
@ -7,6 +7,7 @@ add_subdirectory(c-library)
|
|||||||
add_subdirectory(cplusplus)
|
add_subdirectory(cplusplus)
|
||||||
add_subdirectory(fortran)
|
add_subdirectory(fortran)
|
||||||
add_subdirectory(python)
|
add_subdirectory(python)
|
||||||
|
add_subdirectory(tools)
|
||||||
add_subdirectory(force-styles)
|
add_subdirectory(force-styles)
|
||||||
|
|
||||||
find_package(ClangFormat 8.0)
|
find_package(ClangFormat 8.0)
|
||||||
|
|||||||
20
unittest/tools/CMakeLists.txt
Normal file
20
unittest/tools/CMakeLists.txt
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
|
||||||
|
# we use python 3's subprocess module to run the tools and check the output
|
||||||
|
if(CMAKE_VERSION VERSION_LESS 3.12)
|
||||||
|
find_package(PythonInterp 3.5) # Deprecated since version 3.12
|
||||||
|
if(PYTHONINTERP_FOUND)
|
||||||
|
set(Python_EXECUTABLE ${PYTHON_EXECUTABLE})
|
||||||
|
endif()
|
||||||
|
else()
|
||||||
|
find_package(Python3 COMPONENTS Interpreter)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(Python_EXECUTABLE)
|
||||||
|
if(BUILD_LAMMPS_SHELL)
|
||||||
|
add_test(NAME LammpsShell
|
||||||
|
COMMAND ${Python_EXECUTABLE} -u ${CMAKE_CURRENT_SOURCE_DIR}/test_lammps_shell.py -v
|
||||||
|
WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
|
||||||
|
endif()
|
||||||
|
else()
|
||||||
|
message(STATUS "Skipping Tests for LAMMPS tools: no suitable Python interpreter")
|
||||||
|
endif()
|
||||||
49
unittest/tools/test_lammps_shell.py
Normal file
49
unittest/tools/test_lammps_shell.py
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
|
||||||
|
import os, re, subprocess, unittest
|
||||||
|
|
||||||
|
# enable test mode
|
||||||
|
os.putenv('LAMMPS_SHELL_TESTING','1')
|
||||||
|
|
||||||
|
shell_prompt_re = r"(.*LAMMPS Shell> ([a-z0-9_]+) *([a-z0-9_\.]+)?.*)+"
|
||||||
|
|
||||||
|
#
|
||||||
|
class LammpsShell(unittest.TestCase):
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
self.proc = subprocess.Popen('./lammps-shell',
|
||||||
|
stdin=subprocess.PIPE, stdout=subprocess.PIPE)
|
||||||
|
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
self.proc.kill()
|
||||||
|
|
||||||
|
|
||||||
|
def InputRunner(self,text):
|
||||||
|
"""Test tab expansions"""
|
||||||
|
try:
|
||||||
|
[outs,errs] = self.proc.communicate(input=text, timeout=1)
|
||||||
|
except TimeoutExpired:
|
||||||
|
proc.kill()
|
||||||
|
[outs,errs] = proc.communicate()
|
||||||
|
|
||||||
|
#print(outs.decode())
|
||||||
|
return re.findall(shell_prompt_re, outs.decode('UTF-8'), re.MULTILINE)[0]
|
||||||
|
|
||||||
|
def testExpandClear(self):
|
||||||
|
"""Test expansion of a shell specific command"""
|
||||||
|
self.assertEqual(self.InputRunner(b'cle\t\n')[1],"clear")
|
||||||
|
|
||||||
|
def testExpandSource(self):
|
||||||
|
"""Test expansion of a shell command and a file name"""
|
||||||
|
with open('.tmp.in.source', 'w') as out:
|
||||||
|
print('units real', file=out)
|
||||||
|
out.close()
|
||||||
|
matches=self.InputRunner(b'sour\t.tmp.in.sou\t\n')
|
||||||
|
os.remove('.tmp.in.source')
|
||||||
|
self.assertEqual(matches[1],"source")
|
||||||
|
self.assertEqual(matches[2],".tmp.in.source")
|
||||||
|
|
||||||
|
|
||||||
|
###########################
|
||||||
|
if __name__ == "__main__":
|
||||||
|
unittest.main()
|
||||||
Reference in New Issue
Block a user