Passed
Push — dev ( 4bfa05...67478a )
by Konstantinos
01:31
created

test_data_manager.test_data_manager()   B

Complexity

Conditions 1

Size

Total Lines 75
Code Lines 52

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 52
dl 0
loc 75
rs 8.5709
c 0
b 0
f 0
cc 1
nop 1

How to fix   Long Method   

Long Method

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:

1
import pytest
2
from green_magic.data.commands_manager import CommandsManager
3
from green_magic.data.backend import Backend, DataEngine
4
from green_magic.data.data_manager import DataManager
5
from green_magic.data.backend import panda_handling
6
7
8
def test_engine_registration():
9
    from green_magic.data.backend import DataEngine
10
    from green_magic.data.backend.engine import EngineType
11
    assert type(DataEngine) == EngineType
12
    from green_magic.data.command_factories import CommandRegistrator
13
14
    # type(type(DataEngine))
15
    ATTRS = ('registry', '_commands', 'command')
16
    DataEngine.new('test_pd')
17
    assert 'test_pd' in DataEngine.subclasses
18
    assert type(DataEngine.test_pd) == type(DataEngine)
19
    assert all(hasattr(DataEngine.test_pd, x) for x in ATTRS)
20
21
    DataEngine.new('data_lib')
22
    assert 'data_lib' in DataEngine.subclasses
23
    assert type(DataEngine.data_lib) == type(DataEngine)
24
    assert all(hasattr(DataEngine.data_lib, x) for x in ATTRS)
25
26
    for x in ATTRS:
27
        print(getattr(DataEngine.test_pd, x), getattr(DataEngine.data_lib, x))
28
        assert id(getattr(DataEngine.test_pd, x)) != id(getattr(DataEngine.data_lib, x)) != id(DataEngine.registry)
29
30
    assert id(DataEngine.test_pd.datapoints_factory) == id(DataEngine.data_lib.datapoints_factory)
31
32
    assert len(DataEngine.test_pd.registry) == 0
33
    assert len(DataEngine.data_lib.registry) == 0
34
35
36
# def test_data_manager(test_json_data, data_manager, test_engine, datapoints):
37
#     import types
38
#     from green_magic.utils import Command
39
#     from green_magic.data.features.phi import PhiFunction
40
#     assert data_manager.backend.engine.__class__.datapoints_factory not in PhiFunction.subject._observers
41
#
42
#     assert len(datapoints) == test_json_data['nb_lines']
43
#     assert set(datapoints.attributes) == test_json_data['attributes']
44
#
45
#     @DataEngine.test_pd.dec()
46
#     def add_attribute(_datapoints, values, new_attribute):
47
#         _datapoints.observations[new_attribute] = values
48
#
49
#     assert type(DataEngine.test_pd) == type(DataEngine)
50
#     assert type(DataEngine.test_pd.registry) == dict
51
#     assert type(DataEngine.test_pd._commands) == dict
52
#     assert 'add_attribute' in DataEngine.test_pd.registry
53
#     assert 'add_attribute' in DataEngine.test_pd._commands
54
#     assert 'add_attribute' not in DataEngine.registry
55
#
56
#     assert type(DataEngine.test_pd._commands['add_attribute']) == Command
57
#
58
#     cmd = data_manager.command.add_attribute
59
#     assert type(cmd._receiver) == types.FunctionType
60
#     assert cmd._method == '__call__'
61
#     cmd.args = [datapoints, [_ for _ in range(1, len(datapoints) + 1)], 'test_attr']
62
#
63
#     from green_magic.utils.commands import Invoker, CommandHistory
64
#     inv = Invoker(CommandHistory())
65
#     inv.execute_command(cmd)
66
#
67
#     assert set(datapoints.attributes) == set(_ for _ in list(test_json_data['attributes']) + ['test_attr'])
68
#
69
#     @DataEngine.dec()
70
#     def list_to_encoded(_datapoints, values, new_attribute):
71
#         _datapoints.observations[new_attribute] = values
72
#
73
#     assert 'list_to_encoded' in DataEngine.registry
74
#     assert 'list_to_encoded' not in DataEngine.test_pd.registry
75