def test_fill_admin1_geom_fail(self): """Test function _fill_admin1_geom fail.""" iso3 = 'CHE' admin1_rec = list(ADM1_FILE.records()) prov_list = ['Barcelona'] with self.assertRaises(ValueError): with self.assertLogs('climada.entity.exposures.black_marble', level='ERROR') as cm: _fill_admin1_geom(iso3, admin1_rec, prov_list) self.assertIn('Barcelona not found. Possible provinces of CHE are: ', cm.output[0])
def test_fill_admin1_geom_fail(self): """Test function _fill_admin1_geom fail.""" iso3 = 'CHE' admin1_rec = list(ADM1_FILE.records()) prov_list = ['Barcelona'] with self.assertRaises(ValueError) as cm: _fill_admin1_geom(iso3, admin1_rec, prov_list) self.assertIn('Barcelona not found. Possible provinces of CHE are: ', str(cm.exception))
def test_fill_admin1_geom_pass(self): """Test function _fill_admin1_geom pass.""" iso3 = 'ESP' admin1_rec = list(ADM1_FILE.records()) prov_list = ['Barcelona'] res_bcn = _fill_admin1_geom(iso3, admin1_rec, prov_list) self.assertEqual(len(res_bcn), 1) self.assertIsInstance(res_bcn[0], shapely.geometry.polygon.Polygon) prov_list = ['Barcelona', 'Tarragona'] res_bcn = _fill_admin1_geom(iso3, admin1_rec, prov_list) self.assertEqual(len(res_bcn), 2) self.assertIsInstance(res_bcn[0], shapely.geometry.polygon.Polygon) self.assertIsInstance(res_bcn[1], shapely.geometry.polygon.Polygon)