1
+ """
2
+ test_get_figure:
3
+ =================
4
+
5
+ A module intended for use with Nose.
6
+
7
+ """
8
+ import time
9
+ from nose .tools import raises
10
+ from ... graph_objs import *
11
+ from ... plotly import plotly as py
12
+ from ... import exceptions
13
+
14
+ un = 'pythonapi'
15
+ ak = 'ubpiol2cve'
16
+ tk = 'vaia8trjjb'
17
+ fi = 461
18
+ py .sign_in (un , ak )
19
+
20
+ run_tests = False
21
+
22
+
23
+ def test_initialize_stream_plot ():
24
+ if run_tests :
25
+ stream = Stream (token = tk , maxpoints = 50 )
26
+ res = py .plot ([Scatter (x = [], y = [], mode = 'markers' , stream = stream )],
27
+ auto_open = False ,
28
+ filename = 'stream-test' )
29
+ assert res == u'https://plot.ly/~PythonAPI/461'
30
+ time .sleep (5 )
31
+
32
+
33
+ def test_stream_single_points ():
34
+ if run_tests :
35
+ stream = Stream (token = tk , maxpoints = 50 )
36
+ res = py .plot ([Scatter (x = [], y = [], mode = 'markers' , stream = stream )],
37
+ auto_open = False ,
38
+ filename = 'stream-test' )
39
+ time .sleep (5 )
40
+ my_stream = py .Stream (tk )
41
+ my_stream .open ()
42
+ my_stream .write (Scatter (x = 1 , y = 10 ))
43
+ time .sleep (1 )
44
+ my_stream .close ()
45
+ fig = py .get_figure (un , fi )
46
+ print fig .to_string ()
47
+ assert fig ['data' ][0 ]['x' ] == 1
48
+ assert fig ['data' ][0 ]['y' ] == 10
49
+
50
+
51
+ def test_stream_multiple_points ():
52
+ if run_tests :
53
+ stream = Stream (token = tk , maxpoints = 50 )
54
+ res = py .plot ([Scatter (x = [], y = [], mode = 'markers' , stream = stream )],
55
+ auto_open = False ,
56
+ filename = 'stream-test' )
57
+ time .sleep (5 )
58
+ my_stream = py .Stream (tk )
59
+ my_stream .open ()
60
+ my_stream .write (Scatter (x = [1 , 2 , 3 , 4 ], y = [2 , 1 , 2 , 5 ]))
61
+ time .sleep (1 )
62
+ my_stream .close ()
63
+ fig = py .get_figure (un , fi )
64
+ print fig .to_string ()
65
+ assert fig ['data' ][0 ]['x' ] == [1 , 2 , 3 , 4 ]
66
+ assert fig ['data' ][0 ]['y' ] == [2 , 1 , 2 , 5 ]
67
+
68
+
69
+ def test_stream_layout ():
70
+ if run_tests :
71
+ stream = Stream (token = tk , maxpoints = 50 )
72
+ res = py .plot ([Scatter (x = [], y = [], mode = 'markers' , stream = stream )],
73
+ auto_open = False ,
74
+ filename = 'stream-test' )
75
+ time .sleep (5 )
76
+ title_0 = "some title i picked first"
77
+ title_1 = "this other title i picked second"
78
+ my_stream = py .Stream (tk )
79
+ my_stream .open ()
80
+ my_stream .write (Scatter (x = 1 , y = 10 ), layout = Layout (title = title_0 ))
81
+ time .sleep (1 )
82
+ my_stream .close ()
83
+ fig = py .get_figure (un , fi )
84
+ print fig .to_string ()
85
+ assert fig ['layout' ]['title' ] == title_0
86
+ my_stream .open ()
87
+ my_stream .write (Scatter (x = 1 , y = 10 ), layout = Layout (title = title_1 ))
88
+ time .sleep (1 )
89
+ my_stream .close ()
90
+ fig = py .get_figure (un , fi )
91
+ print fig .to_string ()
92
+ assert fig ['layout' ]['title' ] == title_1
93
+
94
+
95
+ @raises (exceptions .PlotlyError )
96
+ def test_stream_validate_data ():
97
+ if run_tests :
98
+ my_stream = py .Stream (tk )
99
+ my_stream .open ()
100
+ my_stream .write (dict (x = 1 , y = 10 , z = [1 ])) # assumes scatter...
101
+ time .sleep (1 )
102
+ my_stream .close ()
103
+ else :
104
+ raise exceptions .PlotlyError ()
105
+
106
+
107
+ @raises (exceptions .PlotlyError )
108
+ def test_stream_validate_layout ():
109
+ if run_tests :
110
+ my_stream = py .Stream (tk )
111
+ my_stream .open ()
112
+ my_stream .write (Scatter (x = 1 , y = 10 ), layout = Layout (legend = True ))
113
+ time .sleep (1 )
114
+ my_stream .close ()
115
+ else :
116
+ raise exceptions .PlotlyError ()
0 commit comments