From 1171aa384047bf7bd1401c842fa1532172a891d8 Mon Sep 17 00:00:00 2001 From: Phil Miller Date: Tue, 26 Dec 2023 17:16:25 -0800 Subject: [PATCH] WIP: Modify tests to reflect that external file dependencies are linked in the build tree, and don't need to be located relative to the source path --- test/bmi/Bmi_Py_Adapter_Test.cpp | 14 ++++++++------ .../catchments/Bmi_Multi_Formulation_Test.cpp | 4 ++-- .../catchments/Bmi_Py_Formulation_Test.cpp | 14 ++++++++------ 3 files changed, 18 insertions(+), 14 deletions(-) diff --git a/test/bmi/Bmi_Py_Adapter_Test.cpp b/test/bmi/Bmi_Py_Adapter_Test.cpp index 9ce706f710..64af3e0621 100644 --- a/test/bmi/Bmi_Py_Adapter_Test.cpp +++ b/test/bmi/Bmi_Py_Adapter_Test.cpp @@ -129,12 +129,12 @@ py::object Bmi_Py_Adapter_Test::Path = InterpreterUtil::getPyModule(std::vector< void Bmi_Py_Adapter_Test::SetUp() { - std::string repo_root = py_find_repo_root(); + //std::string repo_root = py_find_repo_root(); example_scenario template_ex_struct; // These should be safe for all examples template_ex_struct.module_name = "test_bmi_py.bmi_model"; - template_ex_struct.module_directory = repo_root + "/extern/"; + template_ex_struct.module_directory = "./extern/"; // Now generate the examples vector based on the above template example size_t num_example_scenarios = 1; @@ -143,11 +143,11 @@ void Bmi_Py_Adapter_Test::SetUp() { examples[i] = template_ex_struct; } - examples[0].forcing_file = repo_root + "/data/forcing/cat-27_2015-12-01 00_00_00_2015-12-30 23_00_00.csv"; + examples[0].forcing_file = "./data/forcing/cat-27_2015-12-01 00_00_00_2015-12-30 23_00_00.csv"; // We can handle setting the right init config and initializing the adapter in a loop for (int i = 0; i < examples.size(); ++i) { - examples[i].bmi_init_config = repo_root + "/test/data/bmi/test_bmi_python/test_bmi_python_config_" + examples[i].bmi_init_config = "./test/data/bmi/test_bmi_python/test_bmi_python_config_" + std::to_string(i) + ".yml"; examples[i].adapter = std::make_shared(examples[i].module_name, examples[i].bmi_init_config, @@ -160,14 +160,16 @@ void Bmi_Py_Adapter_Test::TearDown() { } void Bmi_Py_Adapter_Test::SetUpTestSuite() { - std::string repo_root = py_find_repo_root(); - std::string module_directory = repo_root + "/extern/"; + //std::string repo_root = py_find_repo_root(); + std::string module_directory = "./extern/"; + #if 0 // Add the package dir from a local virtual environment directory also, if there is one std::string venv_dir = py_dir_search({repo_root + "/.venv", repo_root + "/venv"}); if (!venv_dir.empty()) { InterpreterUtil::addToPyPath(py_find_venv_site_packages_dir(venv_dir)); } + #endif // Also add the extern dir with our test lib to Python system path InterpreterUtil::addToPyPath(module_directory); } diff --git a/test/realizations/catchments/Bmi_Multi_Formulation_Test.cpp b/test/realizations/catchments/Bmi_Multi_Formulation_Test.cpp index c986cef2f4..1f741f25f9 100644 --- a/test/realizations/catchments/Bmi_Multi_Formulation_Test.cpp +++ b/test/realizations/catchments/Bmi_Multi_Formulation_Test.cpp @@ -467,8 +467,8 @@ std::shared_ptr Bmi_Multi_Formulation_Test::interperter = Inter void Bmi_Multi_Formulation_Test::SetUpTestSuite() { #ifdef ACTIVATE_PYTHON - std::string repo_root = py_find_repo_root(); - std::string module_directory = repo_root + "/extern/"; + // std::string repo_root = py_find_repo_root(); + std::string module_directory = "./extern/"; // Add the extern dir with our test lib to Python system path InterpreterUtil::addToPyPath(module_directory); diff --git a/test/realizations/catchments/Bmi_Py_Formulation_Test.cpp b/test/realizations/catchments/Bmi_Py_Formulation_Test.cpp index 9def1547b1..bd84e3af03 100644 --- a/test/realizations/catchments/Bmi_Py_Formulation_Test.cpp +++ b/test/realizations/catchments/Bmi_Py_Formulation_Test.cpp @@ -182,13 +182,13 @@ std::shared_ptr Bmi_Py_Formulation_Test::interperter = Interpre void Bmi_Py_Formulation_Test::SetUp() { Path = InterpreterUtil::getPyModule(std::vector {"pathlib", "Path"}); - std::string repo_root = py_find_repo_root(); - std::string forcing_data_dir = repo_root + "/data/forcing/"; + //std::string repo_root = py_find_repo_root(); + std::string forcing_data_dir = "./data/forcing/"; py_formulation_example_scenario template_ex_struct; // These should be safe for all examples template_ex_struct.module_name = "test_bmi_py.bmi_model"; - template_ex_struct.module_directory = repo_root + "/extern/"; + template_ex_struct.module_directory = "./extern/"; template_ex_struct.main_output_variable = "OUTPUT_VAR_1"; template_ex_struct.uses_forcing_file = false; @@ -205,7 +205,7 @@ void Bmi_Py_Formulation_Test::SetUp() { // We can handle setting the rest up in a loop std::string forcing_file; for (size_t i = 0; i < examples.size(); ++i) { - examples[i].bmi_init_config = repo_root + "/test/data/bmi/test_bmi_python/test_bmi_python_config_" + examples[i].bmi_init_config = "./test/data/bmi/test_bmi_python/test_bmi_python_config_" + std::to_string(i) + ".yml"; forcing_file = forcing_data_dir + examples[i].catchment_id + "_2015-12-01 00_00_00_2015-12-30 23_00_00.csv"; examples[i].forcing_params = std::make_shared(forcing_file, "legacy", "2015-12-01 00:00:00", @@ -226,14 +226,16 @@ void Bmi_Py_Formulation_Test::SetUp() { } void Bmi_Py_Formulation_Test::SetUpTestSuite() { - std::string repo_root = py_find_repo_root(); - std::string module_directory = repo_root + "/extern/"; + // std::string repo_root = py_find_repo_root(); + std::string module_directory = "./extern/"; + #if 0 // Add the package dir from a local virtual environment directory also, if there is one std::string venv_dir = py_dir_search({repo_root + "/.venv", repo_root + "/venv"}); if (!venv_dir.empty()) { InterpreterUtil::addToPyPath(py_find_venv_site_packages_dir(venv_dir)); } + #endif // Also add the extern dir with our test lib to Python system path InterpreterUtil::addToPyPath(module_directory);