X-Git-Url: https://git.openstreetmap.org./nominatim.git/blobdiff_plain/18c99a5c5f55636175a0b1baa2a8e3d426b0937c..8f3429939ff0566d9ca848d3909540e4bb92b474:/test/python/test_tokenizer_legacy_icu.py diff --git a/test/python/test_tokenizer_legacy_icu.py b/test/python/test_tokenizer_legacy_icu.py index 836f15b9..abb058d2 100644 --- a/test/python/test_tokenizer_legacy_icu.py +++ b/test/python/test_tokenizer_legacy_icu.py @@ -141,16 +141,28 @@ def test_make_standard_hnr(analyzer): assert a._make_standard_hnr('iv') == 'IV' -def test_add_postcodes_from_db(analyzer, word_table, table_factory, temp_db_cursor): +def test_update_postcodes_from_db_empty(analyzer, table_factory, word_table): table_factory('location_postcode', 'postcode TEXT', content=(('1234',), ('12 34',), ('AB23',), ('1234',))) with analyzer() as a: - a.add_postcodes_from_db() + a.update_postcodes_from_db() - assert temp_db_cursor.row_set("""SELECT word, word_token from word - """) \ - == set((('1234', ' 1234'), ('12 34', ' 12 34'), ('AB23', ' AB23'))) + assert word_table.count() == 3 + assert word_table.get_postcodes() == {'1234', '12 34', 'AB23'} + + +def test_update_postcodes_from_db_add_and_remove(analyzer, table_factory, word_table): + table_factory('location_postcode', 'postcode TEXT', + content=(('1234',), ('45BC', ), ('XX45', ))) + word_table.add_postcode(' 1234', '1234') + word_table.add_postcode(' 5678', '5678') + + with analyzer() as a: + a.update_postcodes_from_db() + + assert word_table.count() == 3 + assert word_table.get_postcodes() == {'1234', '45BC', 'XX45'} def test_update_special_phrase_empty_table(analyzer, word_table, temp_db_cursor): @@ -159,7 +171,7 @@ def test_update_special_phrase_empty_table(analyzer, word_table, temp_db_cursor) ("König bei", "amenity", "royal", "near"), ("Könige", "amenity", "royal", "-"), ("street", "highway", "primary", "in") - ]) + ], True) assert temp_db_cursor.row_set("""SELECT word_token, word, class, type, operator FROM word WHERE class != 'place'""") \ @@ -176,11 +188,24 @@ def test_update_special_phrase_delete_all(analyzer, word_table, temp_db_cursor): assert 2 == temp_db_cursor.scalar("SELECT count(*) FROM word WHERE class != 'place'""") with analyzer() as a: - a.update_special_phrases([]) + a.update_special_phrases([], True) assert 0 == temp_db_cursor.scalar("SELECT count(*) FROM word WHERE class != 'place'""") +def test_update_special_phrases_no_replace(analyzer, word_table, temp_db_cursor,): + temp_db_cursor.execute("""INSERT INTO word (word_token, word, class, type, operator) + VALUES (' FOO', 'foo', 'amenity', 'prison', 'in'), + (' BAR', 'bar', 'highway', 'road', null)""") + + assert 2 == temp_db_cursor.scalar("SELECT count(*) FROM word WHERE class != 'place'""") + + with analyzer() as a: + a.update_special_phrases([], False) + + assert 2 == temp_db_cursor.scalar("SELECT count(*) FROM word WHERE class != 'place'""") + + def test_update_special_phrase_modify(analyzer, word_table, temp_db_cursor): temp_db_cursor.execute("""INSERT INTO word (word_token, word, class, type, operator) VALUES (' FOO', 'foo', 'amenity', 'prison', 'in'), @@ -193,7 +218,7 @@ def test_update_special_phrase_modify(analyzer, word_table, temp_db_cursor): ('prison', 'amenity', 'prison', 'in'), ('bar', 'highway', 'road', '-'), ('garden', 'leisure', 'garden', 'near') - ]) + ], True) assert temp_db_cursor.row_set("""SELECT word_token, word, class, type, operator FROM word WHERE class != 'place'""") \ @@ -211,22 +236,19 @@ def test_process_place_names(analyzer, getorcreate_term_id): @pytest.mark.parametrize('pc', ['12345', 'AB 123', '34-345']) -def test_process_place_postcode(analyzer, temp_db_cursor, pc): +def test_process_place_postcode(analyzer, word_table, pc): with analyzer() as a: info = a.process_place({'address': {'postcode' : pc}}) - assert temp_db_cursor.row_set("""SELECT word FROM word - WHERE class = 'place' and type = 'postcode'""") \ - == set(((pc, ),)) + assert word_table.get_postcodes() == {pc, } @pytest.mark.parametrize('pc', ['12:23', 'ab;cd;f', '123;836']) -def test_process_place_bad_postcode(analyzer, temp_db_cursor, pc): +def test_process_place_bad_postcode(analyzer, word_table, pc): with analyzer() as a: info = a.process_place({'address': {'postcode' : pc}}) - assert 0 == temp_db_cursor.scalar("""SELECT count(*) FROM word - WHERE class = 'place' and type = 'postcode'""") + assert not word_table.get_postcodes() @pytest.mark.parametrize('hnr', ['123a', '1', '101'])