Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test cleanup #519

Merged
merged 5 commits into from
Apr 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion include/realizations/catchment/AbstractCLibBmiAdapter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,12 @@ namespace models {
if (!utils::FileChecker::file_is_readable(bmi_lib_file)) {
//Try alternative extension...
size_t idx = bmi_lib_file.rfind(".");
std::string alt_bmi_lib_file;
std::string alt_bmi_lib_file;
if(bmi_lib_file.length() == 0){
this->init_exception_msg =
"Can't init " + this->model_name + "; library file path is empty";
throw std::runtime_error(this->init_exception_msg);
}
if(bmi_lib_file.substr(idx) == ".so"){
alt_bmi_lib_file = bmi_lib_file.substr(0,idx) + ".dylib";
} else if(bmi_lib_file.substr(idx) == ".dylib"){
Expand Down
4 changes: 4 additions & 0 deletions include/realizations/catchment/Bmi_Py_Adapter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,10 @@ namespace models {
if (init_exception_msg.empty()) {
init_exception_msg = "Unknown Python model initialization exception.";
}
//This message is lost and often contains valuable info. Either need to break up and catch
//other possible exceptions, wrap all these in a custom exception, or at the very least, print
//the original messge before it gets lost in this re-throw.
std::cerr<<init_exception_msg<<std::endl;
throw e;
}
}
Expand Down
1 change: 1 addition & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ if(NGEN_ACTIVATE_ROUTING)
test_routing_pybind
1
routing/Routing_Py_Bind_Test.cpp
NGen::core # for filechecker utility
NGen::routing
pybind11::embed
)
Expand Down
8 changes: 8 additions & 0 deletions test/core/nexus/NexusRemoteTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ void Nexus_Remote_Test::TearDown()
//to a downstream remote nexus.
TEST_F(Nexus_Remote_Test, TestInit0)
{
if ( mpi_num_procs < 2 ) {
GTEST_SKIP();
}

HY_PointHydroNexusRemote::catcment_location_map_t loc_map;

std::shared_ptr<HY_PointHydroNexusRemote> nexus;
Expand Down Expand Up @@ -409,6 +413,10 @@ TEST_F(Nexus_Remote_Test, Test4R2S2LS)

TEST_F(Nexus_Remote_Test, TestDeadlock1)
{
if ( mpi_num_procs < 2 ) {
GTEST_SKIP();
}

HY_PointHydroNexusRemote::catcment_location_map_t loc_map;

std::shared_ptr<HY_PointHydroNexusRemote> nexus1;
Expand Down
16 changes: 8 additions & 8 deletions test/data/routing/ngen_routing_config_unit_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ network_topology_parameters:
supernetwork_parameters:
#----------
geo_file_type: HYFeaturesNetwork
geo_file_path: ./test/data/routing/gauge_01073000.gpkg
geo_file_path: ../../test/data/routing/gauge_01073000.gpkg
mask_file_path: # domain/unit_test_noRS/coastal_subset.txt
synthetic_wb_segments:
#- 4800002
Expand All @@ -21,8 +21,8 @@ network_topology_parameters:
break_network_at_waterbodies: False
level_pool:
#----------
level_pool_waterbody_parameter_file_path: ./test/data/routing/gauge_01073000.gpkg
reservoir_parameter_file : ./test/data/routing/gauge_01073000.gpkg
level_pool_waterbody_parameter_file_path: ../../test/data/routing/gauge_01073000.gpkg
reservoir_parameter_file : ../../test/data/routing/gauge_01073000.gpkg
#rfc:
#----------
#reservoir_parameter_file : domain/reservoir_index_AnA.nc
Expand Down Expand Up @@ -58,11 +58,11 @@ compute_parameters:
#----------
qts_subdivisions : 12
dt : 300 # [sec]
qlat_input_folder : ./test/data/routing/
qlat_input_folder : ../../test/data/routing/
qlat_file_pattern_filter : "nex-*"
nexus_input_folder : ./test/data/routing/
nexus_input_folder : ../../test/data/routing/
nexus_file_pattern_filter : "nex-*" #OR "*NEXOUT.parquet" OR "nex-*"
binary_nexus_file_folder : ./test/data/routing/ # this is required if nexus_file_pattern_filter="nex-*"
binary_nexus_file_folder : ../../test/data/routing/ # this is required if nexus_file_pattern_filter="nex-*"
#coastal_boundary_input_file : channel_forcing/schout_1.nc
nts : 8640 #288 for 1day
max_loop_size : 720 # [hr]
Expand Down Expand Up @@ -98,6 +98,6 @@ output_parameters:
#wrf_hydro_channel_output_source_folder: ./
chanobs_output:
#----------
chanobs_output_directory: ./test/data/routing/
chanobs_output_directory: ../../test/data/routing/
chanobs_filepath : Chanobs.nc
lakeout_output: ./test/data/routing/
lakeout_output: ../../test/data/routing/
20 changes: 16 additions & 4 deletions test/realizations/Formulation_Manager_Test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,12 @@ class Formulation_Manager_Test : public ::testing::Test {

std::vector<std::string> path_options = {
"",
"../",
"../../",
"./test/",
"../test/",
"../../test/",
"../",
"../../"
"../../test/"

};

std::string fix_paths(std::string json)
Expand All @@ -84,6 +85,17 @@ class Formulation_Manager_Test : public ::testing::Test {
"./data/forcing/cat-27_2015-12-01 00_00_00_2015-12-30 23_00_00.csv",
"./data/forcing/cat-27115-nwm-aorc-variant-derived-format.csv"
};
std::vector<std::string> v = {};
for(unsigned int i = 0; i < path_options.size(); i++){
v.push_back( path_options[i] + "data/forcing" );
}
std::string dir = utils::FileChecker::find_first_readable(v);
if(dir != ""){
std::string remove = "\"./data/forcing/\"";
std::string replace = "\""+dir+"\"";
//std::cerr<<"TRYING TO REPLACE DIRECTORY... "<<remove<<" -> "<<replace<<std::endl;
boost::replace_all(json, remove , replace);
}
for (unsigned int i = 0; i < forcing_paths.size(); i++) {
if(json.find(forcing_paths[i]) == std::string::npos){
continue;
Expand All @@ -95,7 +107,7 @@ class Formulation_Manager_Test : public ::testing::Test {
std::string right_path = utils::FileChecker::find_first_readable(v);
if(right_path != forcing_paths[i]){
std::cerr<<"Replacing "<<forcing_paths[i]<<" with "<<right_path<<std::endl;
json = json.replace(json.find(forcing_paths[i]), forcing_paths[i].length(), right_path);
boost::replace_all(json, forcing_paths[i] , right_path);
}
}
return json;
Expand Down
9 changes: 7 additions & 2 deletions test/routing/Routing_Py_Bind_Test.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifdef ROUTING_PYBIND_TESTS_ACTIVE
#include "gtest/gtest.h"
#include "Routing_Py_Adapter.hpp"
#include "FileChecker.h"
#include <string>
#include <pybind11/embed.h>
#include <pybind11/stl.h>
Expand Down Expand Up @@ -33,8 +34,12 @@ TEST_F(RoutingPyBindTest, TestRoutingPyBind)
//std::vector<double> nexus_values_vec{1.1, 2.2, 3.3, 4.4, 5.5};

//SET THESE AS INPUTS
std::string t_route_config_file_with_path = "./test/data/routing/ngen_routing_config_unit_test.yaml";

std::vector<std::string> paths = {
"./test/data/routing/ngen_routing_config_unit_test.yaml",
"../test/data/routing/ngen_routing_config_unit_test.yaml",
"../../test/data/routing/ngen_routing_config_unit_test.yaml"
};
std::string t_route_config_file_with_path = utils::FileChecker::find_first_readable(paths);
//Note: Currently, delta_time is set in the t-route yaml configuration file, and the
//number_of_timesteps is determined from the total number of nexus outputs in t-rout
//It is recommended to still pass these values to the routing_py_adapter object in
Expand Down