Passed
Pull Request — dev (#32)
by Konstantinos
64:40
created

test_registry_pop_method()   A

Complexity

Conditions 2

Size

Total Lines 10
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 8
nop 1
dl 0
loc 10
rs 10
c 0
b 0
f 0
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