| Conditions | 2 |
| Total Lines | 52 |
| Code Lines | 41 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
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:
If many parameters/temporary variables are present:
| 1 | import pytest |
||
| 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 |