Skip to content

Commit

Permalink
Python Unittests: Add to ctest
Browse files Browse the repository at this point in the history
  • Loading branch information
ax3l committed Jun 20, 2018
1 parent ca9c222 commit 6e79798
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 17 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@
*.out
*.app

##########
# Python #
##########
*.pyc
__pycache__

#######
# IDE #
#######
Expand Down
36 changes: 31 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -561,11 +561,37 @@ if(BUILD_TESTING)
endif()

# TODO: Python Unit tests
#if(BUILD_TESTING)
# if(openPMD_HAVE_PYTHON)
# ...
# endif()
#endif()
if(BUILD_TESTING)
if(openPMD_HAVE_PYTHON)
if(openPMD_HAVE_HDF5)
if(EXISTS "${openPMD_BINARY_DIR}/samples/git-sample/")

add_test(NAME Unittest.py
COMMAND ${PYTHON_EXECUTABLE}
${openPMD_SOURCE_DIR}/test/python/unittest/Test.py -v
WORKING_DIRECTORY
${CMAKE_RUNTIME_OUTPUT_DIRECTORY}
)
if(WIN32)
string(REGEX REPLACE "/" "\\\\" WIN_BUILD_BASEDIR ${openPMD_BINARY_DIR})
string(REGEX REPLACE "/" "\\\\" WIN_BUILD_BINDIR ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
string(REPLACE ";" "\\;" WIN_PATH "$ENV{PATH}")
string(REPLACE ";" "\\;" WIN_PYTHONPATH "$ENV{PYTHONPATH}")
set_property(TEST Unittest.py
PROPERTY ENVIRONMENT
"PATH=${WIN_BUILD_BINDIR}\\${CMAKE_BUILD_TYPE}\;${WIN_PATH}\n"
"PYTHONPATH=${WIN_BUILD_BASEDIR}\\${CMAKE_INSTALL_PYTHONDIR}\\${CMAKE_BUILD_TYPE}\;${WIN_PYTHONPATH}"
)
else()
set_tests_properties(Unittest.py
PROPERTIES ENVIRONMENT
"PYTHONPATH=${openPMD_BINARY_DIR}/${CMAKE_INSTALL_PYTHONDIR}:$ENV{PYTHONPATH}"
)
endif()
endif()
endif()
endif()
endif()


# Examples ####################################################################
Expand Down
1 change: 0 additions & 1 deletion test/python/unittest/TestFiles

This file was deleted.

23 changes: 12 additions & 11 deletions test/python/unittest/TestUtilities/TestUtilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
License: LGPLv3+
"""

import os
import os.path
from os import path


def generateTestFilePath(file_name):
Expand All @@ -18,13 +17,15 @@ def generateTestFilePath(file_name):
@return : The absolute path to ../TestFiles/<file_name> .
"""

test_files_dir = 'TestFiles'
this_path = os.path.abspath(os.path.dirname(__file__))
parent_dir = os.path.pardir
test_files_path = os.path.abspath(
os.path.join(
this_path, parent_dir, test_files_dir
)
)
test_files_dir = path.join('../samples/', file_name)
return test_files_dir

return os.path.join(test_files_path, file_name)
# this_path = path.abspath(path.dirname(__file__))
# parent_dir = path.pardir
# test_files_path = path.abspath(
# path.join(
# this_path, parent_dir, test_files_dir
# )
# )

# return path.join(test_files_path, file_name)

0 comments on commit 6e79798

Please sign in to comment.