tests.experimental.test_function_injection   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 16
dl 0
loc 25
rs 10
c 0
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A ClassNeedingAFunction.trigger() 0 3 1
A ClassNeedingAFunction.__init__() 0 2 1

2 Functions

Rating   Name   Duplication   Size   Complexity  
A test_ways_of_constructing_functions_can_be_provided() 0 4 1
A add_stuff() 0 2 1
1
from typing import Callable
2
3
4
from lagom import Container
5
from lagom.experimental.definitions import PlainFunction
6
7
8
class ClassNeedingAFunction:
9
    def __init__(self, adder: Callable[[int, int], int]):
10
        self.adder = adder
11
12
    def trigger(self, x, y):
13
        adder = self.adder
14
        return adder(x, y)
15
16
17
def add_stuff(x: int, y: int) -> int:
18
    return x + y
19
20
21
def test_ways_of_constructing_functions_can_be_provided(container: Container):
22
    container[Callable[[int, int], int]] = PlainFunction(add_stuff)  # type: ignore
23
    erm = container[ClassNeedingAFunction]
24
    assert erm.trigger(2, 3) == 5
25