Completed
Push — master ( 336d1a...d357d6 )
by Konstantinos
20s queued 13s
created

test_singleton   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 1
eloc 15
dl 0
loc 22
rs 10
c 0
b 0
f 0

1 Function

Rating   Name   Duplication   Size   Complexity  
A test_singleton() 0 16 1
1
import typing as t
2
3
from software_patterns import Singleton
4
5
6
def test_singleton():
7
    class MySingleton(metaclass=Singleton):
8
        def __init__(self, data: t.Mapping):
9
            self.data = data
10
11
    instance_1 = MySingleton({'a': 1})
12
    instance_2 = MySingleton({'b': 2})
13
14
    assert id(instance_1) == id(instance_2)
15
    assert instance_1.data['a'] == instance_2.data['a'] == 1
16
    assert 'b' not in instance_1.data
17
    assert 'b' not in instance_2.data
18
19
    instance_1.data['c'] = 0
20
21
    assert instance_2.data['c'] == 0
22