| Conditions | 1 |
| Total Lines | 52 |
| Code Lines | 37 |
| 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 | from green_magic.data.commands_manager import CommandsManager |
||
| 44 | def test_data_manager(sample_json): |
||
| 45 | import types |
||
| 46 | from green_magic.utils.commands import Command |
||
| 47 | from green_magic.data.backend.panda_handling.df_backend import PDTabularIterator, PDTabularRetriever |
||
| 48 | DataEngine.new('test_pd') |
||
| 49 | assert 'test_pd' in DataEngine.subclasses |
||
| 50 | assert hasattr(DataEngine, 'state') |
||
| 51 | assert hasattr(DataEngine, 'registry') |
||
| 52 | |||
| 53 | data_api = DataManager(CommandsManager(), Backend(DataEngine.create('test_pd'))) |
||
| 54 | # make the datapoint_manager listen to newly created Datapoints objects events |
||
| 55 | assert hasattr(data_api, 'commands_manager') |
||
| 56 | assert hasattr(data_api.commands_manager, 'command') |
||
| 57 | assert hasattr(data_api.backend, 'datapoints_manager') |
||
| 58 | |||
| 59 | data_api.backend.engine.__class__.datapoints_factory.subject.attach(data_api.backend.datapoints_manager) |
||
| 60 | DataEngine.test_pd.command_factory.attach(data_api.commands_manager.command.accumulator) |
||
| 61 | |||
| 62 | # test runtime command registration |
||
| 63 | import pandas as pd |
||
| 64 | @DataEngine.test_pd.dec() |
||
| 65 | def observations(file_path): |
||
| 66 | return pd.read_json(file_path, lines=True) |
||
| 67 | |||
| 68 | assert type(DataEngine.test_pd) == type(DataEngine) |
||
| 69 | assert type(DataEngine.test_pd.registry) == dict |
||
| 70 | assert type(DataEngine.test_pd._commands) == dict |
||
| 71 | assert 'observations' in DataEngine.test_pd.registry |
||
| 72 | assert 'observations' in DataEngine.test_pd._commands |
||
| 73 | assert 'observations' not in DataEngine.registry |
||
| 74 | |||
| 75 | assert type(DataEngine.test_pd._commands['observations']) == Command |
||
| 76 | |||
| 77 | cmd = DataEngine.test_pd._commands['observations'] |
||
| 78 | # cmd = data_api.command.observations |
||
| 79 | cmd.args = [sample_json] |
||
| 80 | |||
| 81 | assert type(cmd._receiver) == types.FunctionType |
||
| 82 | assert cmd._method == '__call__' |
||
| 83 | assert cmd.args == [sample_json] |
||
| 84 | |||
| 85 | from green_magic.utils.commands import Invoker, CommandHistory |
||
| 86 | |||
| 87 | DataEngine.test_pd.retriever = PDTabularRetriever() |
||
| 88 | DataEngine.test_pd.iterator = PDTabularIterator() |
||
| 89 | |||
| 90 | inv = Invoker(CommandHistory()) |
||
| 91 | inv.execute_command(cmd) |
||
| 92 | |||
| 93 | assert data_api.backend.datapoints_manager.datapoints |
||
| 94 | |||
| 95 | assert len(data_api.backend.datapoints_manager.datapoints) == 100 |