2 Tests for execution of the sanitztion step.
6 from nominatim.errors import UsageError
7 import nominatim.tokenizer.place_sanitizer as sanitizer
8 from nominatim.indexer.place_info import PlaceInfo
11 def test_placeinfo_clone_new_name():
12 place = sanitizer.PlaceName('foo', 'ki', 'su')
14 newplace = place.clone(name='bar')
16 assert place.name == 'foo'
17 assert newplace.name == 'bar'
18 assert newplace.kind == 'ki'
19 assert newplace.suffix == 'su'
22 def test_placeinfo_clone_merge_attr():
23 place = sanitizer.PlaceName('foo', 'ki', 'su')
24 place.set_attr('a1', 'v1')
25 place.set_attr('a2', 'v2')
27 newplace = place.clone(attr={'a2': 'new', 'b2': 'foo'})
29 assert place.get_attr('a2') == 'v2'
30 assert place.get_attr('b2') is None
31 assert newplace.get_attr('a1') == 'v1'
32 assert newplace.get_attr('a2') == 'new'
33 assert newplace.get_attr('b2') == 'foo'
36 def test_placeinfo_has_attr():
37 place = sanitizer.PlaceName('foo', 'ki', 'su')
38 place.set_attr('a1', 'v1')
40 assert place.has_attr('a1')
41 assert not place.has_attr('whatever')
44 def test_sanitizer_default():
45 san = sanitizer.PlaceSanitizer([{'step': 'split-name-list'}])
47 name, address = san.process_names(PlaceInfo({'name': {'name:de:de': '1;2;3'},
48 'address': {'street': 'Bald'}}))
51 assert all(isinstance(n, sanitizer.PlaceName) for n in name)
52 assert all(n.kind == 'name' for n in name)
53 assert all(n.suffix == 'de:de' for n in name)
55 assert len(address) == 1
56 assert all(isinstance(n, sanitizer.PlaceName) for n in address)
59 @pytest.mark.parametrize('rules', [None, []])
60 def test_sanitizer_empty_list(rules):
61 san = sanitizer.PlaceSanitizer(rules)
63 name, address = san.process_names(PlaceInfo({'name': {'name:de:de': '1;2;3'}}))
66 assert all(isinstance(n, sanitizer.PlaceName) for n in name)
69 def test_sanitizer_missing_step_definition():
70 with pytest.raises(UsageError):
71 san = sanitizer.PlaceSanitizer([{'id': 'split-name-list'}])