Skip to content

Commit

Permalink
Python tests - source folder set by CMake
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrea Brambilla authored and Andrea Brambilla committed Feb 22, 2018
1 parent bc0c9ee commit 89b6d3f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
10 changes: 5 additions & 5 deletions python/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
set(TEST_SOURCES
__init__.py
)

set(TEST_ROOT ${CMAKE_CURRENT_SOURCE_DIR})
set(INSTALL_DIRECTORY ${PROJECT_BINARY_DIR}/${PYTHON_INSTALL_PREFIX})

add_python_package("python.tests" "${PYTHON_INSTALL_PREFIX}/tests" "${TEST_SOURCES}" False)
configure_file(
__init__.py
"${PROJECT_BINARY_DIR}/${PYTHON_INSTALL_PREFIX}/tests/__init__.py"
@ONLY
)

add_subdirectory(global)

Expand Down
9 changes: 8 additions & 1 deletion python/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,19 @@


def source_root():
src = '@CMAKE_CURRENT_SOURCE_DIR@/../..'
if os.path.isdir(src):
return os.path.realpath(src)

# If the file was not correctly configured by cmake, look for the source
# folder, assuming the build folder is inside the source folder.
path_list = os.path.dirname(os.path.abspath(__file__)).split("/")
while True:
while len(path_list) > 0:
git_path = os.path.join(os.sep, "/".join(path_list), ".git")
if os.path.isdir(git_path):
return os.path.join(os.sep, *path_list)
path_list.pop()
raise RuntimeError('Cannot find the source folder')


class ErtTest(ExtendedTestCase):
Expand Down

0 comments on commit 89b6d3f

Please sign in to comment.