Passed
Push — master ( af33de...5841e5 )
by Steve
02:15
created

test.test_partial_functions   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 7
eloc 26
dl 0
loc 44
rs 10
c 0
b 0
f 0

6 Functions

Rating   Name   Duplication   Size   Complexity  
A test_partial_application_can_be_applied_to_functions() 0 3 1
A example_generator() 0 2 1
A example_function() 0 2 1
A test_a_decorator_can_be_used_to_bind_as_well() 0 2 1
A test_partial_application_can_be_applied_to_generators() 0 6 2
A another_example_function() 0 3 1
1
from typing import Generator, AsyncGenerator
2
3
import pytest
4
5
from lagom import Container, bind_to_container
6
from lagom.exceptions import UnresolvableType
7
8
9
class MyDep:
10
    value: str = "testing"
11
12
13
container = Container()
14
15
16
def example_function(resolved: MyDep, message: str) -> str:
17
    return resolved.value + message
18
19
20
def example_generator(resolved: MyDep, message: str) -> Generator:
21
    yield resolved.value + message
22
23
24
@bind_to_container(container)
25
def another_example_function(resolved: MyDep, message: str) -> str:
26
    return resolved.value + message
27
28
29
def test_partial_application_can_be_applied_to_functions():
30
    partial = container.partial(example_function)
31
    assert partial(message=" world") == "testing world"
32
33
34
def test_a_decorator_can_be_used_to_bind_as_well():
35
    assert another_example_function(message=" hello") == "testing hello"
36
37
38
def test_partial_application_can_be_applied_to_generators():
39
    partial = container.partial(example_generator)
40
    results = []
41
    for result in partial(message=" world"):
42
        results.append(result)
43
    assert results == ["testing world"]
44