|
1
|
|
|
from graphinate.builders import Builder, build |
|
2
|
|
|
from graphinate.enums import GraphType |
|
3
|
|
|
from graphinate.modeling import GraphModel |
|
4
|
|
|
|
|
5
|
|
|
|
|
6
|
|
|
class MockBuilder(Builder): |
|
7
|
|
|
def build(self, **kwargs): |
|
8
|
|
|
return {"built": True, "kwargs": kwargs} |
|
9
|
|
|
|
|
10
|
|
|
|
|
11
|
|
|
def test_build_returns_graph_data_structure(): |
|
12
|
|
|
# Arrange |
|
13
|
|
|
graph_model = GraphModel(name="TestModel") |
|
14
|
|
|
graph_type = GraphType.Graph |
|
15
|
|
|
default_node_attributes = {"attribute": "value"} |
|
16
|
|
|
builder_cls = MockBuilder |
|
17
|
|
|
|
|
18
|
|
|
# Act |
|
19
|
|
|
result = build( |
|
20
|
|
|
builder_cls=builder_cls, |
|
21
|
|
|
graph_model=graph_model, |
|
22
|
|
|
graph_type=graph_type, |
|
23
|
|
|
default_node_attributes=default_node_attributes, |
|
24
|
|
|
custom_arg="custom_value" |
|
25
|
|
|
) |
|
26
|
|
|
|
|
27
|
|
|
# Assert |
|
28
|
|
|
assert result == { |
|
29
|
|
|
"built": True, |
|
30
|
|
|
"kwargs": { |
|
31
|
|
|
"default_node_attributes": {"attribute": "value"}, |
|
32
|
|
|
"custom_arg": "custom_value", |
|
33
|
|
|
}, |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
|
|
37
|
|
|
def test_build_invokes_builder_with_correct_arguments(mocker): |
|
38
|
|
|
# Arrange |
|
39
|
|
|
graph_model = GraphModel(name="TestModel") |
|
40
|
|
|
builder_cls = MockBuilder |
|
41
|
|
|
graph_type = GraphType.DiGraph |
|
42
|
|
|
|
|
43
|
|
|
mock_init = mocker.patch.object(MockBuilder, '__init__', return_value=None) |
|
44
|
|
|
mock_build = mocker.patch.object(MockBuilder, 'build', return_value={"mocked": True}) |
|
45
|
|
|
|
|
46
|
|
|
# Act |
|
47
|
|
|
build(builder_cls=builder_cls, graph_model=graph_model, graph_type=graph_type) |
|
48
|
|
|
|
|
49
|
|
|
# Assert |
|
50
|
|
|
mock_init.assert_called_once_with(graph_model, graph_type) |
|
51
|
|
|
mock_build.assert_called_once_with(default_node_attributes=None) |
|
52
|
|
|
|