|
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
|
|
|
|