From d9d8b9c5262ef948d312509b7cf71cdd53791446 Mon Sep 17 00:00:00 2001 From: Sarah Hoffmann Date: Thu, 18 May 2023 18:09:07 +0200 Subject: [PATCH] add tests for parameter converter --- test/python/api/test_api_types.py | 35 +++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 test/python/api/test_api_types.py diff --git a/test/python/api/test_api_types.py b/test/python/api/test_api_types.py new file mode 100644 index 00000000..6a095bcb --- /dev/null +++ b/test/python/api/test_api_types.py @@ -0,0 +1,35 @@ +# SPDX-License-Identifier: GPL-3.0-or-later +# +# This file is part of Nominatim. (https://nominatim.org) +# +# Copyright (C) 2023 by the Nominatim developer community. +# For a full list of authors see the git log. +""" +Tests for loading of parameter dataclasses. +""" +import pytest + +from nominatim.errors import UsageError +import nominatim.api.types as typ + +def test_no_params_defaults(): + params = typ.LookupDetails.from_kwargs({}) + + assert not params.parented_places + assert params.geometry_simplification == 0.0 + + +@pytest.mark.parametrize('k,v', [('geometry_output', 'a'), + ('linked_places', 0), + ('geometry_simplification', 'NaN')]) +def test_bad_format_reverse(k, v): + with pytest.raises(UsageError): + params = typ.ReverseDetails.from_kwargs({k: v}) + + +@pytest.mark.parametrize('rin,rout', [(-23, 0), (0, 0), (1, 1), + (15, 15), (30, 30), (31, 30)]) +def test_rank_params(rin, rout): + params = typ.ReverseDetails.from_kwargs({'max_rank': rin}) + + assert params.max_rank == rout -- 2.39.5