|
1
|
|
|
import pytest |
|
2
|
|
|
|
|
3
|
|
|
|
|
4
|
|
|
@pytest.fixture |
|
5
|
|
|
def data_engine_type(): |
|
6
|
|
|
"""Our EngineType metaclass that helps devs define different data engines (ie pandas). |
|
7
|
|
|
|
|
8
|
|
|
Returns: |
|
9
|
|
|
type: the EngineType metaclass |
|
10
|
|
|
""" |
|
11
|
|
|
from so_magic.data.backend.engine import EngineType |
|
12
|
|
|
assert type(EngineType) == type |
|
13
|
|
|
return EngineType |
|
14
|
|
|
|
|
15
|
|
|
|
|
16
|
|
|
@pytest.fixture |
|
17
|
|
|
def data_engine_class(data_engine_type): |
|
18
|
|
|
"""Our DataEngine class that helps devs create different data engines (ie pandas). |
|
19
|
|
|
|
|
20
|
|
|
Returns: |
|
21
|
|
|
EngineType: the DataEngine class |
|
22
|
|
|
""" |
|
23
|
|
|
from so_magic.data.backend import DataEngine |
|
24
|
|
|
assert type(DataEngine) == data_engine_type |
|
25
|
|
|
return DataEngine |
|
26
|
|
|
|
|
27
|
|
|
|
|
28
|
|
|
@pytest.fixture |
|
29
|
|
|
def engine_attributes(): |
|
30
|
|
|
"""The important attributes that each data engine (eg pandas engine) is expected to have upon creation.""" |
|
31
|
|
|
return 'registry', '_commands', 'command' |
|
32
|
|
|
|
|
33
|
|
|
|
|
34
|
|
|
@pytest.fixture |
|
35
|
|
|
def engine_creation_assertions(engine_attributes, data_engine_class, data_engine_type): |
|
36
|
|
|
"""Execute the necessary assertion statements related to testing the creation of a new Data Engine.""" |
|
37
|
|
|
def make_assertions(engine_object, engine_name: str): |
|
38
|
|
|
"""Assert that the creation and initialization of a new engine was as expected. |
|
39
|
|
|
|
|
40
|
|
|
Args: |
|
41
|
|
|
engine_object (so_magic.data.backend.engine.EngineType): [description] |
|
42
|
|
|
engine_name (str): the engine name to reference it |
|
43
|
|
|
""" |
|
44
|
|
|
assert engine_object == getattr(data_engine_class, engine_name) |
|
45
|
|
|
assert engine_name in data_engine_class.subclasses |
|
46
|
|
|
assert type(getattr(data_engine_class, engine_name)) == data_engine_type |
|
47
|
|
|
assert all(hasattr(getattr(data_engine_class, engine_name), x) for x in engine_attributes) |
|
48
|
|
|
assert len(getattr(data_engine_class, engine_name).registry) == 0 |
|
49
|
|
|
return make_assertions |
|
50
|
|
|
|
|
51
|
|
|
|
|
52
|
|
|
@pytest.mark.parametrize('engine_specs', [ |
|
53
|
|
|
# Scenario 1 -> create 2 engines, given the below data |
|
54
|
|
|
(['engine1', |
|
55
|
|
|
'engine2']), |
|
56
|
|
|
]) |
|
57
|
|
|
def test_engine_registration(engine_specs, engine_creation_assertions, engine_attributes, data_engine_class): |
|
58
|
|
|
"""Test that new engines have their attributes correctly initialized""" |
|
59
|
|
|
for engine_data in engine_specs: |
|
60
|
|
|
data_engine = data_engine_class.new(engine_data) |
|
61
|
|
|
engine_creation_assertions(data_engine, engine_data) |
|
62
|
|
|
|
|
63
|
|
|
expected_distinct_ids = len(engine_specs) + 1 |
|
64
|
|
|
|
|
65
|
|
|
for engine_attribute in engine_attributes: |
|
66
|
|
|
assert len(set([id(getattr(getattr(data_engine_class, engine_name), engine_attribute)) for engine_name in engine_specs] + [id(data_engine_class.registry)])) == expected_distinct_ids |
|
67
|
|
|
|