Passed
Push — main ( 162760...d261f2 )
by Eran
01:41
created

test_d3   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 35
dl 0
loc 71
rs 10
c 0
b 0
f 0

4 Functions

Rating   Name   Duplication   Size   Complexity  
A test_d3_builder__map_graph_model() 0 17 1
A test_d3_builder_json_format() 0 11 1
A test_d3_builder__map_graph_model__both_specific_ids() 0 15 1
A test_d3_builder_invalid_format() 0 8 2
1
import pytest
2
3
import graphinate.builders
4
5
6
@pytest.mark.parametrize('execution_number', range(5))
7
def test_d3_builder__map_graph_model(execution_number, map_graph_model):
8
    # arrange
9
    country_count, city_count, graph_model = map_graph_model
10
    person_count = city_count
11
12
    # act
13
    builder = graphinate.builders.D3Builder(graph_model)
14
    actual_graph = builder.build()
15
16
    # assert
17
    assert actual_graph['directed'] is False
18
    assert actual_graph['multigraph'] is False
19
    assert actual_graph['graph']['name'] == 'Map'
20
    assert actual_graph['graph']['node_types']['country'] == country_count
21
    assert actual_graph['graph']['node_types']['city'] == city_count
22
    assert len(actual_graph['nodes']) == country_count + city_count + person_count
23
24
25
def test_d3_builder__map_graph_model__both_specific_ids(map_graph_model):
26
    # arrange
27
    _, _, graph_model = map_graph_model
28
29
    # act
30
    builder = graphinate.builders.D3Builder(graph_model)
31
    actual_graph = builder.build(country_id="1", city_id="1")
32
33
    # assert
34
    assert actual_graph['directed'] is False
35
    assert actual_graph['multigraph'] is False
36
    assert actual_graph['graph']['name'] == 'Map'
37
    assert actual_graph['graph']['node_types'].get('city', 0) in (0, 1)
38
    assert actual_graph['graph']['node_types']['country'] == 1
39
    assert len(actual_graph['nodes']) in (1, 3)
40
41
42
def test_d3_builder_json_format(map_graph_model):
43
    # arrange
44
    _, _, graph_model = map_graph_model
45
    builder = graphinate.builders.D3Builder(graph_model)
46
47
    # act
48
    actual_graph = builder.build(values_format='json')
49
50
    # assert
51
52
    assert actual_graph
53
54
    #assert dates where converted to iso
55
56
    # for node in actual_graph['nodes']:
57
    #     if node.get('value'):
58
    #         for v in node['value']:
59
    #             assert isinstance(v, str)
60
    #             json.loads(v)  # Check if it's a valid JSON string
61
62
63
def test_d3_builder_invalid_format(map_graph_model):
64
    # arrange
65
    _, _, graph_model = map_graph_model
66
    builder = graphinate.builders.D3Builder(graph_model)
67
68
    # act & assert
69
    with pytest.raises(ValueError, match="Invalid values format: invalid_format"):
70
        builder.build(values_format='invalid_format')
71