+class TestPlaceAddress:
+
+ @pytest.fixture(autouse=True)
+ def setup(self, analyzer, getorcreate_full_word):
+ with analyzer(trans=(":: upper()", "'🜵' > ' '")) as anl:
+ self.analyzer = anl
+ yield anl
+
+
+ def process_address(self, **kwargs):
+ return self.analyzer.process_place({'address': kwargs})
+
+
+ def name_token_set(self, *expected_terms):
+ tokens = self.analyzer.get_word_token_info(expected_terms)
+ for token in tokens:
+ assert token[2] is not None, "No token for {0}".format(token)
+
+ return set((t[2] for t in tokens))
+
+
+ @pytest.mark.parametrize('pcode', ['12345', 'AB 123', '34-345'])
+ def test_process_place_postcode(self, word_table, pcode):
+ self.process_address(postcode=pcode)
+
+ assert word_table.get_postcodes() == {pcode, }
+
+
+ @pytest.mark.parametrize('pcode', ['12:23', 'ab;cd;f', '123;836'])
+ def test_process_place_bad_postcode(self, word_table, pcode):
+ self.process_address(postcode=pcode)
+
+ assert not word_table.get_postcodes()
+
+
+ @pytest.mark.parametrize('hnr', ['123a', '1', '101'])
+ def test_process_place_housenumbers_simple(self, hnr, getorcreate_hnr_id):
+ info = self.process_address(housenumber=hnr)
+
+ assert info['hnr'] == hnr.upper()
+ assert info['hnr_tokens'] == "{-1}"
+
+
+ def test_process_place_housenumbers_lists(self, getorcreate_hnr_id):
+ info = self.process_address(conscriptionnumber='1; 2;3')
+
+ assert set(info['hnr'].split(';')) == set(('1', '2', '3'))
+ assert info['hnr_tokens'] == "{-1,-2,-3}"
+
+
+ def test_process_place_housenumbers_duplicates(self, getorcreate_hnr_id):
+ info = self.process_address(housenumber='134',
+ conscriptionnumber='134',
+ streetnumber='99a')
+
+ assert set(info['hnr'].split(';')) == set(('134', '99A'))
+ assert info['hnr_tokens'] == "{-1,-2}"
+
+
+ def test_process_place_housenumbers_cached(self, getorcreate_hnr_id):
+ info = self.process_address(housenumber="45")
+ assert info['hnr_tokens'] == "{-1}"
+
+ info = self.process_address(housenumber="46")
+ assert info['hnr_tokens'] == "{-2}"
+
+ info = self.process_address(housenumber="41;45")
+ assert eval(info['hnr_tokens']) == {-1, -3}
+
+ info = self.process_address(housenumber="41")
+ assert eval(info['hnr_tokens']) == {-3}
+
+
+ def test_process_place_street(self):
+ info = self.process_address(street='Grand Road')
+
+ assert eval(info['street']) == self.name_token_set('#GRAND ROAD')
+
+
+ def test_process_place_street_empty(self):
+ info = self.process_address(street='🜵')
+
+ assert 'street' not in info
+
+
+ def test_process_place_place(self):
+ info = self.process_address(place='Honu Lulu')
+
+ assert eval(info['place_search']) == self.name_token_set('#HONU LULU',
+ 'HONU', 'LULU')
+ assert eval(info['place_match']) == self.name_token_set('#HONU LULU')
+
+
+ def test_process_place_place_empty(self):
+ info = self.process_address(place='🜵')
+
+ assert 'place_search' not in info
+ assert 'place_match' not in info
+
+
+ def test_process_place_address_terms(self):
+ info = self.process_address(country='de', city='Zwickau', state='Sachsen',
+ suburb='Zwickau', street='Hauptstr',
+ full='right behind the church')
+
+ city_full = self.name_token_set('#ZWICKAU')
+ city_all = self.name_token_set('#ZWICKAU', 'ZWICKAU')
+ state_full = self.name_token_set('#SACHSEN')
+ state_all = self.name_token_set('#SACHSEN', 'SACHSEN')
+
+ result = {k: [eval(v[0]), eval(v[1])] for k,v in info['addr'].items()}
+
+ assert result == {'city': [city_all, city_full],
+ 'suburb': [city_all, city_full],
+ 'state': [state_all, state_full]}
+
+
+ def test_process_place_address_terms_empty(self):
+ info = self.process_address(country='de', city=' ', street='Hauptstr',
+ full='right behind the church')
+
+ assert 'addr' not in info
+