forked from pyecharts/pyecharts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_graph.py
More file actions
72 lines (62 loc) · 2.33 KB
/
test_graph.py
File metadata and controls
72 lines (62 loc) · 2.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
from unittest.mock import patch
from nose.tools import assert_equal, assert_in
from pyecharts import options as opts
from pyecharts.charts import Graph
@patch("pyecharts.render.engine.write_utf8_html_file")
def test_graph_base(fake_writer):
nodes = [
{"name": "结点1", "symbolSize": 10},
{"name": "结点2", "symbolSize": 20},
{"name": "结点3", "symbolSize": 30},
{"name": "结点4", "symbolSize": 40},
]
links = []
for i in nodes:
for j in nodes:
links.append({"source": i.get("name"), "target": j.get("name")})
c = Graph().add("", nodes, links, repulsion=8000)
c.render()
_, content = fake_writer.call_args[0]
assert_equal(c.theme, "white")
assert_equal(c.renderer, "canvas")
@patch("pyecharts.render.engine.write_utf8_html_file")
def test_graph_draggable_and_symbol_size(fake_writer):
nodes = [
{"name": "结点1", "symbolSize": 10},
{"name": "结点2", "symbolSize": 20},
{"name": "结点3", "symbolSize": 30},
{"name": "结点4", "symbolSize": 40},
]
links = []
for i in nodes:
for j in nodes:
links.append({"source": i.get("name"), "target": j.get("name")})
c = Graph().add("", nodes, links, repulsion=8000, is_draggable=True, symbol_size=50)
c.render()
_, content = fake_writer.call_args[0]
assert_in("draggable", content)
assert_in("symbolSize", content)
@patch("pyecharts.render.engine.write_utf8_html_file")
def test_graph_edge_label_opts(fake_writer):
nodes = [
{"name": "结点1", "symbolSize": 10},
{"name": "结点2", "symbolSize": 20},
{"name": "结点3", "symbolSize": 30},
{"name": "结点4", "symbolSize": 40},
]
links = []
for i in nodes:
for j in nodes:
links.append({"source": i.get("name"), "target": j.get("name")})
c = Graph().add(
"", nodes, links, repulsion=4000, edge_label=opts.LabelOpts(is_show=True)
)
c.render()
_, content = fake_writer.call_args[0]
assert_in("edgeLabel", content)
def test_graph_item():
node_name, link_source = "test_node_name", "test_link_source"
node = opts.GraphNode(name=node_name)
link = opts.GraphLink(source=link_source)
assert_equal(node_name, node.opts.get("name"))
assert_equal(link_source, link.opts.get("source"))