def test_missing_required_keys(self): """WaveEnergy: testing missing required keys from args.""" from natcap.invest import wave_energy from natcap.invest import validation args = {} validation_error_list = wave_energy.validate(args) invalid_keys = validation.get_invalid_keys(validation_error_list) expected_missing_keys = set(self.base_required_keys) self.assertEqual(invalid_keys, expected_missing_keys)
def test_incorrect_analysis_area_path_value(self): """WaveEnergy: testing incorrect analysis_area_path value.""" from natcap.invest import wave_energy args = {} args['analysis_area_path'] = 'Incorrect Analysis Area' validation_error_list = wave_energy.validate(args) expected_message = 'Value must be one of' # Start of option error msg actual_messages = '' for keys, error_strings in validation_error_list: actual_messages += error_strings self.assertTrue(expected_message in actual_messages)
def test_missing_required_keys_if_valuation(self): """WaveEnergy: testing missing required keys given valuation.""" from natcap.invest import wave_energy from natcap.invest import validation args = {'valuation_container': True} validation_error_list = wave_energy.validate(args) invalid_keys = validation.get_invalid_keys(validation_error_list) expected_missing_keys = set( self.base_required_keys + ['number_of_machines', 'machine_econ_path', 'land_gridPts_path']) self.assertEqual(invalid_keys, expected_missing_keys)
def test_validate_keys_missing_values(self): """WaveEnergy: testing validate when keys are missing values.""" from natcap.invest import wave_energy, validation args = {} args['wave_base_data_path'] = None args['dem_path'] = None validation_error_list = wave_energy.validate(args) expected_error = (['dem_path', 'wave_base_data_path'], validation.MESSAGES['MISSING_VALUE']) self.assertTrue(expected_error in validation_error_list)
def test_validate_bad_aoi_format(self): """WaveEnergy: testing bad AOI vector format with validate.""" from natcap.invest import wave_energy args = {} args['aoi_path'] = os.path.join(SAMPLE_DATA, 'bad_AOI_WCVI.shp') validation_error_list = wave_energy.validate(args) expected_errors = [ (['aoi_path'], 'Layer must be projected in meters'), ] for expected_error in expected_errors: self.assertTrue(expected_error in validation_error_list)
def test_validate_bad_aoi_unrecognized_proj_units(self): """WaveEnergy: test validating AOI vector with unrecognized units""" from natcap.invest import wave_energy, validation args = {} # The unit "not_a_unit" is not recognized by pint args['aoi_path'] = os.path.join(SAMPLE_DATA, 'bad_AOI_fake_unit.shp') validation_error_list = wave_energy.validate(args) expected_error = (['aoi_path'], validation.MESSAGES['WRONG_PROJECTION_UNIT'].format( unit_a='meter', unit_b='not_a_unit')) self.assertTrue(expected_error in validation_error_list)
def test_validate_bad_aoi_incorrect_proj_units(self): """WaveEnergy: test validating AOI vector with incorrect units.""" from natcap.invest import wave_energy, validation args = {} # Validation will recognize the units "foot" and say it's incorrect args['aoi_path'] = os.path.join(SAMPLE_DATA, 'bad_AOI_us_survey_foot.shp') validation_error_list = wave_energy.validate(args) expected_error = (['aoi_path'], validation.MESSAGES['WRONG_PROJECTION_UNIT'].format( unit_a='meter', unit_b='us_survey_foot')) self.assertTrue(expected_error in validation_error_list)
def test_validate_bad_aoi_format(self): """WaveEnergy: testing bad AOI vector format with validate.""" from natcap.invest import wave_energy args = WaveEnergyRegressionTests.generate_base_args(self.workspace_dir) args['aoi_path'] = os.path.join(SAMPLE_DATA, 'bad_AOI_WCVI.shp') validation_error_list = wave_energy.validate(args) expected_errors = [ (['aoi_path'], 'Vector must contain only polygons.'), (['aoi_path'], 'Vector must be projected in meters.'), (['aoi_path'], 'Vector must use the WGS_1984 datum.'), ] for expected_error in expected_errors: self.assertTrue(expected_error in validation_error_list)
def test_validate_keys_missing_values(self): """WaveEnergy: testing validate when keys are missing values.""" from natcap.invest import wave_energy args = {} args['wave_base_data_path'] = None args['dem_path'] = None validation_error_list = wave_energy.validate(args) expected_errors = [ (['dem_path', 'wave_base_data_path'], 'Input is required but has no value'), ] for expected_error in expected_errors: self.assertTrue(expected_error in validation_error_list)
def test_incorrect_analysis_area_value(self): """WaveEnergy: testing incorrect analysis_area value.""" from natcap.invest import wave_energy, validation args = {} args['analysis_area'] = 'Incorrect Analysis Area' validation_error_list = wave_energy.validate(args) expected_message = validation.MESSAGES['INVALID_OPTION'].format( option_list=sorted([ "westcoast", "eastcoast", "northsea4", "northsea10", "australia", "global" ])) actual_messages = '' for keys, error_strings in validation_error_list: actual_messages += error_strings self.assertTrue(expected_message in actual_messages)
def test_validate_keys_missing_values(self): """WaveEnergy: testing validate when keys are missing values.""" from natcap.invest import wave_energy args = WaveEnergyRegressionTests.generate_base_args(self.workspace_dir) args['wave_base_data_path'] = None args['dem_path'] = None validation_error_list = wave_energy.validate(args) expected_errors = [ (['wave_base_data_path'], 'Parameter not found or is not a folder.'), (['dem_path'], 'Parameter must be a filepath to a GDAL-compatible raster file.') ] for expected_error in expected_errors: self.assertTrue(expected_error in validation_error_list)