| Total Complexity | 3 |
| Total Lines | 29 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | from dataclasses import dataclass |
||
| 2 | |||
| 3 | import pytest |
||
| 4 | |||
| 5 | from lagom import Singleton, Construction, Container |
||
| 6 | from lagom.decorators import dependency_definition |
||
| 7 | from lagom.exceptions import InvalidDependencyDefinition |
||
| 8 | |||
| 9 | @dataclass |
||
| 10 | class MyComplexDep: |
||
| 11 | some_number: int |
||
| 12 | |||
| 13 | |||
| 14 | def test_functions_that_are_typed_can_be_used_by_a_container(container: Container): |
||
| 15 | |||
| 16 | @dependency_definition(container) |
||
| 17 | def my_constructor() -> MyComplexDep: |
||
| 18 | return MyComplexDep(some_number=5) |
||
| 19 | |||
| 20 | assert container[MyComplexDep] == MyComplexDep(some_number=5) |
||
| 21 | |||
| 22 | |||
| 23 | def test_functions_that_are_not_typed_raise_an_error(container: Container): |
||
| 24 | |||
| 25 | with pytest.raises(SyntaxError): |
||
| 26 | @dependency_definition(container) |
||
| 27 | def my_constructor(): |
||
| 28 | return MyComplexDep(some_number=5) |
||
| 29 |