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.backend import BackendType |
12
|
|
|
assert type(BackendType) == type |
13
|
|
|
return BackendType |
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.backend import EngineBackend |
24
|
|
|
assert type(EngineBackend) == data_engine_type |
25
|
|
|
return EngineBackend |
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 ( |
32
|
|
|
'registry', |
33
|
|
|
'_commands', |
34
|
|
|
# 'command', |
35
|
|
|
) |
36
|
|
|
|
37
|
|
|
|
38
|
|
|
@pytest.fixture |
39
|
|
|
def engine_creation_assertions(engine_attributes, data_engine_class, data_engine_type): |
40
|
|
|
"""Execute the necessary assertion statements related to testing the creation of a new Data Engine.""" |
41
|
|
|
def make_assertions(engine_object, engine_name: str): |
42
|
|
|
"""Assert that the creation and initialization of a new engine was as expected. |
43
|
|
|
|
44
|
|
|
Args: |
45
|
|
|
engine_object (so_magic.data.backend.engine.EngineType): [description] |
46
|
|
|
engine_name (str): the engine name to reference it |
47
|
|
|
""" |
48
|
|
|
assert engine_object == getattr(data_engine_class, engine_name) |
49
|
|
|
assert engine_name in data_engine_class.subclasses |
50
|
|
|
assert type(getattr(data_engine_class, engine_name)) == data_engine_type |
51
|
|
|
assert all(hasattr(getattr(data_engine_class, engine_name), x) for x in engine_attributes) |
52
|
|
|
assert len(getattr(data_engine_class, engine_name).registry) == 0 |
53
|
|
|
return make_assertions |
54
|
|
|
|
55
|
|
|
|
56
|
|
|
@pytest.mark.parametrize('engine_specs', [ |
57
|
|
|
# Scenario 1 -> create 2 engines, with the below names |
58
|
|
|
(['engine1', |
59
|
|
|
'engine2']), |
60
|
|
|
]) |
61
|
|
|
def test_engine_registration(engine_specs, engine_creation_assertions, engine_attributes, data_engine_class): |
62
|
|
|
"""Test that new engines have their attributes correctly initialized""" |
63
|
|
|
for engine_data in engine_specs: |
64
|
|
|
data_engine = data_engine_class.new(engine_data) |
65
|
|
|
engine_creation_assertions(data_engine, engine_data) |
66
|
|
|
|
67
|
|
|
expected_distinct_ids = len(engine_specs) + 1 |
68
|
|
|
|
69
|
|
|
for engine_attribute in engine_attributes: |
70
|
|
|
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 |
71
|
|
|
|