Passed
Push — mpeta ( 1841cb...62640f )
by Konstantinos
03:46
created

test_singleton   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 23
dl 0
loc 27
rs 10
c 0
b 0
f 0
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A tests.test_singleton.test_singleton() 0 26 3
1
def test_singleton():
2
    from so_magic.utils import Singleton
3
4
    class ObjectRegistry(metaclass=Singleton):
5
        def __init__(self):
6
            super().__init__()
7
            self.objects = {}
8
9
    reg1 = ObjectRegistry()
10
    reg1.objects['a'] = 1
11
    reg2 = ObjectRegistry()
12
    assert reg2.objects == {'a': 1}
13
    reg2.objects['b'] = 2
14
    reg3 = ObjectRegistry()
15
16
    rs = [reg1, reg2, reg3]
17
18
    assert id(reg1) == id(reg2) == id(reg3)
19
    for i in rs:
20
        assert i.objects == {'a': 1, 'b': 2}
21
    assert all(x.objects == {'a': 1,
22
                             'b': 2} for x in rs)
23
    del reg3.objects['a']
24
    assert all(x.objects == {'b': 2} for x in rs)
25
    for i in rs:
26
        assert i.objects == {'b': 2}
27