fixes #BITBUCKET-3673 I'm not sure what the old validataion did, but the error it was checking was if a crop name was valid. we can't really know until we know we have a valid model path, so I don't know if that's a good UI validator or not. something to consider later. but for now it's reasonable to have that functionality in the execute function so I did that. for some reason there was an extraneous loop at the entry point of execute that looked like it used to do this functionality but currently did nothing but uselessly loop. i patched and hijacked for this purpose.

This commit is contained in:
Rich Sharp 2017-11-01 10:31:13 -07:00
parent 3da729d126
commit bdefe52dfa
2 changed files with 10 additions and 4 deletions

View File

@ -120,12 +120,18 @@ def execute(args):
crop_to_landcover_table = utils.build_lookup_from_csv(
args['landcover_to_crop_table_path'], 'crop_name', to_lower=True,
numerical_cast=True)
bad_crop_name_list = []
for crop_name in crop_to_landcover_table:
crop_lucode = crop_to_landcover_table[crop_name][
_EXPECTED_LUCODE_TABLE_HEADER]
crop_climate_bin_raster_path = os.path.join(
args['model_data_path'],
_EXTENDED_CLIMATE_BIN_FILE_PATTERN % crop_name)
if not os.path.exists(crop_climate_bin_raster_path):
bad_crop_name_list.append(crop_name)
if len(bad_crop_name_list) > 0:
raise ValueError(
"The following crop names were provided in %s but no such crops "
"exist for this model: %s" % (
args['landcover_to_crop_table_path'], bad_crop_name_list))
file_suffix = utils.make_suffix_string(args, 'results_suffix')
output_dir = os.path.join(args['workspace_dir'])

View File

@ -83,8 +83,8 @@ class CropProductionTests(unittest.TestCase):
landcover_crop_table.write(
'crop_name,lucode\nfakecrop,20\n')
errors = crop_production_percentile.validate(args)
self.assertEqual(len(errors), 1)
with self.assertRaises(ValueError):
crop_production_percentile.execute(args)
@scm.skip_if_data_missing(SAMPLE_DATA_PATH)
@scm.skip_if_data_missing(MODEL_DATA_PATH)