Skip to content

Commit 5258fa7

Browse files
committed
🔧 Cleanup test_plot.py.
1 parent 75c81df commit 5258fa7

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

plotly/tests/test_core/test_plotly/test_plot.py

+18-14
Original file line numberDiff line numberDiff line change
@@ -11,27 +11,23 @@
1111
import six
1212
from requests.compat import json as _json
1313

14-
from unittest import TestCase
1514
from mock import patch
1615
from nose.plugins.attrib import attr
17-
from nose.tools import raises
1816

1917
import plotly.tools as tls
18+
from plotly import session
2019
from plotly.tests.utils import PlotlyTestCase
2120
from plotly.plotly import plotly as py
2221
from plotly.exceptions import PlotlyError, PlotlyEmptyDataError
2322
from plotly.files import CONFIG_FILE
2423

25-
# username for tests: 'PlotlyImageTest'
26-
# api_key for account: '786r5mecv0'
2724

25+
class TestPlot(PlotlyTestCase):
2826

29-
class TestPlot(TestCase):
3027
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]}]}
3428
super(TestPlot, self).setUp()
29+
py.sign_in('PlotlyImageTest', '786r5mecv0')
30+
self.simple_figure = {'data': [{'x': [1, 2, 3], 'y': [2, 1, 2]}]}
3531

3632
@attr('slow')
3733
def test_plot_valid(self):
@@ -50,7 +46,6 @@ def test_plot_valid(self):
5046
self.assertEqual(saved_fig['data'][0]['y'], fig['data'][0]['y'])
5147
self.assertEqual(saved_fig['layout']['title'], fig['layout']['title'])
5248

53-
@raises(PlotlyError)
5449
def test_plot_invalid(self):
5550
fig = {
5651
'data': [
@@ -61,15 +56,18 @@ def test_plot_invalid(self):
6156
}
6257
]
6358
}
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')
6561

66-
@raises(TypeError)
6762
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')
6966

70-
@raises(PlotlyError)
7167
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')
7371

7472
def test_plot_empty_data(self):
7573
self.assertRaises(PlotlyEmptyDataError, py.plot, [],
@@ -237,6 +235,12 @@ def setUp(self):
237235
self.users_current_mock = patcher.start()
238236
self.addCleanup(patcher.stop)
239237

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+
240244
def test_default_options(self):
241245
options = py._plot_option_logic({})
242246
config_options = tls.get_config_file()

0 commit comments

Comments
 (0)