Passed
Pull Request — dev (#32)
by Konstantinos
59:25 queued 55:43
created

test_utils.test_registry   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 29
dl 0
loc 44
rs 10
c 0
b 0
f 0
wmc 7

4 Functions

Rating   Name   Duplication   Size   Complexity  
A test_registry_remove_method() 0 9 2
A test_registry_get_method() 0 10 2
A registry_infra() 0 5 1
A test_registry_pop_method() 0 10 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
                                          'existing_key': 'key1', 'non_existing_key': 'key2'})
9
10
11
def test_registry_remove_method(registry_infra):
12
    assert registry_infra.existing_key in registry_infra.object
13
14
    registry_infra.object.remove(registry_infra.existing_key)
15
    assert registry_infra.object.objects == {}
16
17
    with pytest.raises(registry_infra.error,
18
                       match=f'Requested to remove item with key {registry_infra.existing_key}, which does not exist.'):
19
        registry_infra.object.remove(registry_infra.existing_key)
20
21
22
def test_registry_pop_method(registry_infra):
23
    assert registry_infra.existing_key in registry_infra.object
24
25
    value = registry_infra.object.pop(registry_infra.existing_key)
26
    assert value == 1
27
    assert registry_infra.object.objects == {}
28
29
    with pytest.raises(registry_infra.error,
30
                       match=f'Requested to pop item with key {registry_infra.existing_key}, which does not exist.'):
31
        registry_infra.object.pop(registry_infra.existing_key)
32
33
34
def test_registry_get_method(registry_infra):
35
    assert registry_infra.existing_key in registry_infra.object
36
37
    value = registry_infra.object.get(registry_infra.existing_key)
38
    assert value == 1
39
    assert registry_infra.object.objects == {registry_infra.existing_key: 1}
40
41
    with pytest.raises(registry_infra.error, match=f'Requested to get item with key {registry_infra.non_existing_key}, '
42
                                                   f'which does not exist.'):
43
        _ = registry_infra.object.get(registry_infra.non_existing_key)
44