test_deps_can_be_overridden_by_anything()   A
last analyzed

Complexity

Conditions 2

Size

Total Lines 4
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
import pytest
2
3
from lagom import Container
4
from lagom.exceptions import DuplicateDefinition
5
6
7
class InitialDep:
8
    pass
9
10
11
class SomeMockForTesting(InitialDep):
12
    pass
13
14
15
class SomeMockThatDoesntEventExtend:
16
    pass
17
18
19
def test_deps_can_be_overridden_by_a_child_class(container: Container):
20
    container.define(InitialDep, lambda: SomeMockForTesting())
21
    resolved = container.resolve(InitialDep)
22
    assert type(resolved) == SomeMockForTesting
23
24
25
def test_deps_can_be_overridden_by_anything(container: Container):
26
    container.define(InitialDep, lambda: SomeMockThatDoesntEventExtend())  # type: ignore
27
    resolved = container.resolve(InitialDep)
28
    assert type(resolved) == SomeMockThatDoesntEventExtend
29
30
31
def test_explicit_definitions_can_only_be_made_once(container: Container):
32
    container.define(InitialDep, lambda: SomeMockForTesting())
33
34
    with pytest.raises(DuplicateDefinition):
35
        container.define(
36
            InitialDep, lambda: SomeMockThatDoesntEventExtend()  # type: ignore
37
        )
38