| Total Complexity | 5 |
| Total Lines | 40 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | from lagom import Container |
||
| 2 | |||
| 3 | |||
| 4 | class Dep: |
||
| 5 | def __init__(self, contents: str): |
||
| 6 | self.contents = contents |
||
| 7 | |||
| 8 | |||
| 9 | class OtherDep: |
||
| 10 | def __init__(self, dep: Dep): |
||
| 11 | self.dep = dep |
||
| 12 | |||
| 13 | |||
| 14 | class OtherDepNeedingALambda: |
||
| 15 | def __init__(self, dep): |
||
| 16 | self.dep = dep |
||
| 17 | |||
| 18 | |||
| 19 | level_one = Container() |
||
| 20 | level_one[Dep] = Dep("level one") |
||
| 21 | level_one[OtherDepNeedingALambda] = lambda c: OtherDepNeedingALambda(c[Dep]) |
||
|
|
|||
| 22 | |||
| 23 | level_two = level_one.clone() |
||
| 24 | level_two[Dep] = Dep("level two") |
||
| 25 | |||
| 26 | level_three = level_two.clone() |
||
| 27 | level_three[Dep] = Dep("level three") |
||
| 28 | |||
| 29 | |||
| 30 | def test_container_invocation_level_controls_the_dep_loaded_for_reflected_constructions(): |
||
| 31 | assert level_one[OtherDep].dep.contents == "level one" |
||
| 32 | assert level_two[OtherDep].dep.contents == "level two" |
||
| 33 | assert level_three[OtherDep].dep.contents == "level three" |
||
| 34 | |||
| 35 | |||
| 36 | def test_container_invocation_level_is_passed_to_lambdas(): |
||
| 37 | assert level_one[OtherDepNeedingALambda].dep.contents == "level one" |
||
| 38 | assert level_two[OtherDepNeedingALambda].dep.contents == "level two" |
||
| 39 | assert level_three[OtherDepNeedingALambda].dep.contents == "level three" |
||
| 40 |