File: test_inheritance.py

package info (click to toggle)
python-async-property 0.2.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 288 kB
  • sloc: python: 765; makefile: 87; sh: 6
file content (46 lines) | stat: -rw-r--r-- 958 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import pytest

from async_property import async_cached_property, AwaitLoader
from async_property.loader import get_loaders

pytestmark = pytest.mark.asyncio


class TestLoaderA(AwaitLoader):
    @async_cached_property
    async def foo(self):
        return True


class TestLoaderB(AwaitLoader):
    @async_cached_property
    async def bar(self):
        return False


class TestLoader(TestLoaderA, TestLoaderB):
    @async_cached_property
    async def abc(self):
        return 123

    @async_cached_property
    async def foo(self):
        return False


async def test_loaders_exist():
    instance = TestLoader()
    assert len(get_loaders(instance)) == 3


async def test_loader_keys():
    instance = TestLoader()
    assert set(dict(get_loaders(instance))) == {'foo', 'bar', 'abc'}


async def test_inherited_value():
    instance = await TestLoader()
    assert instance.foo == False

    base = await TestLoaderA()
    assert base.foo == True