]> git.openstreetmap.org Git - nominatim.git/blob - test/python/api/test_timeout.py
prepare release 5.1.0.post16
[nominatim.git] / test / python / api / test_timeout.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) 2025 by the Nominatim developer community.
6 # For a full list of authors see the git log.
7 """
8 Tests for timeout helper
9 """
10 import asyncio
11
12 import pytest
13
14 from nominatim_api.timeout import Timeout
15
16
17 @pytest.mark.asyncio
18 async def test_timeout_none():
19     timeout = Timeout(None)
20
21     assert timeout.abs is None
22     assert not timeout.is_elapsed()
23
24
25 @pytest.mark.asyncio
26 async def test_timeout_should_not_be_elapsed_after_creation():
27     assert not Timeout(2).is_elapsed()
28
29
30 @pytest.mark.asyncio
31 async def test_timeout_elapse():
32     timeout = Timeout(0.5)
33
34     assert timeout.abs is not None
35     await asyncio.sleep(0.5)
36     assert timeout.is_elapsed()