forked from plotly/plotly.py
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_stream.py
More file actions
116 lines (100 loc) · 3.35 KB
/
test_stream.py
File metadata and controls
116 lines (100 loc) · 3.35 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
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
113
114
115
116
"""
test_get_figure:
=================
A module intended for use with Nose.
"""
import time
from nose.tools import raises
from ... graph_objs import *
from ... plotly import plotly as py
from ... import exceptions
un = 'pythonapi'
ak = 'ubpiol2cve'
tk = 'vaia8trjjb'
fi = 461
py.sign_in(un, ak)
run_tests = False
def test_initialize_stream_plot():
if run_tests:
stream = Stream(token=tk, maxpoints=50)
res = py.plot([Scatter(x=[], y=[], mode='markers', stream=stream)],
auto_open=False,
filename='stream-test')
assert res == u'https://plot.ly/~PythonAPI/461'
time.sleep(5)
def test_stream_single_points():
if run_tests:
stream = Stream(token=tk, maxpoints=50)
res = py.plot([Scatter(x=[], y=[], mode='markers', stream=stream)],
auto_open=False,
filename='stream-test')
time.sleep(5)
my_stream = py.Stream(tk)
my_stream.open()
my_stream.write(Scatter(x=1, y=10))
time.sleep(1)
my_stream.close()
fig = py.get_figure(un, fi)
print fig.to_string()
assert fig['data'][0]['x'] == 1
assert fig['data'][0]['y'] == 10
def test_stream_multiple_points():
if run_tests:
stream = Stream(token=tk, maxpoints=50)
res = py.plot([Scatter(x=[], y=[], mode='markers', stream=stream)],
auto_open=False,
filename='stream-test')
time.sleep(5)
my_stream = py.Stream(tk)
my_stream.open()
my_stream.write(Scatter(x=[1, 2, 3, 4], y=[2, 1, 2, 5]))
time.sleep(1)
my_stream.close()
fig = py.get_figure(un, fi)
print fig.to_string()
assert fig['data'][0]['x'] == [1, 2, 3, 4]
assert fig['data'][0]['y'] == [2, 1, 2, 5]
def test_stream_layout():
if run_tests:
stream = Stream(token=tk, maxpoints=50)
res = py.plot([Scatter(x=[], y=[], mode='markers', stream=stream)],
auto_open=False,
filename='stream-test')
time.sleep(5)
title_0 = "some title i picked first"
title_1 = "this other title i picked second"
my_stream = py.Stream(tk)
my_stream.open()
my_stream.write(Scatter(x=1, y=10), layout=Layout(title=title_0))
time.sleep(1)
my_stream.close()
fig = py.get_figure(un, fi)
print fig.to_string()
assert fig['layout']['title'] == title_0
my_stream.open()
my_stream.write(Scatter(x=1, y=10), layout=Layout(title=title_1))
time.sleep(1)
my_stream.close()
fig = py.get_figure(un, fi)
print fig.to_string()
assert fig['layout']['title'] == title_1
@raises(exceptions.PlotlyError)
def test_stream_validate_data():
if run_tests:
my_stream = py.Stream(tk)
my_stream.open()
my_stream.write(dict(x=1, y=10, z=[1])) # assumes scatter...
time.sleep(1)
my_stream.close()
else:
raise exceptions.PlotlyError()
@raises(exceptions.PlotlyError)
def test_stream_validate_layout():
if run_tests:
my_stream = py.Stream(tk)
my_stream.open()
my_stream.write(Scatter(x=1, y=10), layout=Layout(legend=True))
time.sleep(1)
my_stream.close()
else:
raise exceptions.PlotlyError()