From 89b6d3fffbd49d9f51c459a591cbb38a2c7384f5 Mon Sep 17 00:00:00 2001 From: Andrea Brambilla Date: Mon, 19 Feb 2018 13:57:36 +0100 Subject: [PATCH] Python tests - source folder set by CMake --- python/tests/CMakeLists.txt | 10 +++++----- python/tests/__init__.py | 9 ++++++++- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/python/tests/CMakeLists.txt b/python/tests/CMakeLists.txt index 5d82c798c6b..ac78fe380fd 100644 --- a/python/tests/CMakeLists.txt +++ b/python/tests/CMakeLists.txt @@ -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) diff --git a/python/tests/__init__.py b/python/tests/__init__.py index c409ec5a3cd..d16930efe64 100644 --- a/python/tests/__init__.py +++ b/python/tests/__init__.py @@ -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):