| Conditions | 5 |
| Total Lines | 54 |
| Code Lines | 39 |
| 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 |
||
| 25 | def test_tabular_interfaces(tabular_interfaces, tabular_operators): |
||
| 26 | expected_contract = { |
||
| 27 | 'retriever': ['column', 'row', 'nb_columns', 'nb_rows', 'get_numerical_attributes'], |
||
| 28 | 'iterator': ['columnnames', 'itercolumns', 'iterrows'], |
||
| 29 | } |
||
| 30 | |||
| 31 | retr_members = ['column', 'row', 'nb_columns', 'nb_rows', 'get_numerical_attributes'] |
||
| 32 | |||
| 33 | |||
| 34 | |||
| 35 | pd_tabular_retriever1 = tabular_operators['retriever']() |
||
| 36 | pd_tabular_retriever2 = tabular_operators['retriever']() |
||
| 37 | |||
| 38 | member1 = list(x[0] for x in inspect.getmembers(pd_tabular_retriever1)) |
||
| 39 | member2 = list(x[0] for x in inspect.getmembers(pd_tabular_retriever2)) |
||
| 40 | |||
| 41 | for exp_member in retr_members: |
||
| 42 | assert exp_member in member1 |
||
| 43 | assert exp_member in member2 |
||
| 44 | |||
| 45 | class A: |
||
| 46 | def go(self, x): |
||
| 47 | return x + 1 |
||
| 48 | @staticmethod |
||
| 49 | def ela(y): |
||
| 50 | return y - 1 |
||
| 51 | @classmethod |
||
| 52 | def pame(cls, z): |
||
| 53 | return z * 2 |
||
| 54 | |||
| 55 | a = A() |
||
| 56 | |||
| 57 | go_sig = inspect.signature(a.go) |
||
| 58 | ela_sig = inspect.signature(a.ela) |
||
| 59 | pame_sig = inspect.signature(a.pame) |
||
| 60 | |||
| 61 | assert str(go_sig) == '(x)' |
||
| 62 | assert str(ela_sig) == '(y)' |
||
| 63 | assert str(pame_sig) == '(z)' |
||
| 64 | |||
| 65 | for method in retr_members[:2]: |
||
| 66 | sig = inspect.signature(getattr(pd_tabular_retriever1, method)) |
||
| 67 | assert str(sig) == '(identifier, data)' |
||
| 68 | |||
| 69 | for method in retr_members[2:]: |
||
| 70 | sig = inspect.signature(getattr(pd_tabular_retriever1, method)) |
||
| 71 | assert str(sig) == '(data)' |
||
| 72 | |||
| 73 | assert id(pd_tabular_retriever1._delegate) != id(pd_tabular_retriever2._delegate) |
||
| 74 | |||
| 75 | for function in expected_contract['retriever']: |
||
| 76 | assert function in dir(pd_tabular_retriever1) |
||
| 77 | assert id(getattr(pd_tabular_retriever1, function)) != id(getattr(pd_tabular_retriever2, function)) |
||
| 78 | assert id(getattr(pd_tabular_retriever1._delegate, function)) != id(getattr(pd_tabular_retriever2._delegate, function)) |
||
| 79 | |||
| 87 | # assert id(getattr(pd_tabular_iterator1._delegate, f)) != id(getattr(pd_tabular_iterator2._delegate, f)) |