Skip to content

Commit

Permalink
WIP: Modify tests to reflect that external file dependencies are link…
Browse files Browse the repository at this point in the history
…ed in the build tree, and don't need to be located relative to the source path
  • Loading branch information
PhilMiller committed Dec 27, 2023
1 parent 135f006 commit 1171aa3
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 14 deletions.
14 changes: 8 additions & 6 deletions test/bmi/Bmi_Py_Adapter_Test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<Bmi_Py_Adapter>(examples[i].module_name, examples[i].bmi_init_config,
Expand All @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions test/realizations/catchments/Bmi_Multi_Formulation_Test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -467,8 +467,8 @@ std::shared_ptr<InterpreterUtil> 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);
Expand Down
14 changes: 8 additions & 6 deletions test/realizations/catchments/Bmi_Py_Formulation_Test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,13 +182,13 @@ std::shared_ptr<InterpreterUtil> Bmi_Py_Formulation_Test::interperter = Interpre
void Bmi_Py_Formulation_Test::SetUp() {
Path = InterpreterUtil::getPyModule(std::vector<std::string> {"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;

Expand All @@ -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_params>(forcing_file, "legacy", "2015-12-01 00:00:00",
Expand All @@ -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);

Expand Down

0 comments on commit 1171aa3

Please sign in to comment.