Skip to content

Commit 00ace72

Browse files
committed
replace nose with pytest
1 parent 39a539d commit 00ace72

File tree

37 files changed

+147
-197
lines changed

37 files changed

+147
-197
lines changed

packages/python/chart-studio/chart_studio/tests/test_core/test_tools/test_get_embed.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from unittest import TestCase
44

5-
from nose.tools import raises
5+
import pytest
66

77
import chart_studio.tools as tls
88
from _plotly_utils.exceptions import PlotlyError
@@ -13,10 +13,10 @@ def test_get_valid_embed():
1313
tls.get_embed(url)
1414

1515

16-
@raises(PlotlyError)
1716
def test_get_invalid_embed():
1817
url = "https://plot.ly/~PlotBot/a/"
19-
tls.get_embed(url)
18+
with pytest.raises(PlotlyError):
19+
tls.get_embed(url)
2020

2121

2222
class TestGetEmbed(TestCase):

packages/python/chart-studio/chart_studio/tests/test_optional/test_matplotlylib/test_plot_mpl.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,40 +7,37 @@
77
"""
88
from __future__ import absolute_import
99

10-
from nose.plugins.attrib import attr
11-
from nose.tools import raises
1210

1311
import _plotly_utils.exceptions
1412
from plotly import optional_imports
1513
from chart_studio.plotly import plotly as py
1614
from unittest import TestCase
15+
import pytest
1716

1817
matplotlylib = optional_imports.get_module("plotly.matplotlylib")
1918

2019
if matplotlylib:
2120
import matplotlib.pyplot as plt
2221

2322

24-
@attr("matplotlib")
2523
class PlotMPLTest(TestCase):
2624
def setUp(self):
2725
py.sign_in("PlotlyImageTest", "786r5mecv0", plotly_domain="https://plot.ly")
2826

29-
@raises(_plotly_utils.exceptions.PlotlyGraphObjectError)
3027
def test_update_type_error(self):
3128
fig, ax = plt.subplots()
3229
ax.plot([1, 2, 3])
3330
update = []
34-
py.plot_mpl(fig, update=update, filename="nosetests", auto_open=False)
31+
with pytest.raises(_plotly_utils.exceptions.PlotlyGraphObjectError):
32+
py.plot_mpl(fig, update=update, filename="nosetests", auto_open=False)
3533

36-
@raises(KeyError)
3734
def test_update_validation_error(self):
3835
fig, ax = plt.subplots()
3936
ax.plot([1, 2, 3])
4037
update = {"invalid": "anything"}
41-
py.plot_mpl(fig, update=update, filename="nosetests", auto_open=False)
38+
with pytest.raises(KeyError):
39+
py.plot_mpl(fig, update=update, filename="nosetests", auto_open=False)
4240

43-
@attr("slow")
4441
def test_update(self):
4542
fig, ax = plt.subplots()
4643
ax.plot([1, 2, 3])

packages/python/chart-studio/chart_studio/tests/test_plot_ly/test_file/test_file.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,12 @@
88
import random
99
import string
1010

11-
from nose.plugins.attrib import attr
1211

1312
from chart_studio import plotly as py
1413
from chart_studio.exceptions import PlotlyRequestError
1514
from chart_studio.tests.utils import PlotlyTestCase
1615

1716

18-
@attr("slow")
1917
class FolderAPITestCase(PlotlyTestCase):
2018
def setUp(self):
2119
super(FolderAPITestCase, self).setUp()

packages/python/chart-studio/chart_studio/tests/test_plot_ly/test_get_figure/test_get_figure.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
from unittest import skipIf
1111

1212
import six
13-
from nose.plugins.attrib import attr
1413

1514
import _plotly_utils.exceptions
1615
from chart_studio import exceptions
@@ -38,15 +37,13 @@ def is_trivial(obj):
3837

3938

4039
class GetFigureTest(PlotlyTestCase):
41-
@attr("slow")
4240
def test_get_figure(self):
4341
un = "PlotlyImageTest"
4442
ak = "786r5mecv0"
4543
file_id = 13183
4644
py.sign_in(un, ak)
4745
py.get_figure("PlotlyImageTest", str(file_id))
4846

49-
@attr("slow")
5047
def test_get_figure_with_url(self):
5148
un = "PlotlyImageTest"
5249
ak = "786r5mecv0"
@@ -62,7 +59,6 @@ def test_get_figure_invalid_1(self):
6259
with self.assertRaises(exceptions.PlotlyError):
6360
py.get_figure(url)
6461

65-
@attr("slow")
6662
def test_get_figure_invalid_2(self):
6763
un = "PlotlyImageTest"
6864
ak = "786r5mecv0"
@@ -80,7 +76,6 @@ def test_get_figure_invalid_3(self):
8076
with self.assertRaises(ValueError):
8177
py.get_figure(url)
8278

83-
@attr("slow")
8479
def test_get_figure_does_not_exist(self):
8580
un = "PlotlyImageTest"
8681
ak = "786r5mecv0"
@@ -89,7 +84,6 @@ def test_get_figure_does_not_exist(self):
8984
with self.assertRaises(_plotly_utils.exceptions.PlotlyError):
9085
py.get_figure(url)
9186

92-
@attr("slow")
9387
def test_get_figure_raw(self):
9488
un = "PlotlyImageTest"
9589
ak = "786r5mecv0"

packages/python/chart-studio/chart_studio/tests/test_plot_ly/test_get_requests/test_get_requests.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
import requests
1111
import six
12-
from nose.plugins.attrib import attr
1312
import json as _json
1413

1514
from chart_studio.tests.utils import PlotlyTestCase
@@ -25,7 +24,6 @@
2524

2625

2726
class GetRequestsTest(PlotlyTestCase):
28-
@attr("slow")
2927
def test_user_does_not_exist(self):
3028
username = "user_does_not_exist"
3129
api_key = "invalid-apikey"
@@ -47,7 +45,6 @@ def test_user_does_not_exist(self):
4745
self.assertEqual(response.status_code, 404)
4846
self.assertEqual(content["error"], error_message)
4947

50-
@attr("slow")
5148
def test_file_does_not_exist(self):
5249
username = "PlotlyImageTest"
5350
api_key = "786r5mecv0"
@@ -68,7 +65,6 @@ def test_file_does_not_exist(self):
6865
self.assertEqual(response.status_code, 404)
6966
self.assertEqual(content["error"], error_message)
7067

71-
@attr("slow")
7268
def test_wrong_api_key(self): # TODO: does this test the right thing?
7369
username = "PlotlyImageTest"
7470
api_key = "invalid-apikey"
@@ -85,7 +81,6 @@ def test_wrong_api_key(self): # TODO: does this test the right thing?
8581
# Locked File
8682
# TODO
8783

88-
@attr("slow")
8984
def test_private_permission_defined(self):
9085
username = "PlotlyImageTest"
9186
api_key = "786r5mecv0"
@@ -105,7 +100,6 @@ def test_private_permission_defined(self):
105100
# Private File that is shared
106101
# TODO
107102

108-
@attr("slow")
109103
def test_missing_headers(self):
110104
file_owner = "get_test_user"
111105
file_id = 0
@@ -121,7 +115,6 @@ def test_missing_headers(self):
121115
content = _json.loads(response.content.decode("unicode_escape"))
122116
self.assertEqual(response.status_code, 422)
123117

124-
@attr("slow")
125118
def test_valid_request(self):
126119
username = "PlotlyImageTest"
127120
api_key = "786r5mecv0"

packages/python/chart-studio/chart_studio/tests/test_plot_ly/test_grid/test_grid.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import string
1212
from unittest import skip
1313

14-
from nose.plugins.attrib import attr
1514

1615
from chart_studio import plotly as py
1716
from chart_studio.exceptions import InputError, PlotlyRequestError
@@ -54,19 +53,16 @@ def upload_and_return_grid(self):
5453
return g
5554

5655
# Nominal usage
57-
@attr("slow")
5856
def test_grid_upload(self):
5957
self.upload_and_return_grid()
6058

61-
@attr("slow")
6259
def test_grid_upload_in_new_folder(self):
6360
g = self.get_grid()
6461
path = "new folder: {0}/grid in folder {1}".format(
6562
random_filename(), random_filename()
6663
)
6764
py.grid_ops.upload(g, path, auto_open=False)
6865

69-
@attr("slow")
7066
def test_grid_upload_in_existing_folder(self):
7167
g = self.get_grid()
7268
folder = random_filename()
@@ -75,19 +71,16 @@ def test_grid_upload_in_existing_folder(self):
7571
path = "existing folder: {0}/grid in folder {1}".format(folder, filename)
7672
py.grid_ops.upload(g, path, auto_open=False)
7773

78-
@attr("slow")
7974
def test_column_append(self):
8075
g = self.upload_and_return_grid()
8176
new_col = Column([1, 5, 3], "new col")
8277
py.grid_ops.append_columns([new_col], grid=g)
8378

84-
@attr("slow")
8579
def test_row_append(self):
8680
g = self.upload_and_return_grid()
8781
new_rows = [[1, 2], [10, 20]]
8882
py.grid_ops.append_rows(new_rows, grid=g)
8983

90-
@attr("slow")
9184
def test_plot_from_grid(self):
9285
g = self.upload_and_return_grid()
9386
url = py.plot(
@@ -97,7 +90,6 @@ def test_plot_from_grid(self):
9790
)
9891
return url, g
9992

100-
@attr("slow")
10193
def test_get_figure_from_references(self):
10294
url, g = self.test_plot_from_grid()
10395
fig = py.get_figure(url)
@@ -143,7 +135,6 @@ def test_row_append_of_non_uploaded_grid(self):
143135
py.grid_ops.append_rows(rows, grid=g)
144136

145137
# Input Errors
146-
@attr("slow")
147138
def test_unequal_length_rows(self):
148139
g = self.upload_and_return_grid()
149140
rows = [[1, 2], ["to", "many", "cells"]]
@@ -158,7 +149,6 @@ def test_duplicate_columns(self):
158149
Grid([c1, c2])
159150

160151
# Test delete
161-
@attr("slow")
162152
def test_delete_grid(self):
163153
g = self.get_grid()
164154
fn = random_filename()

packages/python/chart-studio/chart_studio/tests/test_plot_ly/test_image/test_image.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,12 @@
66
import itertools
77
import warnings
88

9-
from nose.plugins.attrib import attr
109

1110
import _plotly_utils.exceptions
1211
from chart_studio.plotly import plotly as py
1312
from chart_studio.tests.utils import PlotlyTestCase
1413

1514

16-
@attr("slow")
1715
class TestImage(PlotlyTestCase):
1816
def setUp(self):
1917
super(TestImage, self).setUp()

packages/python/chart-studio/chart_studio/tests/test_plot_ly/test_meta/test_meta.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import random
1111
import string
1212

13-
from nose.plugins.attrib import attr
1413
from unittest import skip
1514

1615
from chart_studio import plotly as py
@@ -33,15 +32,13 @@ def random_filename(self):
3332
unique_filename = "Valid Grid with Meta " + "".join(random_chars)
3433
return unique_filename
3534

36-
@attr("slow")
3735
def test_upload_meta(self):
3836
unique_filename = self.random_filename()
3937
grid_url = py.grid_ops.upload(self._grid, unique_filename, auto_open=False)
4038

4139
# Add some Metadata to that grid
4240
py.meta_ops.upload(self._meta, grid_url=grid_url)
4341

44-
@attr("slow")
4542
def test_upload_meta_with_grid(self):
4643
c1 = Column([1, 2, 3, 4], "first column")
4744
Grid([c1])

packages/python/chart-studio/chart_studio/tests/test_plot_ly/test_plotly/test_plot.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import json as _json
1414
import warnings
1515

16-
from nose.plugins.attrib import attr
1716

1817
import chart_studio.tools as tls
1918
import plotly.tools
@@ -37,7 +36,6 @@ def setUp(self):
3736
py.sign_in("PlotlyImageTest", "786r5mecv0")
3837
self.simple_figure = {"data": [{"x": [1, 2, 3], "y": [2, 1, 2]}]}
3938

40-
@attr("slow")
4139
def test_plot_valid(self):
4240
fig = {
4341
"data": [{"x": (1, 2, 3), "y": (2, 1, 2)}],
@@ -155,7 +153,6 @@ def test_plot_option_logic_only_sharing_given(self):
155153
}
156154
self.assertEqual(plot_option_logic, expected_plot_option_logic)
157155

158-
@attr("slow")
159156
def test_plot_url_given_sharing_key(self):
160157

161158
# Give share_key is requested, the retun url should contain
@@ -175,7 +172,6 @@ def test_plot_url_given_sharing_key(self):
175172

176173
self.assertTrue("share_key=" in plot_url)
177174

178-
@attr("slow")
179175
def test_plot_url_response_given_sharing_key(self):
180176

181177
# Given share_key is requested, get request of the url should
@@ -196,7 +192,6 @@ def test_plot_url_response_given_sharing_key(self):
196192

197193
self.assertEqual(response.status_code, 200)
198194

199-
@attr("slow")
200195
def test_private_plot_response_with_and_without_share_key(self):
201196

202197
# The json file of the private plot should be 404 and once

packages/python/plotly/plotly/matplotlylib/mplexporter/tests/test_basic.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import matplotlib
22
import numpy as np
33
from distutils.version import LooseVersion
4-
from nose.plugins.skip import SkipTest
4+
import pytest
55
from numpy.testing import assert_warns
66

77
from ..exporter import Exporter
@@ -168,7 +168,7 @@ def test_image():
168168
# Test fails for matplotlib 1.5+ because the size of the image
169169
# generated by matplotlib has changed.
170170
if LooseVersion(matplotlib.__version__) >= LooseVersion('1.5.0'):
171-
raise SkipTest("Test fails for matplotlib version > 1.5.0");
171+
pytest.skip("Test fails for matplotlib version > 1.5.0")
172172
np.random.seed(0) # image size depends on the seed
173173
fig, ax = plt.subplots(figsize=(2, 2))
174174
ax.imshow(np.random.random((10, 10)),

packages/python/plotly/plotly/tests/test_core/test_colors/test_colors.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from unittest import TestCase
22

3-
from nose.tools import raises
43
import plotly.tools as tls
54
from plotly.exceptions import PlotlyError
65
import plotly.colors as colors

packages/python/plotly/plotly/tests/test_core/test_figure_messages/test_move_delete_traces.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import sys
22
from unittest import TestCase
3-
from nose.tools import raises
3+
import pytest
44

55
import plotly.graph_objs as go
66

@@ -80,12 +80,12 @@ def test_move_and_delete_traces(self):
8080
self.figure._send_deleteTraces_msg.assert_called_once_with([1])
8181
self.figure._send_moveTraces_msg.assert_called_once_with([0, 1], [1, 0])
8282

83-
@raises(ValueError)
8483
def test_validate_assigned_traces_are_subset(self):
8584
traces = self.figure.data
86-
self.figure.data = [traces[2], go.Scatter(y=[3, 2, 1]), traces[1]]
85+
with pytest.raises(ValueError):
86+
self.figure.data = [traces[2], go.Scatter(y=[3, 2, 1]), traces[1]]
8787

88-
@raises(ValueError)
8988
def test_validate_assigned_traces_are_not_duplicates(self):
9089
traces = self.figure.data
91-
self.figure.data = [traces[2], traces[1], traces[1]]
90+
with pytest.raises(ValueError):
91+
self.figure.data = [traces[2], traces[1], traces[1]]

0 commit comments

Comments
 (0)