]> git.openstreetmap.org Git - nominatim.git/blob - test/python/api/test_api_types.py
Merge remote-tracking branch 'upstream/master'
[nominatim.git] / test / python / api / test_api_types.py
1 # SPDX-License-Identifier: GPL-3.0-or-later
2 #
3 # This file is part of Nominatim. (https://nominatim.org)
4 #
5 # Copyright (C) 2023 by the Nominatim developer community.
6 # For a full list of authors see the git log.
7 """
8 Tests for loading of parameter dataclasses.
9 """
10 import pytest
11
12 from nominatim.errors import UsageError
13 import nominatim.api.types as typ
14
15 def test_no_params_defaults():
16     params = typ.LookupDetails.from_kwargs({})
17
18     assert not params.parented_places
19     assert params.geometry_simplification == 0.0
20
21
22 @pytest.mark.parametrize('k,v', [('geometry_output',  'a'),
23                                  ('linked_places', 0),
24                                  ('geometry_simplification', 'NaN')])
25 def test_bad_format_reverse(k, v):
26     with pytest.raises(UsageError):
27         params = typ.ReverseDetails.from_kwargs({k: v})
28
29
30 @pytest.mark.parametrize('rin,rout', [(-23, 0), (0, 0), (1, 1),
31                                       (15, 15), (30, 30), (31, 30)])
32 def test_rank_params(rin, rout):
33     params = typ.ReverseDetails.from_kwargs({'max_rank': rin})
34
35     assert params.max_rank == rout