From 854414bec467ee14f2a8347f94e0dec62625d034 Mon Sep 17 00:00:00 2001 From: Trevor James Smith <10819524+Zeitsperre@users.noreply.github.com> Date: Fri, 12 Jan 2024 13:12:11 -0500 Subject: [PATCH] fix some test data loading --- tests/test_cli.py | 105 ++++++++++++++++++++++++++++++++++++---------- tox.ini | 1 + 2 files changed, 84 insertions(+), 22 deletions(-) diff --git a/tests/test_cli.py b/tests/test_cli.py index 99ddf4b8..dd39a2f5 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -1,4 +1,5 @@ import re +from shutil import copyfile import netCDF4 as nc4 from click.testing import CliRunner @@ -13,6 +14,16 @@ def test_generate_grid_weights_with_nc_input_and_2d_coords( ): runner = CliRunner() output_path = tmp_path / "bla.rvt" + + copyfile( + get_local_testdata("raven-routing-sample/VIC_streaminputs.nc"), + tmp_path / "VIC_streaminputs.nc", + ) + copyfile( + get_local_testdata("raven-routing-sample/finalcat_hru_info.zip"), + tmp_path / "finalcat_hru_info.zip", + ) + params = [ "-c", "HRU_ID", @@ -21,8 +32,8 @@ def test_generate_grid_weights_with_nc_input_and_2d_coords( "lat", "-o", output_path, - get_local_testdata("raven-routing-sample/VIC_streaminputs.nc"), - get_local_testdata("raven-routing-sample/finalcat_hru_info.zip"), + tmp_path / "VIC_streaminputs.nc", + tmp_path / "finalcat_hru_info.zip", ] params = list(map(str, params)) @@ -48,13 +59,19 @@ def test_generate_grid_weights_with_multiple_subids( # needs a "routing-file-path" with multiple gauges runner = CliRunner() output_path = tmp_path / "bla.rvt" + + copyfile( + get_local_testdata("raven-routing-sample/VIC_streaminputs.nc"), + tmp_path / "VIC_streaminputs.nc", + ) + copyfile( + get_local_testdata("raven-routing-sample/finalcat_hru_info.zip"), + tmp_path / "finalcat_hru_info.zip", + ) + params = [ - get_local_testdata( - "raven-routing-sample/VIC_streaminputs.nc", - ), - get_local_testdata( - "raven-routing-sample/finalcat_hru_info.zip", - ), + tmp_path / "VIC_streaminputs.nc", + tmp_path / "finalcat_hru_info.zip", "-c", "HRU_ID", "-v", @@ -89,13 +106,19 @@ def test_generate_grid_weights_with_nc_input_and_1d_coords( ): runner = CliRunner() output_path = tmp_path / "bla.rvt" + + copyfile( + get_local_testdata("raven-routing-sample/era5-test-dataset-crop.nc"), + tmp_path / "era5-test-dataset-crop.nc", + ) + copyfile( + get_local_testdata("raven-routing-sample/finalcat_hru_info.zip"), + tmp_path / "finalcat_hru_info.zip", + ) + params = [ - get_local_testdata( - "raven-routing-sample/era5-test-dataset-crop.nc", - ), - get_local_testdata( - "raven-routing-sample/finalcat_hru_info.zip", - ), + tmp_path / "era5-test-dataset-crop.nc", + tmp_path / "finalcat_hru_info.zip", "--var-names", "longitude", "latitude", @@ -124,13 +147,23 @@ def test_generate_grid_weights_with_nc_input_and_1d_coords( def test_generate_grid_weights_with_shp_input(self, tmp_path, get_local_testdata): runner = CliRunner() output_path = tmp_path / "bla.rvt" + + copyfile( + get_local_testdata("raven-routing-sample/OTT_sub.zip"), + tmp_path / "OTT_sub.zip", + ) + copyfile( + get_local_testdata("raven-routing-sample/finalcat_hru_info.zip"), + tmp_path / "finalcat_hru_info.zip", + ) + params = [ "-c", "HRU_ID", "-o", output_path, - get_local_testdata("raven-routing-sample/OTT_sub.zip"), - get_local_testdata("raven-routing-sample/finalcat_hru_info.zip"), + tmp_path / "OTT_sub.zip", + tmp_path / "finalcat_hru_info.zip", ] params = map(str, params) @@ -154,6 +187,16 @@ def test_generate_grid_weights_with_weight_rescaling( ): runner = CliRunner() output_path = tmp_path / "bla.rvt" + + copyfile( + get_local_testdata("raven-routing-sample/OTT_sub.zip"), + tmp_path / "OTT_sub.zip", + ) + copyfile( + get_local_testdata("raven-routing-sample/finalcat_hru_info.zip"), + tmp_path / "finalcat_hru_info.zip", + ) + params = [ "--area-error-threshold", "0.42", @@ -161,10 +204,8 @@ def test_generate_grid_weights_with_weight_rescaling( "HRU_ID", "-o", output_path, - get_local_testdata("raven-routing-sample/OTT_sub.zip"), - get_local_testdata( - "raven-routing-sample/finalcat_hru_info.zip", - ), + tmp_path / "OTT_sub.zip", + tmp_path / "finalcat_hru_info.zip", ] params = map(str, params) @@ -189,13 +230,23 @@ def test_aggregate_forcings_to_hrus(self, tmp_path, get_local_testdata): runner = CliRunner() output_nc_file_path = tmp_path / "aggreg.nc" output_weight_file_path = tmp_path / "weight_aggreg.rvt" - params = [ + + copyfile( get_local_testdata( "raven-routing-sample/VIC_streaminputs.nc", ), + tmp_path / "VIC_streaminputs.nc", + ) + copyfile( get_local_testdata( "raven-routing-sample/VIC_streaminputs_weights.rvt", ), + tmp_path / "VIC_streaminputs_weights.rvt", + ) + + params = [ + tmp_path / "VIC_streaminputs.nc", + tmp_path / "VIC_streaminputs_weights.rvt", "-v", "Streaminputs", "--output-nc-file", @@ -243,9 +294,19 @@ def test_aggregate_forcings_to_hrus_with_nodata(self, tmp_path, get_local_testda runner = CliRunner() output_nc_file_path = tmp_path / "aggreg.nc" output_weight_file_path = tmp_path / "weight_aggreg.rvt" - params = [ + + copyfile( get_local_testdata("raven-routing-sample/VIC_test_nodata.nc"), + tmp_path / "VIC_test_nodata.nc", + ) + copyfile( get_local_testdata("raven-routing-sample/VIC_test_nodata_weights.rvt"), + tmp_path / "VIC_test_nodata_weights.rvt", + ) + + params = [ + tmp_path / "VIC_test_nodata.nc", + tmp_path / "VIC_test_nodata_weights.rvt", "-v", "et", "--dim-names", diff --git a/tox.ini b/tox.ini index b2c6a2aa..0164f7a1 100644 --- a/tox.ini +++ b/tox.ini @@ -39,6 +39,7 @@ passenv = COVERALLS_* GDAL_VERSION GITHUB_* + LD_LIBRARY_PATH LD_PRELOAD RAVENPY_* extras =