Passed
Push — dev ( 3ac626...71cb7d )
by Konstantinos
01:24
created

test_phi.test_phi_creation()   B

Complexity

Conditions 2

Size

Total Lines 52
Code Lines 41

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 41
dl 0
loc 52
rs 8.896
c 0
b 0
f 0
cc 2
nop 2

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
import pytest
2
3
@pytest.fixture
4
def registering_phi_at_the_same_key_error():
5
    from green_magic.utils.registry import ObjectRegistryError
6
    return ObjectRegistryError
7
8
9
@pytest.fixture
10
def app_phi_function(somagic):
11
    return somagic._data_manager.phi_class
12
13
14
def test_phi_creation(app_phi_function, registering_phi_at_the_same_key_error):
15
    from green_magic.data.features.phi import phi_registry
16
17
    assert phi_registry.objects == {}
18
    assert 'pame' not in phi_registry
19
20
    PhiFunction = app_phi_function
21
    @PhiFunction.register('pame')
22
    def ela(x):
23
        """ela Docstring"""
24
        return x + 1
25
26
    assert 'pame' in phi_registry
27
    assert ela.__name__ == 'ela'
28
    assert ela.__doc__ == 'ela Docstring'
29
30
    @PhiFunction.register('')
31
    def gg(x):
32
        return x * 2
33
    assert 'gg' in phi_registry
34
35
    @PhiFunction.register()
36
    def dd(x):
37
        return x * 2
38
    assert 'dd' in phi_registry
39
40
    @PhiFunction.register('edw')
41
    class Edw:
42
        def __call__(self, data, **kwargs):
43
            return data + 5
44
    assert 'edw' in phi_registry
45
    assert phi_registry.get('edw')(3) == 8
46
47
    @PhiFunction.register('')
48
    class qw:
49
        def __call__(self, data, **kwargs):
50
            return data - 5
51
    assert phi_registry.get('qw')(3) == -2
52
    assert 'qw' in phi_registry
53
54
    @PhiFunction.register()
55
    class Nai:
56
        def __call__(self, data, **kwargs):
57
            return data - 5
58
    assert 'Nai' in phi_registry
59
60
    with pytest.raises(registering_phi_at_the_same_key_error):
61
        @PhiFunction.register()
62
        def gg(x):
63
            return x
64
65
    assert phi_registry.get('gg')(1) == 2
66