mirror of
https://github.com/osm-search/Nominatim.git
synced 2026-02-16 15:47:58 +00:00
add tests for get_string_list()
Renaming test file for sanitizer config because pytest requires unique names for test files.
This commit is contained in:
@@ -33,7 +33,7 @@ class SanitizerConfig(UserDict):
|
|||||||
return None if default is None else list(default)
|
return None if default is None else list(default)
|
||||||
|
|
||||||
if isinstance(values, str):
|
if isinstance(values, str):
|
||||||
return [values]
|
return [values] if values else []
|
||||||
|
|
||||||
if not isinstance(values, (list, tuple)):
|
if not isinstance(values, (list, tuple)):
|
||||||
raise UsageError(f"Parameter '{param}' must be string or list of strings.")
|
raise UsageError(f"Parameter '{param}' must be string or list of strings.")
|
||||||
|
|||||||
@@ -13,6 +13,40 @@ from nominatim.errors import UsageError
|
|||||||
from nominatim.tokenizer.place_sanitizer import PlaceName
|
from nominatim.tokenizer.place_sanitizer import PlaceName
|
||||||
from nominatim.tokenizer.sanitizers.config import SanitizerConfig
|
from nominatim.tokenizer.sanitizers.config import SanitizerConfig
|
||||||
|
|
||||||
|
def test_string_list_default_empty():
|
||||||
|
assert SanitizerConfig().get_string_list('op') == []
|
||||||
|
|
||||||
|
|
||||||
|
def test_string_list_default_none():
|
||||||
|
assert SanitizerConfig().get_string_list('op', default=None) is None
|
||||||
|
|
||||||
|
|
||||||
|
def test_string_list_default_something():
|
||||||
|
assert SanitizerConfig().get_string_list('op', default=['a', 'b']) == ['a', 'b']
|
||||||
|
|
||||||
|
|
||||||
|
def test_string_list_value_string():
|
||||||
|
assert SanitizerConfig({'op': 't'}).get_string_list('op', default=['a', 'b']) == ['t']
|
||||||
|
|
||||||
|
|
||||||
|
def test_string_list_value_list():
|
||||||
|
assert SanitizerConfig({'op': ['1', '2']}).get_string_list('op') == ['1', '2']
|
||||||
|
|
||||||
|
|
||||||
|
def test_string_list_value_empty():
|
||||||
|
assert SanitizerConfig({'op': ''}).get_string_list('op', default=['a', 'b']) == []
|
||||||
|
|
||||||
|
|
||||||
|
def test_string_list_value_dict():
|
||||||
|
with pytest.raises(UsageError):
|
||||||
|
SanitizerConfig({'op': {'1': 'a'}}).get_string_list('op')
|
||||||
|
|
||||||
|
|
||||||
|
def test_string_list_value_int_list():
|
||||||
|
with pytest.raises(UsageError):
|
||||||
|
SanitizerConfig({'op': [1, 2]}).get_string_list('op')
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('inp', ('fg34', 'f\\f', 'morning [glory]', '56.78'))
|
@pytest.mark.parametrize('inp', ('fg34', 'f\\f', 'morning [glory]', '56.78'))
|
||||||
def test_create_split_regex_no_params_unsplit(inp):
|
def test_create_split_regex_no_params_unsplit(inp):
|
||||||
regex = SanitizerConfig().get_delimiter()
|
regex = SanitizerConfig().get_delimiter()
|
||||||
Reference in New Issue
Block a user