Completed
Pull Request — master (#4)
by Steve
04:09
created

test.test_partial_functions.example_generator()   A

Complexity

Conditions 1

Size

Total Lines 2
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 2
rs 10
c 0
b 0
f 0
cc 1
nop 2
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