def test_iso3_country_name(self): """iso3 and country name produce same output:""" ent = SpamAgrar() testdata = self.init_testdata() testdata1, teststr1 = ent._spam_set_country(testdata, country='AAA') testdata2, teststr2 = ent._spam_set_country(testdata, country='countryA') self.assert_pd_frame_equal(testdata1, testdata2) self.assertEqual(teststr1, 'AAA') self.assertEqual(teststr2, 'countryA')
def test_invalid_adm1(self): """invalid admin 1 name produces unchanged dataframe:""" ent = SpamAgrar() testdata = self.init_testdata() with self.assertLogs('climada.entity.exposures.spam_agrar', level='INFO') as cm: testdata1, teststr1 = ent._spam_set_country(testdata, name_adm1='stateC', name_adm2='XXX') testdata2 = ent._spam_set_country(testdata, name_adm1='stateC')[0] self.assertIn('Admin2 not found in data: XXX', cm.output[0]) self.assert_pd_frame_equal(testdata1, testdata2) self.assertEqual(teststr1, ' stateC')
def test_all_names_given(self): """all names given and returned as string:""" ent = SpamAgrar() testdata = self.init_testdata() testdata1, teststr1 = ent._spam_set_country(testdata, name_adm2='municB') testdata2, teststr2 = ent._spam_set_country(testdata, country='AAA', name_adm1='kantonB', name_adm2='municB') self.assert_pd_frame_equal(testdata1, testdata2) self.assertEqual(teststr1, ' municB') self.assertEqual(teststr2, 'AAA kantonB municB')
def test_invalid_country(self): """invalid country name produces unchanged dataframe:""" ent = SpamAgrar() testdata = self.init_testdata() with self.assertLogs('climada.entity.exposures.spam_agrar', level='INFO') as cm: testdata1 = ent._spam_set_country(testdata, country='XXX')[0] self.assertIn('Country name not found in data: XXX', cm.output[0]) self.assert_pd_frame_equal(testdata1, testdata)