Passed
Pull Request — dev (#32)
by Konstantinos
03:16 queued 01:49
created

test_utils.test_registry   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 33
dl 0
loc 47
rs 10
c 0
b 0
f 0
wmc 7

4 Functions

Rating   Name   Duplication   Size   Complexity  
A test_registry_remove_method() 0 10 2
A test_registry_get_method() 0 12 2
A registry_infra() 0 4 1
A test_registry_pop_method() 0 11 2
1
import pytest
2
3
4
@pytest.fixture
5
def registry_infra():
6
    from so_magic.utils import ObjectRegistry, ObjectRegistryError
7
    return type('DummyClass', (object,), {'object': ObjectRegistry({'key1': 1}), 'error': ObjectRegistryError})
8
9
10
def test_registry_remove_method(registry_infra):
11
    key_to_remove = 'key1'
12
    assert key_to_remove in registry_infra.object
13
14
    registry_infra.object.remove(key_to_remove)
15
    assert registry_infra.object.objects == {}
16
17
    with pytest.raises(registry_infra.error,
18
                       match=f'Requested to remove item with key {key_to_remove}, which does not exist.'):
19
        registry_infra.object.remove(key_to_remove)
20
    
21
22
def test_registry_pop_method(registry_infra):
23
    key_to_pop = 'key1'
24
    assert key_to_pop in registry_infra.object
25
26
    value = registry_infra.object.pop(key_to_pop)
27
    assert value == 1
28
    assert registry_infra.object.objects == {}
29
30
    with pytest.raises(registry_infra.error,
31
                       match=f'Requested to pop item with key {key_to_pop}, which does not exist.'):
32
        registry_infra.object.pop(key_to_pop)
33
34
35
def test_registry_get_method(registry_infra):
36
    key_to_get = 'key1'
37
    assert key_to_get in registry_infra.object
38
39
    value = registry_infra.object.get(key_to_get)
40
    assert value == 1
41
    assert registry_infra.object.objects == {'key1': 1}
42
43
    non_existing_key = 'key2'
44
    with pytest.raises(registry_infra.error,
45
                       match=f'Requested to get item with key {non_existing_key}, which does not exist.'):
46
        _ = registry_infra.object.get(non_existing_key)
47