| Total Complexity | 2 |
| Total Lines | 51 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | import pytest |
||
| 2 | from green_magic.data.features.phi import PhiFunction |
||
| 3 | |||
| 4 | |||
| 5 | def test_phi_creation(): |
||
| 6 | from green_magic.data.features.phi import phi_registry |
||
| 7 | assert phi_registry.objects == {} |
||
| 8 | @PhiFunction.register('aa') |
||
| 9 | def ela(x): |
||
| 10 | """ela Docstring""" |
||
| 11 | return x + 1 |
||
| 12 | |||
| 13 | assert 'aa' in phi_registry |
||
| 14 | assert ela.__name__ == 'ela' |
||
| 15 | assert ela.__doc__ == 'ela Docstring' |
||
| 16 | |||
| 17 | @PhiFunction.register('') |
||
| 18 | def gg(x): |
||
| 19 | return x * 2 |
||
| 20 | assert 'gg' in phi_registry |
||
| 21 | |||
| 22 | @PhiFunction.register() |
||
| 23 | def dd(x): |
||
| 24 | return x * 2 |
||
| 25 | assert 'dd' in phi_registry |
||
| 26 | |||
| 27 | @PhiFunction.register('edw') |
||
| 28 | class Edw: |
||
| 29 | def __call__(self, data, **kwargs): |
||
| 30 | return data + 5 |
||
| 31 | assert 'edw' in phi_registry |
||
| 32 | assert phi_registry.get('edw')(3) == 8 |
||
| 33 | @PhiFunction.register('') |
||
| 34 | class qw: |
||
| 35 | def __call__(self, data, **kwargs): |
||
| 36 | return data - 5 |
||
| 37 | assert phi_registry.get('qw')(3) == -2 |
||
| 38 | assert 'qw' in phi_registry |
||
| 39 | @PhiFunction.register() |
||
| 40 | class Nai: |
||
| 41 | def __call__(self, data, **kwargs): |
||
| 42 | return data - 5 |
||
| 43 | assert 'Nai' in phi_registry |
||
| 44 | from green_magic.utils import ObjectRegistryError |
||
| 45 | with pytest.raises(ObjectRegistryError): |
||
| 46 | @PhiFunction.register() |
||
| 47 | def gg(x): |
||
| 48 | return x |
||
| 49 | |||
| 50 | assert phi_registry.get('gg')(1) == 2 |
||
| 51 |