Passed
Pull Request — dev (#32)
by Konstantinos
03:59 queued 02:15
created

test_delegate   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 78
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 47
dl 0
loc 78
rs 10
c 0
b 0
f 0
wmc 4

3 Functions

Rating   Name   Duplication   Size   Complexity  
A engine_backends() 0 11 1
A client_pandas_tabular_implementation() 0 51 1
A test_delegate_sanity_check() 0 8 2
1
import pytest
2
3
4
@pytest.fixture
5
def client_pandas_tabular_implementation():
6
    from so_magic.data.interfaces import TabularRetriever, TabularIterator, TabularMutator
7
    
8
    class TestPDTabularRetrieverDelegate(TabularRetriever):
9
        """The observation object is the same as the one you return from 'from_json_lines'"""
10
11
        @classmethod
12
        def column(cls, identifier, data): pass
13
14
        def row(self, identifier, data): pass
15
16
        @classmethod
17
        def nb_columns(cls, data): pass
18
19
        @classmethod
20
        def nb_rows(cls, data): pass
21
22
        @classmethod
23
        def get_numerical_attributes(cls, data): pass
24
25
26
    class TestPDTabularIteratorDelegate(TabularIterator):
27
        """The observation object is the same as the one your return from 'from_json_lines'"""
28
29
        def columnnames(self, data): pass
30
31
        @classmethod
32
        def iterrows(cls, data): pass
33
34
        @classmethod
35
        def itercolumns(cls, data): pass
36
37
38
    class TestPDTabularMutatorDelegate(TabularMutator):
39
40
        @classmethod
41
        def add_column(cls, datapoints, values, new_attribute, **kwargs): pass
42
43
44
    BACKEND = {
45
        'backend_id': 'test-pd',
46
        'backend_name': 'test-pandas',
47
        'interfaces': [
48
            TestPDTabularRetrieverDelegate,
49
            TestPDTabularIteratorDelegate,
50
            TestPDTabularMutatorDelegate,
51
        ]
52
    }
53
54
    return BACKEND
55
56
57
@pytest.fixture
58
def engine_backends(client_pandas_tabular_implementation):
59
    CLIENT_BACKENDS = [
60
        client_pandas_tabular_implementation,
61
    ]
62
    from so_magic.data.backend.panda_handling.df_backend import magic_backends
63
64
    backends = magic_backends()
65
66
    backends.add(*CLIENT_BACKENDS)
67
    return backends
68
69
70
def test_delegate_sanity_check(engine_backends, data_manager):
71
    dt_manager = data_manager()
72
    # assert that the data engine initial (default) backend is "pandas-backend"
73
    # could need to change in the future if we give the client the option to initialize the engine with a backend of their preference
74
    assert dt_manager.engine.backend.id == 'pd'
75
    for backend_id, _backend_implementation in engine_backends:
76
        dt_manager.engine.backend = engine_backends.backends[backend_id]
77
        assert dt_manager.engine.backend.id == backend_id
78