Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 74c2bb0

Browse files
committed
Merge pull request plotly#462 from plotly/update-streaming-tests
Use `TestCase` in `test_stream.py` tests.
2 parents 9f7d44c + 3c7a623 commit 74c2bb0

File tree

1 file changed

+152
-161
lines changed

1 file changed

+152
-161
lines changed
Lines changed: 152 additions & 161 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
"""
2-
test_get_figure:
3-
=================
4-
5-
A module intended for use with Nose.
2+
Streaming tests.
63
74
"""
85
from __future__ import absolute_import
96

107
import time
8+
from unittest import TestCase
119

1210
from nose.plugins.attrib import attr
13-
from nose.tools import raises, eq_
1411

1512
import plotly.plotly as py
1613
from plotly.graph_objs import (Layout, Scatter, Stream)
@@ -24,162 +21,156 @@
2421
'plotly_api_domain': 'https://api.plot.ly'}
2522

2623

27-
def setUp():
28-
py.sign_in(un, ak, **config)
29-
30-
31-
@attr('slow')
32-
def test_initialize_stream_plot():
33-
py.sign_in(un, ak)
34-
stream = Stream(token=tk, maxpoints=50)
35-
url = py.plot([Scatter(x=[], y=[], mode='markers', stream=stream)],
36-
auto_open=False,
37-
world_readable=True,
38-
filename='stream-test')
39-
assert url == 'https://plot.ly/~PythonAPI/461'
40-
time.sleep(.5)
41-
42-
43-
@attr('slow')
44-
def test_stream_single_points():
45-
py.sign_in(un, ak)
46-
stream = Stream(token=tk, maxpoints=50)
47-
res = py.plot([Scatter(x=[], y=[], mode='markers', stream=stream)],
48-
auto_open=False,
49-
world_readable=True,
50-
filename='stream-test')
51-
time.sleep(.5)
52-
my_stream = py.Stream(tk)
53-
my_stream.open()
54-
my_stream.write(Scatter(x=1, y=10))
55-
time.sleep(.5)
56-
my_stream.close()
57-
58-
59-
@attr('slow')
60-
def test_stream_multiple_points():
61-
py.sign_in(un, ak)
62-
stream = Stream(token=tk, maxpoints=50)
63-
url = py.plot([Scatter(x=[], y=[], mode='markers', stream=stream)],
64-
auto_open=False,
65-
world_readable=True,
66-
filename='stream-test')
67-
time.sleep(.5)
68-
my_stream = py.Stream(tk)
69-
my_stream.open()
70-
my_stream.write(Scatter(x=[1, 2, 3, 4], y=[2, 1, 2, 5]))
71-
time.sleep(.5)
72-
my_stream.close()
73-
74-
75-
@attr('slow')
76-
def test_stream_layout():
77-
py.sign_in(un, ak)
78-
stream = Stream(token=tk, maxpoints=50)
79-
url = py.plot([Scatter(x=[], y=[], mode='markers', stream=stream)],
80-
auto_open=False,
81-
world_readable=True,
82-
filename='stream-test')
83-
time.sleep(.5)
84-
title_0 = "some title i picked first"
85-
title_1 = "this other title i picked second"
86-
my_stream = py.Stream(tk)
87-
my_stream.open()
88-
my_stream.write(Scatter(x=1, y=10), layout=Layout(title=title_0))
89-
time.sleep(.5)
90-
my_stream.close()
91-
my_stream.open()
92-
my_stream.write(Scatter(x=1, y=10), layout=Layout(title=title_1))
93-
my_stream.close()
94-
95-
96-
@attr('slow')
97-
@raises(exceptions.PlotlyError)
98-
def test_stream_validate_data():
99-
py.sign_in(un, ak)
100-
my_stream = py.Stream(tk)
101-
my_stream.open()
102-
my_stream.write(dict(x=1, y=10, z=[1])) # assumes scatter...
103-
my_stream.close()
104-
105-
106-
@attr('slow')
107-
@raises(exceptions.PlotlyError)
108-
def test_stream_validate_layout():
109-
py.sign_in(un, ak)
110-
my_stream = py.Stream(tk)
111-
my_stream.open()
112-
my_stream.write(Scatter(x=1, y=10), layout=Layout(legend=True))
113-
my_stream.close()
114-
115-
116-
@attr('slow')
117-
def test_stream_unstreamable():
118-
119-
# even though `name` isn't streamable, we don't validate it --> should pass
120-
121-
py.sign_in(un, ak)
122-
my_stream = py.Stream(tk)
123-
my_stream.open()
124-
my_stream.write(Scatter(x=1, y=10, name='nope'))
125-
my_stream.close()
126-
127-
128-
def test_stream_no_scheme():
129-
130-
# If no scheme is used in the plotly_streaming_domain, port 80
131-
# should be used for streaming and ssl_enabled should be False
132-
133-
py.sign_in(un, ak, **{'plotly_streaming_domain': 'stream.plot.ly'})
134-
my_stream = py.Stream(tk)
135-
expected_streaming_specs = {
136-
'server': 'stream.plot.ly',
137-
'port': 80,
138-
'ssl_enabled': False,
139-
'headers': {
140-
'Host': 'stream.plot.ly',
141-
'plotly-streamtoken': tk
24+
class TestStreaming(TestCase):
25+
26+
def setUp(self):
27+
py.sign_in(un, ak, **config)
28+
29+
@attr('slow')
30+
def test_initialize_stream_plot(self):
31+
py.sign_in(un, ak)
32+
stream = Stream(token=tk, maxpoints=50)
33+
url = py.plot([Scatter(x=[], y=[], mode='markers', stream=stream)],
34+
auto_open=False,
35+
world_readable=True,
36+
filename='stream-test')
37+
assert url == 'https://plot.ly/~PythonAPI/461'
38+
time.sleep(.5)
39+
40+
@attr('slow')
41+
def test_stream_single_points(self):
42+
py.sign_in(un, ak)
43+
stream = Stream(token=tk, maxpoints=50)
44+
res = py.plot([Scatter(x=[], y=[], mode='markers', stream=stream)],
45+
auto_open=False,
46+
world_readable=True,
47+
filename='stream-test')
48+
time.sleep(.5)
49+
my_stream = py.Stream(tk)
50+
my_stream.open()
51+
my_stream.write(Scatter(x=1, y=10))
52+
time.sleep(.5)
53+
my_stream.close()
54+
55+
@attr('slow')
56+
def test_stream_multiple_points(self):
57+
py.sign_in(un, ak)
58+
stream = Stream(token=tk, maxpoints=50)
59+
url = py.plot([Scatter(x=[], y=[], mode='markers', stream=stream)],
60+
auto_open=False,
61+
world_readable=True,
62+
filename='stream-test')
63+
time.sleep(.5)
64+
my_stream = py.Stream(tk)
65+
my_stream.open()
66+
my_stream.write(Scatter(x=[1, 2, 3, 4], y=[2, 1, 2, 5]))
67+
time.sleep(.5)
68+
my_stream.close()
69+
70+
@attr('slow')
71+
def test_stream_layout(self):
72+
py.sign_in(un, ak)
73+
stream = Stream(token=tk, maxpoints=50)
74+
url = py.plot([Scatter(x=[], y=[], mode='markers', stream=stream)],
75+
auto_open=False,
76+
world_readable=True,
77+
filename='stream-test')
78+
time.sleep(.5)
79+
title_0 = "some title i picked first"
80+
title_1 = "this other title i picked second"
81+
my_stream = py.Stream(tk)
82+
my_stream.open()
83+
my_stream.write(Scatter(x=1, y=10), layout=Layout(title=title_0))
84+
time.sleep(.5)
85+
my_stream.close()
86+
my_stream.open()
87+
my_stream.write(Scatter(x=1, y=10), layout=Layout(title=title_1))
88+
my_stream.close()
89+
90+
@attr('slow')
91+
def test_stream_validate_data(self):
92+
with self.assertRaises(exceptions.PlotlyError):
93+
py.sign_in(un, ak)
94+
my_stream = py.Stream(tk)
95+
my_stream.open()
96+
my_stream.write(dict(x=1, y=10, z=[1])) # assumes scatter...
97+
my_stream.close()
98+
99+
@attr('slow')
100+
def test_stream_validate_layout(self):
101+
with self.assertRaises(exceptions.PlotlyError):
102+
py.sign_in(un, ak)
103+
my_stream = py.Stream(tk)
104+
my_stream.open()
105+
my_stream.write(Scatter(x=1, y=10), layout=Layout(legend=True))
106+
my_stream.close()
107+
108+
@attr('slow')
109+
def test_stream_unstreamable(self):
110+
111+
# even though `name` isn't streamable, we don't validate it --> pass
112+
113+
py.sign_in(un, ak)
114+
my_stream = py.Stream(tk)
115+
my_stream.open()
116+
my_stream.write(Scatter(x=1, y=10, name='nope'))
117+
my_stream.close()
118+
119+
def test_stream_no_scheme(self):
120+
121+
# If no scheme is used in the plotly_streaming_domain, port 80
122+
# should be used for streaming and ssl_enabled should be False
123+
124+
py.sign_in(un, ak, **{'plotly_streaming_domain': 'stream.plot.ly'})
125+
my_stream = py.Stream(tk)
126+
expected_streaming_specs = {
127+
'server': 'stream.plot.ly',
128+
'port': 80,
129+
'ssl_enabled': False,
130+
'headers': {
131+
'Host': 'stream.plot.ly',
132+
'plotly-streamtoken': tk
133+
}
142134
}
143-
}
144-
actual_streaming_specs = my_stream.get_streaming_specs()
145-
eq_(expected_streaming_specs, actual_streaming_specs)
146-
147-
148-
def test_stream_http():
149-
150-
# If the http scheme is used in the plotly_streaming_domain, port 80
151-
# should be used for streaming and ssl_enabled should be False
152-
153-
py.sign_in(un, ak, **{'plotly_streaming_domain': 'http://stream.plot.ly'})
154-
my_stream = py.Stream(tk)
155-
expected_streaming_specs = {
156-
'server': 'stream.plot.ly',
157-
'port': 80,
158-
'ssl_enabled': False,
159-
'headers': {
160-
'Host': 'stream.plot.ly',
161-
'plotly-streamtoken': tk
135+
actual_streaming_specs = my_stream.get_streaming_specs()
136+
self.assertEqual(expected_streaming_specs, actual_streaming_specs)
137+
138+
def test_stream_http(self):
139+
140+
# If the http scheme is used in the plotly_streaming_domain, port 80
141+
# should be used for streaming and ssl_enabled should be False
142+
143+
py.sign_in(un, ak,
144+
**{'plotly_streaming_domain': 'http://stream.plot.ly'})
145+
my_stream = py.Stream(tk)
146+
expected_streaming_specs = {
147+
'server': 'stream.plot.ly',
148+
'port': 80,
149+
'ssl_enabled': False,
150+
'headers': {
151+
'Host': 'stream.plot.ly',
152+
'plotly-streamtoken': tk
153+
}
162154
}
163-
}
164-
actual_streaming_specs = my_stream.get_streaming_specs()
165-
eq_(expected_streaming_specs, actual_streaming_specs)
166-
167-
168-
def test_stream_https():
169-
170-
# If the https scheme is used in the plotly_streaming_domain, port 443
171-
# should be used for streaming and ssl_enabled should be True
172-
173-
py.sign_in(un, ak, **{'plotly_streaming_domain': 'https://stream.plot.ly'})
174-
my_stream = py.Stream(tk)
175-
expected_streaming_specs = {
176-
'server': 'stream.plot.ly',
177-
'port': 443,
178-
'ssl_enabled': True,
179-
'headers': {
180-
'Host': 'stream.plot.ly',
181-
'plotly-streamtoken': tk
155+
actual_streaming_specs = my_stream.get_streaming_specs()
156+
self.assertEqual(expected_streaming_specs, actual_streaming_specs)
157+
158+
def test_stream_https(self):
159+
160+
# If the https scheme is used in the plotly_streaming_domain, port 443
161+
# should be used for streaming and ssl_enabled should be True
162+
163+
py.sign_in(un, ak,
164+
**{'plotly_streaming_domain': 'https://stream.plot.ly'})
165+
my_stream = py.Stream(tk)
166+
expected_streaming_specs = {
167+
'server': 'stream.plot.ly',
168+
'port': 443,
169+
'ssl_enabled': True,
170+
'headers': {
171+
'Host': 'stream.plot.ly',
172+
'plotly-streamtoken': tk
173+
}
182174
}
183-
}
184-
actual_streaming_specs = my_stream.get_streaming_specs()
185-
eq_(expected_streaming_specs, actual_streaming_specs)
175+
actual_streaming_specs = my_stream.get_streaming_specs()
176+
self.assertEqual(expected_streaming_specs, actual_streaming_specs)

0 commit comments

Comments
 (0)