11
11
import six
12
12
from requests .compat import json as _json
13
13
14
- from unittest import TestCase
15
14
from mock import patch
16
15
from nose .plugins .attrib import attr
17
- from nose .tools import raises
18
16
19
17
import plotly .tools as tls
18
+ from plotly import session
20
19
from plotly .tests .utils import PlotlyTestCase
21
20
from plotly .plotly import plotly as py
22
21
from plotly .exceptions import PlotlyError , PlotlyEmptyDataError
23
22
from plotly .files import CONFIG_FILE
24
23
25
- # username for tests: 'PlotlyImageTest'
26
- # api_key for account: '786r5mecv0'
27
24
25
+ class TestPlot (PlotlyTestCase ):
28
26
29
- class TestPlot (TestCase ):
30
27
def setUp (self ):
31
- py .sign_in ('PlotlyImageTest' , '786r5mecv0' ,
32
- plotly_domain = 'https://plot.ly' )
33
- self .simple_figure = {'data' : [{'x' : [1 , 2 , 3 ], 'y' : [2 , 1 , 2 ]}]}
34
28
super (TestPlot , self ).setUp ()
29
+ py .sign_in ('PlotlyImageTest' , '786r5mecv0' )
30
+ self .simple_figure = {'data' : [{'x' : [1 , 2 , 3 ], 'y' : [2 , 1 , 2 ]}]}
35
31
36
32
@attr ('slow' )
37
33
def test_plot_valid (self ):
@@ -50,7 +46,6 @@ def test_plot_valid(self):
50
46
self .assertEqual (saved_fig ['data' ][0 ]['y' ], fig ['data' ][0 ]['y' ])
51
47
self .assertEqual (saved_fig ['layout' ]['title' ], fig ['layout' ]['title' ])
52
48
53
- @raises (PlotlyError )
54
49
def test_plot_invalid (self ):
55
50
fig = {
56
51
'data' : [
@@ -61,15 +56,18 @@ def test_plot_invalid(self):
61
56
}
62
57
]
63
58
}
64
- py .plot (fig , auto_open = False , filename = 'plot_invalid' )
59
+ with self .assertRaises (PlotlyError ):
60
+ py .plot (fig , auto_open = False , filename = 'plot_invalid' )
65
61
66
- @raises (TypeError )
67
62
def test_plot_invalid_args_1 (self ):
68
- py .plot (x = [1 , 2 , 3 ], y = [2 , 1 , 2 ], auto_open = False , filename = 'plot_invalid' )
63
+ with self .assertRaises (TypeError ):
64
+ py .plot (x = [1 , 2 , 3 ], y = [2 , 1 , 2 ], auto_open = False ,
65
+ filename = 'plot_invalid' )
69
66
70
- @raises (PlotlyError )
71
67
def test_plot_invalid_args_2 (self ):
72
- py .plot ([1 , 2 , 3 ], [2 , 1 , 2 ], auto_open = False , filename = 'plot_invalid' )
68
+ with self .assertRaises (PlotlyError ):
69
+ py .plot ([1 , 2 , 3 ], [2 , 1 , 2 ], auto_open = False ,
70
+ filename = 'plot_invalid' )
73
71
74
72
def test_plot_empty_data (self ):
75
73
self .assertRaises (PlotlyEmptyDataError , py .plot , [],
@@ -237,6 +235,12 @@ def setUp(self):
237
235
self .users_current_mock = patcher .start ()
238
236
self .addCleanup (patcher .stop )
239
237
238
+ # Some tests specifically check how *file-level* plot options alter
239
+ # plot option logic. In order not to re-write that, we simply clear the
240
+ # *session* information since it would take precedent. The _session is
241
+ # set when you `sign_in`.
242
+ session ._session ['plot_options' ].clear ()
243
+
240
244
def test_default_options (self ):
241
245
options = py ._plot_option_logic ({})
242
246
config_options = tls .get_config_file ()
0 commit comments