| Total Complexity | 9 |
| Total Lines | 31 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | import pytest |
||
| 2 | |||
| 3 | from lagom import Singleton, Construction, Container |
||
| 4 | from lagom.exceptions import InvalidDependencyDefinition |
||
| 5 | |||
| 6 | |||
| 7 | class MyBasicDep: |
||
| 8 | basic_value = 5 |
||
| 9 | pass |
||
| 10 | |||
| 11 | |||
| 12 | class ComplexDep: |
||
| 13 | def __init__(self, some_dep): |
||
| 14 | self.value = some_dep.basic_value |
||
| 15 | |||
| 16 | |||
| 17 | def test_lambda_arity_zero_works(container: Container): |
||
| 18 | container.define(MyBasicDep, lambda: MyBasicDep()) |
||
| 19 | assert type(container[MyBasicDep]) == MyBasicDep |
||
| 20 | |||
| 21 | |||
| 22 | def test_lambda_arity_one_is_passed_the_container(container: Container): |
||
| 23 | container.define(MyBasicDep, lambda: MyBasicDep()) |
||
| 24 | container.define(ComplexDep, lambda c: ComplexDep(c[MyBasicDep])) |
||
| 25 | assert container[ComplexDep].value == 5 |
||
| 26 | |||
| 27 | |||
| 28 | def test_lambda_arity_two_results_in_an_error(container: Container): |
||
| 29 | with pytest.raises(InvalidDependencyDefinition): |
||
| 30 | container.define(MyBasicDep, lambda _x, _y: MyBasicDep) |
||
| 31 |