def test_undefined_user_disturbance_type_error(self): """checks that an error is raised when a disturbance type is not present in the user value of disturbance type mapping """ config = { "disturbance_types": [{ "user_dist_type": "fire", "default_dist_type": "Wildfire" }] } ref = Mock(spec=SITCBMDefaults) sit_mapping = SITMapping(config, ref) with self.assertRaises(KeyError): sit_mapping.get_default_disturbance_type_id( pd.Series(["missing_value"]))
def test_get_disturbance_type_id_returns_expected_value(self): """Checks the expected output of SITMapping.get_disturbance_type_id """ config = { "disturbance_types": [{ "user_dist_type": "fire", "default_dist_type": "Wildfire" }, { "user_dist_type": "clearcut", "default_dist_type": "ClearCut" }] } ref = Mock(spec=SITCBMDefaults) def mock_get_disturbance_type_id(name): if name == "Wildfire": return 1 if name == "ClearCut": return 2 raise ValueError() ref.get_disturbance_type_id.side_effect = mock_get_disturbance_type_id sit_mapping = SITMapping(config, ref) result = sit_mapping.get_default_disturbance_type_id( pd.Series(["fire"] + ["clearcut"])) self.assertTrue(list(result) == [1, 2])
def test_duplicated_user_disturbance_type_error(self): """checks that an error is raised when a disturbance type is duplicated in the sit json config """ config = { "disturbance_types": [{ "user_dist_type": "duplicated", "default_dist_type": "Wildfire" }, { "user_dist_type": "duplicated", "default_dist_type": "Clearcut" }] } ref = Mock(spec=SITCBMDefaults) sit_mapping = SITMapping(config, ref) with self.assertRaises(KeyError): sit_mapping.get_default_disturbance_type_id( pd.Series(["duplicated"]))
def test_undefined_default_disturbance_type_error(self): """checks that an error is raised when a default disturbance type is not present in the disturbance type reference """ config = { "disturbance_types": [{ "user_dist_type": "fire", "default_dist_type": "Wildfire" }] } ref = Mock(spec=SITCBMDefaults) def mock_get_disturbance_type_id(name): raise KeyError() ref.get_disturbance_type_id.side_effect = \ mock_get_disturbance_type_id sit_mapping = SITMapping(config, ref) with self.assertRaises(KeyError): sit_mapping.get_default_disturbance_type_id(pd.Series(["fire"])) self.assertTrue(ref.get_disturbance_type_id.called)