/
test_flow_visualization.py
52 lines (39 loc) · 2.22 KB
/
test_flow_visualization.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
import os
import numpy as np
from PIL import Image
from jina.flow import Flow
def test_visualization_with_yml_file_img(tmpdir):
cur_dir = os.path.dirname(os.path.abspath(__file__))
tmpfile = os.path.join(tmpdir, 'flow_test.jpg')
flow = Flow.load_config(os.path.join(cur_dir, '../yaml/test_flow_visualization.yml')).plot(output=tmpfile)
with Image.open(os.path.join(cur_dir, 'flow_test.jpg')) as flow_original:
with Image.open(tmpfile) as flow_created:
assert flow_original.size == flow_created.size
np.testing.assert_array_almost_equal(flow_original, flow_created)
def test_visualization_plot_in_middle(tmpdir):
cur_dir = os.path.dirname(os.path.abspath(__file__))
tmpfile = os.path.join(tmpdir, 'flow_test_middle.jpg')
flow = (Flow().add(name='pod_a')
.plot(output=tmpfile)
.add(name='pod_b', needs='gateway')
.join(needs=['pod_a', 'pod_b']))
with Image.open(os.path.join(cur_dir, 'flow_original_middle.jpg')) as flow_original:
with Image.open(tmpfile) as flow_created:
assert flow_original.size == flow_created.size
np.testing.assert_array_almost_equal(flow_original, flow_created)
def test_visualization_plot_twice(tmpdir):
cur_dir = os.path.dirname(os.path.abspath(__file__))
tmpfile_middle = os.path.join(tmpdir, 'flow_test_middle.jpg')
tmpfile_end = os.path.join(tmpdir, 'flow_test_end.jpg')
flow = (Flow().add(name='pod_a')
.plot(output=tmpfile_middle)
.add(name='pod_b', needs='gateway')
.join(needs=['pod_a', 'pod_b']).plot(output=tmpfile_end))
with Image.open(os.path.join(cur_dir, 'flow_original_middle.jpg')) as flow_original_middle:
with Image.open(tmpfile_middle) as flow_created_middle:
assert flow_original_middle.size == flow_created_middle.size
np.testing.assert_array_almost_equal(flow_original_middle, flow_created_middle)
with Image.open(os.path.join(cur_dir, 'flow_original_end.jpg')) as flow_original_end:
with Image.open(tmpfile_end) as flow_created_end:
assert flow_original_end.size == flow_created_end.size
np.testing.assert_array_almost_equal(flow_original_end, flow_created_end)