forked from glaserL/viasp
-
Notifications
You must be signed in to change notification settings - Fork 1
/
test_clingraph.py
112 lines (95 loc) · 3.91 KB
/
test_clingraph.py
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
from flask import current_app
def test_clingraph_delete(client_with_a_clingraph):
client, _, _, _ = client_with_a_clingraph
res = client.delete("/control/clingraph")
assert res.status_code == 200
res = client.get("/control/clingraph")
assert res.status_code == 200
assert res.data == b'{"using_clingraph": false}'
def test_using_clingraph(client_with_a_clingraph):
prg = """
node(X):-a(X).
attr(node,a,color,blue) :- node(a), not b(a).
attr(node,a,color,red) :- node(a), b(a).
"""
client, _, _, program = client_with_a_clingraph
serialized = current_app.json.dumps({"viz-encoding":prg, "engine":"dot", "graphviz-type": "graph"})
res = client.post("/control/clingraph", data=serialized, headers={'Content-Type': 'application/json'})
assert res.status_code == 200
assert res.data == b'ok'
res = client.get("/control/clingraph")
assert res.status_code == 200
if "{b(X)}" in program:
assert res.data == b'{"using_clingraph": true}'
else:
assert res.data == b'{"using_clingraph": false}'
def test_clingraph_children(client_with_a_clingraph):
prg = """
node(X):-a(X).
attr(node,a,color,blue) :- node(a), not b(a).
attr(node,a,color,red) :- node(a), b(a).
"""
client, _, _, program = client_with_a_clingraph
serialized = current_app.json.dumps({"viz-encoding":prg, "engine":"dot", "graphviz-type": "graph"})
res = client.post("/control/clingraph", data=serialized, headers={'Content-Type': 'application/json'})
assert res.status_code == 200
assert res.data == b'ok'
res = client.get("/clingraph/children")
assert res.status_code == 200
clingraph_nodes = current_app.json.loads(res.data)
if "{b(X)}" in program:
# program_simple and program_multiple_sorts
assert len(clingraph_nodes) == 4
res = client.get(f"/graph/clingraph/{clingraph_nodes[0].uuid}")
assert res.status_code == 200
assert res.content_type == 'image/png'
else:
# program_recursive
assert len(clingraph_nodes) == 0
def test_clingraph_image(client_with_a_clingraph):
prg = """
node(X):-a(X).
attr(node,a,color,blue) :- node(a), not b(a).
attr(node,a,color,red) :- node(a), b(a).
"""
client, _, _, program = client_with_a_clingraph
serialized = current_app.json.dumps({"viz-encoding":prg, "engine":"dot", "graphviz-type": "graph"})
res = client.post("/control/clingraph", data=serialized, headers={'Content-Type': 'application/json'})
assert res.status_code == 200
assert res.data == b'ok'
res = client.get("/clingraph/children")
assert res.status_code == 200
clingraph_nodes = current_app.json.loads(res.data)
if "{b(X)}" in program:
res = client.get(f"/graph/clingraph/{clingraph_nodes[0].uuid}")
assert res.status_code == 200
assert res.content_type == 'image/png'
def test_clingraph_edges(client_with_a_clingraph):
prg = """
node(X):-a(X).
attr(node,a,color,blue) :- node(a), not b(a).
attr(node,a,color,red) :- node(a), b(a).
"""
client, _, _, program = client_with_a_clingraph
serialized = current_app.json.dumps({
"viz-encoding": prg,
"engine": "dot",
"graphviz-type": "graph"
})
res = client.post("/control/clingraph",
data=serialized,
headers={'Content-Type': 'application/json'})
assert res.status_code == 200
assert res.data == b'ok'
res = client.post(f"/graph/edges",
json={
"shownRecursion": [],
"usingClingraph": "true"
})
assert res.status_code == 200
assert type(res.json) == list
if "{b(X)}" in program:
# program_simple and program_multiple_sorts
assert len(res.json) == 12
else:
assert len(res.json) == 2