+ == {('PRISON', 'prison', 'amenity', 'prison', 'in'),
+ ('BAR', 'bar', 'highway', 'road', None),
+ ('GARDEN', 'garden', 'leisure', 'garden', 'near')}
+
+
+def test_add_country_names_new(analyzer, word_table):
+ with analyzer() as anl:
+ anl.add_country_names('es', {'name': 'Espagña', 'name:en': 'Spain'})
+
+ assert word_table.get_country() == {('es', 'ESPAGÑA'), ('es', 'SPAIN')}
+
+
+def test_add_country_names_extend(analyzer, word_table):
+ word_table.add_country('ch', 'SCHWEIZ')
+
+ with analyzer() as anl:
+ anl.add_country_names('ch', {'name': 'Schweiz', 'name:fr': 'Suisse'})
+
+ assert word_table.get_country() == {('ch', 'SCHWEIZ'), ('ch', 'SUISSE')}
+
+
+class TestPlaceNames:
+
+ @pytest.fixture(autouse=True)
+ def setup(self, analyzer, getorcreate_full_word):
+ with analyzer() as anl:
+ self.analyzer = anl
+ yield anl
+
+
+ def expect_name_terms(self, info, *expected_terms):
+ tokens = self.analyzer.get_word_token_info(expected_terms)
+ print (tokens)
+ for token in tokens:
+ assert token[2] is not None, "No token for {0}".format(token)
+
+ assert eval(info['names']) == set((t[2] for t in tokens))
+
+
+ def test_simple_names(self):
+ info = self.analyzer.process_place({'name': {'name': 'Soft bAr', 'ref': '34'}})
+
+ self.expect_name_terms(info, '#Soft bAr', '#34', 'Soft', 'bAr', '34')
+
+
+ @pytest.mark.parametrize('sep', [',' , ';'])
+ def test_names_with_separator(self, sep):
+ info = self.analyzer.process_place({'name': {'name': sep.join(('New York', 'Big Apple'))}})
+
+ self.expect_name_terms(info, '#New York', '#Big Apple',
+ 'new', 'york', 'big', 'apple')
+
+
+ def test_full_names_with_bracket(self):
+ info = self.analyzer.process_place({'name': {'name': 'Houseboat (left)'}})
+
+ self.expect_name_terms(info, '#Houseboat (left)', '#Houseboat',
+ 'houseboat', 'left')
+
+
+ def test_country_name(self, word_table):
+ info = self.analyzer.process_place({'name': {'name': 'Norge'},
+ 'country_feature': 'no'})
+
+ self.expect_name_terms(info, '#norge', 'norge')
+ assert word_table.get_country() == {('no', 'NORGE')}
+
+
+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')