tests.test_magic_partial_async_functions   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 42
dl 0
loc 66
rs 10
c 0
b 0
f 0
wmc 5

5 Functions

Rating   Name   Duplication   Size   Complexity  
A test_calling_async_partials_works_as_expected() 0 7 1
A test_partial_application_async_functions_with_shared_pass_iscoroutinefunction() 0 8 1
A test_partial_application_async_functions_pass_iscoroutinefunction() 0 8 1
A test_calling_async_partials_on_a_object_works_as_expected() 0 14 1
A test_calling_async_partials_works_as_expected_with_shared_too() 0 9 1
1
import inspect
2
3
import pytest
4
5
from lagom import Container, magic_bind_to_container, injectable
6
7
8
class Something:
9
    pass
10
11
12
def test_partial_application_async_functions_pass_iscoroutinefunction(
13
    container: Container,
14
):
15
    @magic_bind_to_container(container)
16
    async def example_async_function(message: str) -> str:
17
        return message
18
19
    assert inspect.iscoroutinefunction(example_async_function)
20
21
22
def test_partial_application_async_functions_with_shared_pass_iscoroutinefunction(
23
    container: Container,
24
):
25
    @magic_bind_to_container(container, shared=[Something])
26
    async def example_async_function(message: str) -> str:
27
        return message
28
29
    assert inspect.iscoroutinefunction(example_async_function)
30
31
32
@pytest.mark.asyncio
33
async def test_calling_async_partials_works_as_expected(container: Container):
34
    @magic_bind_to_container(container)
35
    async def example_async_function(message: str) -> str:
36
        return message
37
38
    assert await example_async_function("test") == "test"
39
40
41
@pytest.mark.asyncio
42
async def test_calling_async_partials_on_a_object_works_as_expected(
43
    container: Container,
44
):
45
    class Thingy:
46
        async def example_async_function(
47
            self, message: str, something: Something = injectable
48
        ) -> str:
49
            assert isinstance(something, Something)
50
            return message
51
52
    thing = Thingy()
53
    bound_thing = container.partial(thing.example_async_function)
54
    assert await bound_thing("test") == "test"
55
56
57
@pytest.mark.asyncio
58
async def test_calling_async_partials_works_as_expected_with_shared_too(
59
    container: Container,
60
):
61
    @magic_bind_to_container(container, shared=[Something])
62
    async def example_async_function(message: str) -> str:
63
        return message
64
65
    assert await example_async_function("test") == "test"
66