File: test_timeoutdict.py

package info (click to toggle)
aiocoap 0.4.14-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 1,756 kB
  • sloc: python: 16,846; makefile: 23; sh: 9
file content (23 lines) | stat: -rw-r--r-- 573 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# SPDX-FileCopyrightText: Christian Amsüss and the aiocoap contributors
#
# SPDX-License-Identifier: MIT

import asyncio

from aiocoap.util.asyncio.timeoutdict import TimeoutDict

from .fixtures import WithAsyncLoop, asynctest


class TestTimeoutDict(WithAsyncLoop):
    @asynctest
    async def test_presence_and_absence(self):
        timeout = 0.2
        d = TimeoutDict(timeout)
        d["k"] = "v"
        await asyncio.sleep(timeout / 2)

        assert d["k"] == "v"

        await asyncio.sleep(timeout * 2.5)
        self.assertRaises(KeyError, lambda: d["k"])