Skip to content

Commit

Permalink
separate regression test for natcap#1005
Browse files Browse the repository at this point in the history
  • Loading branch information
emlys committed Aug 18, 2023
1 parent 36345dd commit f4343e6
Showing 1 changed file with 31 additions and 16 deletions.
47 changes: 31 additions & 16 deletions tests/test_ndr.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,25 +194,18 @@ def test_no_nutrient_selected(self):
with self.assertRaises(ValueError):
ndr.execute(args)

def test_base_regression(self):
"""NDR base regression test on sample data.

Execute NDR with sample data and checks that the output files are
generated and that the aggregate shapefile fields are the same as the
regression case.
"""
def test_runoff_proxy_undefined_nodata(self):
"""NDR: values should be correct with undefined runoff proxy nodata."""
from natcap.invest.ndr import ndr

# use predefined directory so test can clean up files during teardown
args = NDRTests.generate_base_args(self.workspace_dir)
# make an empty output shapefile on top of where the new output
# shapefile should reside to ensure the model overwrites it
with open(
os.path.join(self.workspace_dir, 'watershed_results_ndr.gpkg'),
'wb') as f:
f.write(b'')

# make args explicit that this is a base run of SWY
target_path = os.path.join(self.workspace_dir, 'runoff_proxy_input.tif')
source = gdal.OpenEx(args['runoff_proxy_path'], gdal.OF_RASTER)
driver = gdal.GetDriverByName('GTIFF')
target = driver.CreateCopy(target_path, source)
target.GetRasterBand(1).DeleteNoDataValue()
source, target = None, None
args['runoff_proxy_path'] = target_path
ndr.execute(args)

# regression test for https://github.com/natcap/invest/issues/1005
Expand All @@ -237,6 +230,28 @@ def test_base_regression(self):
runoff_proxy_index_array[mask],
masked_runoff_proxy_array[mask] / expected_mean)

def test_base_regression(self):
"""NDR base regression test on sample data.
Execute NDR with sample data and checks that the output files are
generated and that the aggregate shapefile fields are the same as the
regression case.
"""
from natcap.invest.ndr import ndr

# use predefined directory so test can clean up files during teardown
args = NDRTests.generate_base_args(self.workspace_dir)

# make an empty output shapefile on top of where the new output
# shapefile should reside to ensure the model overwrites it
with open(
os.path.join(self.workspace_dir, 'watershed_results_ndr.gpkg'),
'wb') as f:
f.write(b'')

# make args explicit that this is a base run of SWY
ndr.execute(args)

result_vector = ogr.Open(os.path.join(
args['workspace_dir'], 'watershed_results_ndr.gpkg'))
result_layer = result_vector.GetLayer()
Expand Down

0 comments on commit f4343e6

Please sign in to comment.