From 448c0a8702b96a7ad2bbffbe98a937766c9fb27c Mon Sep 17 00:00:00 2001 From: Emmanuelle Gouillart Date: Wed, 19 Feb 2020 11:42:29 -0500 Subject: [PATCH 01/10] attempt to replace nose with pytest --- .circleci/config.yml | 2 +- packages/python/plotly/tox.ini | 24 ++++++++++++------------ 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 5e58717cc4a..b02e989c310 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -339,7 +339,7 @@ jobs: command: | cd packages/python/plotly locale - tox -e py37-core -- -a '!nodev' + tox -e py37-core -- -k 'not nodev' no_output_timeout: 20m - run: name: Commit diff --git a/packages/python/plotly/tox.ini b/packages/python/plotly/tox.ini index df41b7e1df1..90f239cc12f 100644 --- a/packages/python/plotly/tox.ini +++ b/packages/python/plotly/tox.ini @@ -81,25 +81,25 @@ deps= basepython={env:PLOTLY_TOX_PYTHON_27:} commands= python --version - nosetests {posargs} -x plotly/tests/test_core + pytest {posargs} -x plotly/tests/test_core [testenv:py35-core] basepython={env:PLOTLY_TOX_PYTHON_35:} commands= python --version - nosetests {posargs} -x plotly/tests/test_core + pytest {posargs} -x plotly/tests/test_core [testenv:py36-core] basepython={env:PLOTLY_TOX_PYTHON_36:} commands= python --version - nosetests {posargs} -x plotly/tests/test_core + pytest {posargs} -x plotly/tests/test_core [testenv:py37-core] basepython={env:PLOTLY_TOX_PYTHON_37:} commands= python --version - nosetests {posargs} -x plotly/tests/test_core + pytest {posargs} -x plotly/tests/test_core ; OPTIONAL ENVIRONMENTS ;[testenv:py27-optional] @@ -116,8 +116,8 @@ commands= basepython={env:PLOTLY_TOX_PYTHON_27:} commands= python --version - nosetests {posargs} -x plotly/tests/test_core - nosetests {posargs} -x plotly/tests/test_optional + pytest {posargs} -x plotly/tests/test_core + pytest {posargs} -x plotly/tests/test_optional pytest _plotly_utils/tests/ pytest plotly/tests/test_io @@ -125,8 +125,8 @@ commands= basepython={env:PLOTLY_TOX_PYTHON_35:} commands= python --version - nosetests {posargs} -x plotly/tests/test_core - nosetests {posargs} -x plotly/tests/test_optional + pytest {posargs} -x plotly/tests/test_core + pytest {posargs} -x plotly/tests/test_optional pytest _plotly_utils/tests/ pytest plotly/tests/test_io @@ -134,8 +134,8 @@ commands= basepython={env:PLOTLY_TOX_PYTHON_36:} commands= python --version - nosetests {posargs} -x plotly/tests/test_core - nosetests {posargs} -x plotly/tests/test_optional + pytest {posargs} -x plotly/tests/test_core + pytest {posargs} -x plotly/tests/test_optional pytest _plotly_utils/tests/ pytest plotly/tests/test_io @@ -143,7 +143,7 @@ commands= basepython={env:PLOTLY_TOX_PYTHON_37:} commands= python --version - nosetests {posargs} -x plotly/tests/test_core - nosetests {posargs} -x plotly/tests/test_optional + pytest {posargs} -x plotly/tests/test_core + pytest {posargs} -x plotly/tests/test_optional pytest _plotly_utils/tests/ pytest plotly/tests/test_io From 39a539dedbefb5f958b18a35fea82882bef47083 Mon Sep 17 00:00:00 2001 From: Emmanuelle Gouillart Date: Wed, 19 Feb 2020 14:19:54 -0500 Subject: [PATCH 02/10] removed nose from test requirements --- packages/python/plotly/tox.ini | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/python/plotly/tox.ini b/packages/python/plotly/tox.ini index 90f239cc12f..268c1a2aecd 100644 --- a/packages/python/plotly/tox.ini +++ b/packages/python/plotly/tox.ini @@ -53,7 +53,6 @@ deps= coverage==4.3.1 decorator==4.0.9 mock==2.0.0 - nose==1.3.7 requests==2.12.4 six==1.10.0 pytz==2016.10 From 00ace7242a0dd198dd11a278eb57e0adf643d50e Mon Sep 17 00:00:00 2001 From: Emmanuelle Gouillart Date: Thu, 20 Feb 2020 19:36:19 -0500 Subject: [PATCH 03/10] replace nose with pytest --- .../test_core/test_tools/test_get_embed.py | 6 +-- .../test_matplotlylib/test_plot_mpl.py | 13 ++--- .../tests/test_plot_ly/test_file/test_file.py | 2 - .../test_get_figure/test_get_figure.py | 6 --- .../test_get_requests/test_get_requests.py | 7 --- .../tests/test_plot_ly/test_grid/test_grid.py | 10 ---- .../test_plot_ly/test_image/test_image.py | 2 - .../tests/test_plot_ly/test_meta/test_meta.py | 3 -- .../test_plot_ly/test_plotly/test_plot.py | 5 -- .../mplexporter/tests/test_basic.py | 4 +- .../test_core/test_colors/test_colors.py | 1 - .../test_move_delete_traces.py | 10 ++-- .../test_figure_messages/test_on_change.py | 18 +++---- .../test_validate_no_frames.py | 15 +++--- .../test_graph_objs/test_annotations.py | 2 - .../test_graph_objs/test_append_trace.py | 19 ++++--- .../test_graph_objs/test_constructor.py | 18 +++---- .../test_core/test_graph_objs/test_data.py | 7 --- .../test_graph_objs/test_error_bars.py | 1 - .../test_graph_objs/test_figure_properties.py | 51 ++++++++++--------- .../test_core/test_graph_objs/test_frames.py | 4 +- .../test_graph_objs/test_layout_subplots.py | 11 ++-- .../test_properties_validated.py | 30 +++++------ .../test_core/test_graph_objs/test_scatter.py | 1 - .../test_graph_objs/test_template.py | 28 +++++----- .../test_core/test_offline/test_offline.py | 4 +- .../test_matplotlylib/test_annotations.py | 4 +- .../test_matplotlylib/test_axis_scales.py | 4 +- .../test_matplotlylib/test_bars.py | 10 ++-- .../test_matplotlylib/test_data.py | 11 ++-- .../test_matplotlylib/test_date_times.py | 4 +- .../test_matplotlylib/test_lines.py | 6 +-- .../test_matplotlylib/test_scatter.py | 7 ++- .../test_matplotlylib/test_subplots.py | 4 +- .../test_offline/test_offline.py | 7 ++- .../test_optional/test_utils/test_utils.py | 4 +- packages/python/plotly/pytest.ini | 5 ++ 37 files changed, 147 insertions(+), 197 deletions(-) create mode 100644 packages/python/plotly/pytest.ini diff --git a/packages/python/chart-studio/chart_studio/tests/test_core/test_tools/test_get_embed.py b/packages/python/chart-studio/chart_studio/tests/test_core/test_tools/test_get_embed.py index bbb6499fcae..77709176e50 100644 --- a/packages/python/chart-studio/chart_studio/tests/test_core/test_tools/test_get_embed.py +++ b/packages/python/chart-studio/chart_studio/tests/test_core/test_tools/test_get_embed.py @@ -2,7 +2,7 @@ from unittest import TestCase -from nose.tools import raises +import pytest import chart_studio.tools as tls from _plotly_utils.exceptions import PlotlyError @@ -13,10 +13,10 @@ def test_get_valid_embed(): tls.get_embed(url) -@raises(PlotlyError) def test_get_invalid_embed(): url = "https://plot.ly/~PlotBot/a/" - tls.get_embed(url) + with pytest.raises(PlotlyError): + tls.get_embed(url) class TestGetEmbed(TestCase): diff --git a/packages/python/chart-studio/chart_studio/tests/test_optional/test_matplotlylib/test_plot_mpl.py b/packages/python/chart-studio/chart_studio/tests/test_optional/test_matplotlylib/test_plot_mpl.py index ac352928465..e1c89017026 100644 --- a/packages/python/chart-studio/chart_studio/tests/test_optional/test_matplotlylib/test_plot_mpl.py +++ b/packages/python/chart-studio/chart_studio/tests/test_optional/test_matplotlylib/test_plot_mpl.py @@ -7,13 +7,12 @@ """ from __future__ import absolute_import -from nose.plugins.attrib import attr -from nose.tools import raises import _plotly_utils.exceptions from plotly import optional_imports from chart_studio.plotly import plotly as py from unittest import TestCase +import pytest matplotlylib = optional_imports.get_module("plotly.matplotlylib") @@ -21,26 +20,24 @@ import matplotlib.pyplot as plt -@attr("matplotlib") class PlotMPLTest(TestCase): def setUp(self): py.sign_in("PlotlyImageTest", "786r5mecv0", plotly_domain="https://plot.ly") - @raises(_plotly_utils.exceptions.PlotlyGraphObjectError) def test_update_type_error(self): fig, ax = plt.subplots() ax.plot([1, 2, 3]) update = [] - py.plot_mpl(fig, update=update, filename="nosetests", auto_open=False) + with pytest.raises(_plotly_utils.exceptions.PlotlyGraphObjectError): + py.plot_mpl(fig, update=update, filename="nosetests", auto_open=False) - @raises(KeyError) def test_update_validation_error(self): fig, ax = plt.subplots() ax.plot([1, 2, 3]) update = {"invalid": "anything"} - py.plot_mpl(fig, update=update, filename="nosetests", auto_open=False) + with pytest.raises(KeyError): + py.plot_mpl(fig, update=update, filename="nosetests", auto_open=False) - @attr("slow") def test_update(self): fig, ax = plt.subplots() ax.plot([1, 2, 3]) diff --git a/packages/python/chart-studio/chart_studio/tests/test_plot_ly/test_file/test_file.py b/packages/python/chart-studio/chart_studio/tests/test_plot_ly/test_file/test_file.py index 3b3746414aa..4dccef14467 100644 --- a/packages/python/chart-studio/chart_studio/tests/test_plot_ly/test_file/test_file.py +++ b/packages/python/chart-studio/chart_studio/tests/test_plot_ly/test_file/test_file.py @@ -8,14 +8,12 @@ import random import string -from nose.plugins.attrib import attr from chart_studio import plotly as py from chart_studio.exceptions import PlotlyRequestError from chart_studio.tests.utils import PlotlyTestCase -@attr("slow") class FolderAPITestCase(PlotlyTestCase): def setUp(self): super(FolderAPITestCase, self).setUp() diff --git a/packages/python/chart-studio/chart_studio/tests/test_plot_ly/test_get_figure/test_get_figure.py b/packages/python/chart-studio/chart_studio/tests/test_plot_ly/test_get_figure/test_get_figure.py index 69b6da830c6..b0c4ca68ba2 100644 --- a/packages/python/chart-studio/chart_studio/tests/test_plot_ly/test_get_figure/test_get_figure.py +++ b/packages/python/chart-studio/chart_studio/tests/test_plot_ly/test_get_figure/test_get_figure.py @@ -10,7 +10,6 @@ from unittest import skipIf import six -from nose.plugins.attrib import attr import _plotly_utils.exceptions from chart_studio import exceptions @@ -38,7 +37,6 @@ def is_trivial(obj): class GetFigureTest(PlotlyTestCase): - @attr("slow") def test_get_figure(self): un = "PlotlyImageTest" ak = "786r5mecv0" @@ -46,7 +44,6 @@ def test_get_figure(self): py.sign_in(un, ak) py.get_figure("PlotlyImageTest", str(file_id)) - @attr("slow") def test_get_figure_with_url(self): un = "PlotlyImageTest" ak = "786r5mecv0" @@ -62,7 +59,6 @@ def test_get_figure_invalid_1(self): with self.assertRaises(exceptions.PlotlyError): py.get_figure(url) - @attr("slow") def test_get_figure_invalid_2(self): un = "PlotlyImageTest" ak = "786r5mecv0" @@ -80,7 +76,6 @@ def test_get_figure_invalid_3(self): with self.assertRaises(ValueError): py.get_figure(url) - @attr("slow") def test_get_figure_does_not_exist(self): un = "PlotlyImageTest" ak = "786r5mecv0" @@ -89,7 +84,6 @@ def test_get_figure_does_not_exist(self): with self.assertRaises(_plotly_utils.exceptions.PlotlyError): py.get_figure(url) - @attr("slow") def test_get_figure_raw(self): un = "PlotlyImageTest" ak = "786r5mecv0" diff --git a/packages/python/chart-studio/chart_studio/tests/test_plot_ly/test_get_requests/test_get_requests.py b/packages/python/chart-studio/chart_studio/tests/test_plot_ly/test_get_requests/test_get_requests.py index a57487f3107..1f7c96369f3 100644 --- a/packages/python/chart-studio/chart_studio/tests/test_plot_ly/test_get_requests/test_get_requests.py +++ b/packages/python/chart-studio/chart_studio/tests/test_plot_ly/test_get_requests/test_get_requests.py @@ -9,7 +9,6 @@ import requests import six -from nose.plugins.attrib import attr import json as _json from chart_studio.tests.utils import PlotlyTestCase @@ -25,7 +24,6 @@ class GetRequestsTest(PlotlyTestCase): - @attr("slow") def test_user_does_not_exist(self): username = "user_does_not_exist" api_key = "invalid-apikey" @@ -47,7 +45,6 @@ def test_user_does_not_exist(self): self.assertEqual(response.status_code, 404) self.assertEqual(content["error"], error_message) - @attr("slow") def test_file_does_not_exist(self): username = "PlotlyImageTest" api_key = "786r5mecv0" @@ -68,7 +65,6 @@ def test_file_does_not_exist(self): self.assertEqual(response.status_code, 404) self.assertEqual(content["error"], error_message) - @attr("slow") def test_wrong_api_key(self): # TODO: does this test the right thing? username = "PlotlyImageTest" api_key = "invalid-apikey" @@ -85,7 +81,6 @@ def test_wrong_api_key(self): # TODO: does this test the right thing? # Locked File # TODO - @attr("slow") def test_private_permission_defined(self): username = "PlotlyImageTest" api_key = "786r5mecv0" @@ -105,7 +100,6 @@ def test_private_permission_defined(self): # Private File that is shared # TODO - @attr("slow") def test_missing_headers(self): file_owner = "get_test_user" file_id = 0 @@ -121,7 +115,6 @@ def test_missing_headers(self): content = _json.loads(response.content.decode("unicode_escape")) self.assertEqual(response.status_code, 422) - @attr("slow") def test_valid_request(self): username = "PlotlyImageTest" api_key = "786r5mecv0" diff --git a/packages/python/chart-studio/chart_studio/tests/test_plot_ly/test_grid/test_grid.py b/packages/python/chart-studio/chart_studio/tests/test_plot_ly/test_grid/test_grid.py index 669dd46f551..ac542e70fb7 100644 --- a/packages/python/chart-studio/chart_studio/tests/test_plot_ly/test_grid/test_grid.py +++ b/packages/python/chart-studio/chart_studio/tests/test_plot_ly/test_grid/test_grid.py @@ -11,7 +11,6 @@ import string from unittest import skip -from nose.plugins.attrib import attr from chart_studio import plotly as py from chart_studio.exceptions import InputError, PlotlyRequestError @@ -54,11 +53,9 @@ def upload_and_return_grid(self): return g # Nominal usage - @attr("slow") def test_grid_upload(self): self.upload_and_return_grid() - @attr("slow") def test_grid_upload_in_new_folder(self): g = self.get_grid() path = "new folder: {0}/grid in folder {1}".format( @@ -66,7 +63,6 @@ def test_grid_upload_in_new_folder(self): ) py.grid_ops.upload(g, path, auto_open=False) - @attr("slow") def test_grid_upload_in_existing_folder(self): g = self.get_grid() folder = random_filename() @@ -75,19 +71,16 @@ def test_grid_upload_in_existing_folder(self): path = "existing folder: {0}/grid in folder {1}".format(folder, filename) py.grid_ops.upload(g, path, auto_open=False) - @attr("slow") def test_column_append(self): g = self.upload_and_return_grid() new_col = Column([1, 5, 3], "new col") py.grid_ops.append_columns([new_col], grid=g) - @attr("slow") def test_row_append(self): g = self.upload_and_return_grid() new_rows = [[1, 2], [10, 20]] py.grid_ops.append_rows(new_rows, grid=g) - @attr("slow") def test_plot_from_grid(self): g = self.upload_and_return_grid() url = py.plot( @@ -97,7 +90,6 @@ def test_plot_from_grid(self): ) return url, g - @attr("slow") def test_get_figure_from_references(self): url, g = self.test_plot_from_grid() fig = py.get_figure(url) @@ -143,7 +135,6 @@ def test_row_append_of_non_uploaded_grid(self): py.grid_ops.append_rows(rows, grid=g) # Input Errors - @attr("slow") def test_unequal_length_rows(self): g = self.upload_and_return_grid() rows = [[1, 2], ["to", "many", "cells"]] @@ -158,7 +149,6 @@ def test_duplicate_columns(self): Grid([c1, c2]) # Test delete - @attr("slow") def test_delete_grid(self): g = self.get_grid() fn = random_filename() diff --git a/packages/python/chart-studio/chart_studio/tests/test_plot_ly/test_image/test_image.py b/packages/python/chart-studio/chart_studio/tests/test_plot_ly/test_image/test_image.py index d9c5253c820..c4d43a636cd 100644 --- a/packages/python/chart-studio/chart_studio/tests/test_plot_ly/test_image/test_image.py +++ b/packages/python/chart-studio/chart_studio/tests/test_plot_ly/test_image/test_image.py @@ -6,14 +6,12 @@ import itertools import warnings -from nose.plugins.attrib import attr import _plotly_utils.exceptions from chart_studio.plotly import plotly as py from chart_studio.tests.utils import PlotlyTestCase -@attr("slow") class TestImage(PlotlyTestCase): def setUp(self): super(TestImage, self).setUp() diff --git a/packages/python/chart-studio/chart_studio/tests/test_plot_ly/test_meta/test_meta.py b/packages/python/chart-studio/chart_studio/tests/test_plot_ly/test_meta/test_meta.py index d26fb8c6010..2af3ff9df3c 100644 --- a/packages/python/chart-studio/chart_studio/tests/test_plot_ly/test_meta/test_meta.py +++ b/packages/python/chart-studio/chart_studio/tests/test_plot_ly/test_meta/test_meta.py @@ -10,7 +10,6 @@ import random import string -from nose.plugins.attrib import attr from unittest import skip from chart_studio import plotly as py @@ -33,7 +32,6 @@ def random_filename(self): unique_filename = "Valid Grid with Meta " + "".join(random_chars) return unique_filename - @attr("slow") def test_upload_meta(self): unique_filename = self.random_filename() grid_url = py.grid_ops.upload(self._grid, unique_filename, auto_open=False) @@ -41,7 +39,6 @@ def test_upload_meta(self): # Add some Metadata to that grid py.meta_ops.upload(self._meta, grid_url=grid_url) - @attr("slow") def test_upload_meta_with_grid(self): c1 = Column([1, 2, 3, 4], "first column") Grid([c1]) diff --git a/packages/python/chart-studio/chart_studio/tests/test_plot_ly/test_plotly/test_plot.py b/packages/python/chart-studio/chart_studio/tests/test_plot_ly/test_plotly/test_plot.py index 3982bde7d88..7351f1ee2a9 100644 --- a/packages/python/chart-studio/chart_studio/tests/test_plot_ly/test_plotly/test_plot.py +++ b/packages/python/chart-studio/chart_studio/tests/test_plot_ly/test_plotly/test_plot.py @@ -13,7 +13,6 @@ import json as _json import warnings -from nose.plugins.attrib import attr import chart_studio.tools as tls import plotly.tools @@ -37,7 +36,6 @@ def setUp(self): py.sign_in("PlotlyImageTest", "786r5mecv0") self.simple_figure = {"data": [{"x": [1, 2, 3], "y": [2, 1, 2]}]} - @attr("slow") def test_plot_valid(self): fig = { "data": [{"x": (1, 2, 3), "y": (2, 1, 2)}], @@ -155,7 +153,6 @@ def test_plot_option_logic_only_sharing_given(self): } self.assertEqual(plot_option_logic, expected_plot_option_logic) - @attr("slow") def test_plot_url_given_sharing_key(self): # Give share_key is requested, the retun url should contain @@ -175,7 +172,6 @@ def test_plot_url_given_sharing_key(self): self.assertTrue("share_key=" in plot_url) - @attr("slow") def test_plot_url_response_given_sharing_key(self): # Given share_key is requested, get request of the url should @@ -196,7 +192,6 @@ def test_plot_url_response_given_sharing_key(self): self.assertEqual(response.status_code, 200) - @attr("slow") def test_private_plot_response_with_and_without_share_key(self): # The json file of the private plot should be 404 and once diff --git a/packages/python/plotly/plotly/matplotlylib/mplexporter/tests/test_basic.py b/packages/python/plotly/plotly/matplotlylib/mplexporter/tests/test_basic.py index 1c4dfb3e92b..b86759fa183 100644 --- a/packages/python/plotly/plotly/matplotlylib/mplexporter/tests/test_basic.py +++ b/packages/python/plotly/plotly/matplotlylib/mplexporter/tests/test_basic.py @@ -1,7 +1,7 @@ import matplotlib import numpy as np from distutils.version import LooseVersion -from nose.plugins.skip import SkipTest +import pytest from numpy.testing import assert_warns from ..exporter import Exporter @@ -168,7 +168,7 @@ def test_image(): # Test fails for matplotlib 1.5+ because the size of the image # generated by matplotlib has changed. if LooseVersion(matplotlib.__version__) >= LooseVersion('1.5.0'): - raise SkipTest("Test fails for matplotlib version > 1.5.0"); + pytest.skip("Test fails for matplotlib version > 1.5.0") np.random.seed(0) # image size depends on the seed fig, ax = plt.subplots(figsize=(2, 2)) ax.imshow(np.random.random((10, 10)), diff --git a/packages/python/plotly/plotly/tests/test_core/test_colors/test_colors.py b/packages/python/plotly/plotly/tests/test_core/test_colors/test_colors.py index 053b595e507..e382e9bfd7d 100644 --- a/packages/python/plotly/plotly/tests/test_core/test_colors/test_colors.py +++ b/packages/python/plotly/plotly/tests/test_core/test_colors/test_colors.py @@ -1,6 +1,5 @@ from unittest import TestCase -from nose.tools import raises import plotly.tools as tls from plotly.exceptions import PlotlyError import plotly.colors as colors diff --git a/packages/python/plotly/plotly/tests/test_core/test_figure_messages/test_move_delete_traces.py b/packages/python/plotly/plotly/tests/test_core/test_figure_messages/test_move_delete_traces.py index a644cf65940..9a8e332549b 100644 --- a/packages/python/plotly/plotly/tests/test_core/test_figure_messages/test_move_delete_traces.py +++ b/packages/python/plotly/plotly/tests/test_core/test_figure_messages/test_move_delete_traces.py @@ -1,6 +1,6 @@ import sys from unittest import TestCase -from nose.tools import raises +import pytest import plotly.graph_objs as go @@ -80,12 +80,12 @@ def test_move_and_delete_traces(self): self.figure._send_deleteTraces_msg.assert_called_once_with([1]) self.figure._send_moveTraces_msg.assert_called_once_with([0, 1], [1, 0]) - @raises(ValueError) def test_validate_assigned_traces_are_subset(self): traces = self.figure.data - self.figure.data = [traces[2], go.Scatter(y=[3, 2, 1]), traces[1]] + with pytest.raises(ValueError): + self.figure.data = [traces[2], go.Scatter(y=[3, 2, 1]), traces[1]] - @raises(ValueError) def test_validate_assigned_traces_are_not_duplicates(self): traces = self.figure.data - self.figure.data = [traces[2], traces[1], traces[1]] + with pytest.raises(ValueError): + self.figure.data = [traces[2], traces[1], traces[1]] diff --git a/packages/python/plotly/plotly/tests/test_core/test_figure_messages/test_on_change.py b/packages/python/plotly/plotly/tests/test_core/test_figure_messages/test_on_change.py index 5f2aeb610ff..8e2ce3426df 100644 --- a/packages/python/plotly/plotly/tests/test_core/test_figure_messages/test_on_change.py +++ b/packages/python/plotly/plotly/tests/test_core/test_figure_messages/test_on_change.py @@ -1,6 +1,6 @@ import sys from unittest import TestCase -from nose.tools import raises +import pytest import plotly.graph_objs as go @@ -24,26 +24,26 @@ def setUp(self): # on_change validation # -------------------- - @raises(ValueError) def test_raise_if_no_figure(self): scatt = go.Scatter() fn = MagicMock() - scatt.on_change(fn, "x") + with pytest.raises(ValueError): + scatt.on_change(fn, "x") - @raises(ValueError) def test_raise_on_frame_hierarchy(self): fn = MagicMock() - self.figure.frames[0].layout.xaxis.on_change(fn, "range") + with pytest.raises(ValueError): + self.figure.frames[0].layout.xaxis.on_change(fn, "range") - @raises(ValueError) def test_validate_property_path_nested(self): fn = MagicMock() - self.figure.layout.xaxis.on_change(fn, "bogus") + with pytest.raises(ValueError): + self.figure.layout.xaxis.on_change(fn, "bogus") - @raises(ValueError) def test_validate_property_path_nested(self): fn = MagicMock() - self.figure.layout.on_change(fn, "xaxis.titlefont.bogus") + with pytest.raises(ValueError): + self.figure.layout.on_change(fn, "xaxis.titlefont.bogus") # Python triggered changes # ------------------------ diff --git a/packages/python/plotly/plotly/tests/test_core/test_figure_widget_backend/test_validate_no_frames.py b/packages/python/plotly/plotly/tests/test_core/test_figure_widget_backend/test_validate_no_frames.py index d7331872e86..7a9efdcc7a7 100644 --- a/packages/python/plotly/plotly/tests/test_core/test_figure_widget_backend/test_validate_no_frames.py +++ b/packages/python/plotly/plotly/tests/test_core/test_figure_widget_backend/test_validate_no_frames.py @@ -1,29 +1,28 @@ from unittest import TestCase import plotly.graph_objs as go -from nose.tools import raises - +import pytest class TestNoFrames(TestCase): if "FigureWidget" in go.__dict__.keys(): - @raises(ValueError) def test_no_frames_in_constructor_kwarg(self): - go.FigureWidget(frames=[{}]) + with pytest.raises(ValueError): + go.FigureWidget(frames=[{}]) def test_emtpy_frames_ok_as_constructor_kwarg(self): go.FigureWidget(frames=[]) - @raises(ValueError) def test_no_frames_in_constructor_dict(self): - go.FigureWidget({"frames": [{}]}) + with pytest.raises(ValueError): + go.FigureWidget({"frames": [{}]}) def test_emtpy_frames_ok_as_constructor_dict_key(self): go.FigureWidget({"frames": []}) - @raises(ValueError) def test_no_frames_assignment(self): fig = go.FigureWidget() - fig.frames = [{}] + with pytest.raises(ValueError): + fig.frames = [{}] def test_emtpy_frames_assignment_ok(self): fig = go.FigureWidget() diff --git a/packages/python/plotly/plotly/tests/test_core/test_graph_objs/test_annotations.py b/packages/python/plotly/plotly/tests/test_core/test_graph_objs/test_annotations.py index c551bc5be13..65aff11e98a 100644 --- a/packages/python/plotly/plotly/tests/test_core/test_graph_objs/test_annotations.py +++ b/packages/python/plotly/plotly/tests/test_core/test_graph_objs/test_annotations.py @@ -8,8 +8,6 @@ from __future__ import absolute_import from unittest import skip -from nose.tools import raises - from plotly.exceptions import ( PlotlyError, PlotlyDictKeyError, diff --git a/packages/python/plotly/plotly/tests/test_core/test_graph_objs/test_append_trace.py b/packages/python/plotly/plotly/tests/test_core/test_graph_objs/test_append_trace.py index 9f522492226..f01770ceb81 100644 --- a/packages/python/plotly/plotly/tests/test_core/test_graph_objs/test_append_trace.py +++ b/packages/python/plotly/plotly/tests/test_core/test_graph_objs/test_append_trace.py @@ -1,6 +1,5 @@ from __future__ import absolute_import - -from nose.tools import raises +import pytest from plotly.graph_objs import ( Data, @@ -19,31 +18,31 @@ import copy -@raises(Exception) def test_print_grid_before_make_subplots(): fig = Figure() - fig.print_grid() + with pytest.raises(Exception): + fig.print_grid() -@raises(Exception) def test_append_trace_before_make_subplots(): trace = Scatter(x=[1, 2, 3], y=[2, 3, 4]) fig = Figure() - fig.append_trace(trace, 2, 2) + with pytest.raises(Exception): + fig.append_trace(trace, 2, 2) -@raises(Exception) def test_append_trace_row_out_of_range(): trace = Scatter(x=[1, 2, 3], y=[2, 3, 4]) fig = tls.make_subplots(rows=2, cols=3) - fig.append_trace(trace, 10, 2) + with pytest.raises(Exception): + fig.append_trace(trace, 10, 2) -@raises(Exception) def test_append_trace_col_out_of_range(): trace = Scatter(x=[1, 2, 3], y=[2, 3, 4]) fig = tls.make_subplots(rows=2, cols=3) - fig.append_trace(trace, 2, 0) + with pytest.raises(Exception): + fig.append_trace(trace, 2, 0) def test_append_scatter(): diff --git a/packages/python/plotly/plotly/tests/test_core/test_graph_objs/test_constructor.py b/packages/python/plotly/plotly/tests/test_core/test_graph_objs/test_constructor.py index 870b11b3de2..09fa78857b8 100644 --- a/packages/python/plotly/plotly/tests/test_core/test_graph_objs/test_constructor.py +++ b/packages/python/plotly/plotly/tests/test_core/test_graph_objs/test_constructor.py @@ -1,6 +1,6 @@ from unittest import TestCase import plotly.graph_objs as go -from nose.tools import raises +import pytest class TestGraphObjConstructor(TestCase): @@ -28,18 +28,18 @@ def test_kwarg_takes_precedence(self): m.to_plotly_json(), {"color": "blue", "size": 12, "opacity": 0.6} ) - @raises(ValueError) def test_invalid_kwarg(self): - go.scatter.Marker(bogus=[1, 2, 3]) + with pytest.raises(ValueError): + go.scatter.Marker(bogus=[1, 2, 3]) - @raises(ValueError) def test_invalid_arg(self): - go.scatter.Marker([1, 2, 3]) + with pytest.raises(ValueError): + go.scatter.Marker([1, 2, 3]) - @raises(ValueError) def test_valid_arg_with_invalid_key_name(self): - go.scatter.Marker({"bogus": 12}) + with pytest.raises(ValueError): + go.scatter.Marker({"bogus": 12}) - @raises(ValueError) def test_valid_arg_with_invalid_key_value(self): - go.scatter.Marker({"color": "bogus"}) + with pytest.raises(ValueError): + go.scatter.Marker({"color": "bogus"}) diff --git a/packages/python/plotly/plotly/tests/test_core/test_graph_objs/test_data.py b/packages/python/plotly/plotly/tests/test_core/test_graph_objs/test_data.py index faec80efcd0..136a043a46f 100644 --- a/packages/python/plotly/plotly/tests/test_core/test_graph_objs/test_data.py +++ b/packages/python/plotly/plotly/tests/test_core/test_graph_objs/test_data.py @@ -8,7 +8,6 @@ from __future__ import absolute_import from unittest import skip -from nose.tools import raises from plotly.exceptions import ( PlotlyError, @@ -30,7 +29,6 @@ def test_trivial(): assert Data() == list() -# @raises(PlotlyError) def test_weird_instantiation(): # Python allows this... assert Data({}) == [] @@ -43,26 +41,21 @@ def test_dict_instantiation(): Data([{"type": "scatter"}]) -# @raises(PlotlyDictKeyError) def test_dict_instantiation_key_error(): assert Data([{"not-a-key": "anything"}]) == [{"not-a-key": "anything"}] -# @raises(PlotlyDictValueError) def test_dict_instantiation_key_error_2(): assert Data([{"marker": "not-a-dict"}]) == [{"marker": "not-a-dict"}] -# @raises(PlotlyDataTypeError) def test_dict_instantiation_type_error(): assert Data([{"type": "invalid_type"}]) == [{"type": "invalid_type"}] -# @raises(PlotlyListEntryError) def test_dict_instantiation_graph_obj_error_0(): assert Data([Data()]) == [[]] -# raises(PlotlyListEntryError) def test_dict_instantiation_graph_obj_error_2(): assert Data([Annotations()]) == [[]] diff --git a/packages/python/plotly/plotly/tests/test_core/test_graph_objs/test_error_bars.py b/packages/python/plotly/plotly/tests/test_core/test_graph_objs/test_error_bars.py index 7526135d154..d12abbc24c6 100644 --- a/packages/python/plotly/plotly/tests/test_core/test_graph_objs/test_error_bars.py +++ b/packages/python/plotly/plotly/tests/test_core/test_graph_objs/test_error_bars.py @@ -7,7 +7,6 @@ """ from __future__ import absolute_import -from nose.tools import raises from plotly.graph_objs import ErrorX, ErrorY from plotly.exceptions import PlotlyDictKeyError diff --git a/packages/python/plotly/plotly/tests/test_core/test_graph_objs/test_figure_properties.py b/packages/python/plotly/plotly/tests/test_core/test_graph_objs/test_figure_properties.py index 26a256de9f1..99ee26e0bad 100644 --- a/packages/python/plotly/plotly/tests/test_core/test_graph_objs/test_figure_properties.py +++ b/packages/python/plotly/plotly/tests/test_core/test_graph_objs/test_figure_properties.py @@ -1,6 +1,7 @@ from unittest import TestCase +import pytest + import plotly.graph_objs as go -from nose.tools import raises import plotly.io as pio @@ -81,21 +82,21 @@ def test_property_assignment_dots(self): self.figure["frames[0].layout.yaxis.title.text"] = "f2" self.assertEqual(self.figure["frames.0.layout.yaxis.title.text"], "f2") - @raises(AttributeError) def test_access_invalid_attr(self): - self.figure.bogus + with pytest.raises(AttributeError): + self.figure.bogus - @raises(KeyError) def test_access_invalid_item(self): - self.figure["bogus"] + with pytest.raises(KeyError): + self.figure["bogus"] - @raises(AttributeError) def test_assign_invalid_attr(self): - self.figure.bogus = "val" + with pytest.raises(AttributeError): + self.figure.bogus = "val" - @raises(KeyError) def test_access_invalid_item(self): - self.figure["bogus"] = "val" + with pytest.raises(KeyError): + self.figure["bogus"] = "val" # Update def test_update_layout(self): @@ -202,9 +203,9 @@ def test_update_frames(self): ) self.assertEqual(self.figure.frames[0].layout.yaxis.title.text, "f4") - @raises(ValueError) def test_update_invalid_attr(self): - self.figure.layout.update({"xaxis": {"bogus": 32}}) + with pytest.raises(ValueError): + self.figure.layout.update({"xaxis": {"bogus": 32}}) # plotly_restyle def test_plotly_restyle(self): @@ -218,13 +219,13 @@ def test_plotly_restyle(self): self.assertEqual(self.figure.data[0].marker.color, "blue") - @raises(ValueError) def test_restyle_validate_property(self): - self.figure.plotly_restyle({"bogus": 3}, trace_indexes=[0]) + with pytest.raises(ValueError): + self.figure.plotly_restyle({"bogus": 3}, trace_indexes=[0]) - @raises(ValueError) def test_restyle_validate_property_nested(self): - self.figure.plotly_restyle({"marker.bogus": 3}, trace_indexes=[0]) + with pytest.raises(ValueError): + self.figure.plotly_restyle({"marker.bogus": 3}, trace_indexes=[0]) # plotly_relayout def test_plotly_relayout(self): @@ -235,17 +236,17 @@ def test_plotly_relayout(self): self.figure.plotly_relayout(relayout_data={"xaxis.range": [10, 20]}) self.assertEqual(self.figure.layout.xaxis.range, (10, 20)) - @raises(ValueError) def test_relayout_validate_property(self): - self.figure.plotly_relayout({"bogus": [1, 3]}) + with pytest.raises(ValueError): + self.figure.plotly_relayout({"bogus": [1, 3]}) - @raises(ValueError) def test_relayout_validate_property_nested(self): - self.figure.plotly_relayout({"xaxis.bogus": [1, 3]}) + with pytest.raises(ValueError): + self.figure.plotly_relayout({"xaxis.bogus": [1, 3]}) - @raises(ValueError) def test_relayout_validate_unintialized_subplot(self): - self.figure.plotly_relayout({"xaxis2.range": [1, 3]}) + with pytest.raises(ValueError): + self.figure.plotly_relayout({"xaxis2.range": [1, 3]}) # plotly_update def test_plotly_update_layout(self): @@ -267,10 +268,10 @@ def test_plotly_update_data(self): self.assertEqual(self.figure.data[0].marker.color, "blue") - @raises(ValueError) def test_plotly_update_validate_property_trace(self): - self.figure.plotly_update(restyle_data={"bogus": 3}, trace_indexes=[0]) + with pytest.raises(ValueError): + self.figure.plotly_update(restyle_data={"bogus": 3}, trace_indexes=[0]) - @raises(ValueError) def test_plotly_update_validate_property_layout(self): - self.figure.plotly_update(relayout_data={"xaxis.bogus": [1, 3]}) + with pytest.raises(ValueError): + self.figure.plotly_update(relayout_data={"xaxis.bogus": [1, 3]}) diff --git a/packages/python/plotly/plotly/tests/test_core/test_graph_objs/test_frames.py b/packages/python/plotly/plotly/tests/test_core/test_graph_objs/test_frames.py index 37a33b20265..c7dc96d8e82 100644 --- a/packages/python/plotly/plotly/tests/test_core/test_graph_objs/test_frames.py +++ b/packages/python/plotly/plotly/tests/test_core/test_graph_objs/test_frames.py @@ -4,7 +4,7 @@ from plotly.graph_objs import Bar, Frames, Frame, Layout -from nose.plugins.attrib import attr +import pytest import re @@ -43,7 +43,7 @@ def test_non_string_frame(self): # with self.assertRaises(exceptions.PlotlyListEntryError): # frames.append(0) - @attr("nodev") + @pytest.mark.nodev def test_deeply_nested_layout_attributes(self): frames = Frame frames.layout = [Layout()] diff --git a/packages/python/plotly/plotly/tests/test_core/test_graph_objs/test_layout_subplots.py b/packages/python/plotly/plotly/tests/test_core/test_graph_objs/test_layout_subplots.py index 1401512ada4..037d2384983 100644 --- a/packages/python/plotly/plotly/tests/test_core/test_graph_objs/test_layout_subplots.py +++ b/packages/python/plotly/plotly/tests/test_core/test_graph_objs/test_layout_subplots.py @@ -1,6 +1,7 @@ from unittest import TestCase +import pytest + import plotly.graph_objs as go -from nose.tools import raises import plotly.io as pio @@ -33,13 +34,13 @@ def test_initial_access_subplots(self): self.assertIs(self.layout.mapbox, self.layout.mapbox1) self.assertIs(self.layout.polar, self.layout.polar1) - @raises(AttributeError) def test_initial_access_subplot2(self): - self.layout.xaxis2 + with pytest.raises(AttributeError): + self.layout.xaxis2 - @raises(KeyError) def test_initial_access_subplot2(self): - self.layout["xaxis2"] + with pytest.raises(KeyError): + self.layout["xaxis2"] def test_assign_subplots(self): self.assertIsNone(self.layout.xaxis.title.text) diff --git a/packages/python/plotly/plotly/tests/test_core/test_graph_objs/test_properties_validated.py b/packages/python/plotly/plotly/tests/test_core/test_graph_objs/test_properties_validated.py index e31d1dad095..c3edcfb1113 100644 --- a/packages/python/plotly/plotly/tests/test_core/test_graph_objs/test_properties_validated.py +++ b/packages/python/plotly/plotly/tests/test_core/test_graph_objs/test_properties_validated.py @@ -1,6 +1,6 @@ from unittest import TestCase import plotly.graph_objs as go -from nose.tools import raises +import pytest class TestPropertyValidation(TestCase): @@ -9,43 +9,43 @@ def setUp(self): self.scatter = go.Scatter() self.scatter.name = "Scatter 1" - @raises(ValueError) def test_validators_work_attr(self): """ Note: all of the individual validators are tested in `_plotly_utils/tests/validators`. Here we're just making sure that datatypes make use of validators """ - self.scatter.name = [1, 2, 3] + with pytest.raises(ValueError): + self.scatter.name = [1, 2, 3] - @raises(ValueError) def test_validators_work_item(self): """ Note: all of the individual validators are tested in `_plotly_utils/tests/validators`. Here we're just making sure that datatypes make use of validators """ - self.scatter["name"] = [1, 2, 3] + with pytest.raises(ValueError): + self.scatter["name"] = [1, 2, 3] - @raises(ValueError) def test_invalid_attr_assignment(self): - self.scatter.bogus = 87 + with pytest.raises(ValueError): + self.scatter.bogus = 87 - @raises(ValueError) def test_invalid_item_assignment(self): - self.scatter["bogus"] = 87 + with pytest.raises(ValueError): + self.scatter["bogus"] = 87 - @raises(ValueError) def test_invalid_dot_assignment(self): - self.scatter["marker.bogus"] = 87 + with pytest.raises(ValueError): + self.scatter["marker.bogus"] = 87 - @raises(ValueError) def test_invalid_tuple_assignment(self): - self.scatter[("marker", "bogus")] = 87 + with pytest.raises(ValueError): + self.scatter[("marker", "bogus")] = 87 - @raises(ValueError) def test_invalid_constructor_kwarg(self): - go.Scatter(bogus=87) + with pytest.raises(ValueError): + go.Scatter(bogus=87) class TestPropertyPresentation(TestCase): diff --git a/packages/python/plotly/plotly/tests/test_core/test_graph_objs/test_scatter.py b/packages/python/plotly/plotly/tests/test_core/test_graph_objs/test_scatter.py index d3af52db2a4..78d3aa1d773 100644 --- a/packages/python/plotly/plotly/tests/test_core/test_graph_objs/test_scatter.py +++ b/packages/python/plotly/plotly/tests/test_core/test_graph_objs/test_scatter.py @@ -7,7 +7,6 @@ """ from __future__ import absolute_import -from nose.tools import raises from plotly.graph_objs import Scatter from plotly.exceptions import PlotlyError diff --git a/packages/python/plotly/plotly/tests/test_core/test_graph_objs/test_template.py b/packages/python/plotly/plotly/tests/test_core/test_graph_objs/test_template.py index 47bbf12b064..06f50fe8fd4 100644 --- a/packages/python/plotly/plotly/tests/test_core/test_graph_objs/test_template.py +++ b/packages/python/plotly/plotly/tests/test_core/test_graph_objs/test_template.py @@ -2,7 +2,7 @@ import copy from unittest import TestCase -from nose.tools import raises +import pytest import plotly.io as pio import plotly.graph_objs as go @@ -105,27 +105,27 @@ def test_defaults_in_property_assignment(self): }, ) - @raises(ValueError) def test_invalid_defaults_property_name_constructor(self): - go.Figure(layout={"template": {"layout": {"imagedefaults": {"bogus": 500}}}}) + with pytest.raises(ValueError): + go.Figure(layout={"template": {"layout": {"imagedefaults": {"bogus": 500}}}}) - @raises(ValueError) def test_invalid_defaults_property_value_constructor(self): - go.Figure( - layout={ + with pytest.raises(ValueError): + go.Figure( + layout={ "template": {"layout": {"imagedefaults": {"sizex": "str not number"}}} - } - ) + } + ) - @raises(ValueError) def test_invalid_defaults_property_name_constructor(self): - go.Figure(layout={"template": {"layout": {"xaxis": {"bogus": 500}}}}) + with pytest.raises(ValueError): + go.Figure(layout={"template": {"layout": {"xaxis": {"bogus": 500}}}}) - @raises(ValueError) def test_invalid_defaults_property_value_constructor(self): - go.Figure( - layout={"template": {"layout": {"xaxis": {"range": "str not tuple"}}}} - ) + with pytest.raises(ValueError): + go.Figure( + layout={"template": {"layout": {"xaxis": {"range": "str not tuple"}}}} + ) # plotly.io.template tests # ------------------------ diff --git a/packages/python/plotly/plotly/tests/test_core/test_offline/test_offline.py b/packages/python/plotly/plotly/tests/test_core/test_offline/test_offline.py index b922d4f5ec7..315a81b9417 100644 --- a/packages/python/plotly/plotly/tests/test_core/test_offline/test_offline.py +++ b/packages/python/plotly/plotly/tests/test_core/test_offline/test_offline.py @@ -6,8 +6,8 @@ import os from unittest import TestCase +import pytest -from nose.plugins.attrib import attr import json as _json import plotly @@ -314,7 +314,7 @@ def get_html(): self.assertIn('"bogus": 42', html) - @attr("nodev") + @pytest.mark.nodev def test_plotlyjs_version(self): path = os.path.join(packages_root, "javascript", "plotlywidget", "package.json") with open(path, "rt") as f: diff --git a/packages/python/plotly/plotly/tests/test_optional/test_matplotlylib/test_annotations.py b/packages/python/plotly/plotly/tests/test_optional/test_matplotlylib/test_annotations.py index 6d0b337cd73..18d8fb7c4b1 100644 --- a/packages/python/plotly/plotly/tests/test_optional/test_matplotlylib/test_annotations.py +++ b/packages/python/plotly/plotly/tests/test_optional/test_matplotlylib/test_annotations.py @@ -1,6 +1,6 @@ from __future__ import absolute_import -from nose.plugins.attrib import attr +import pytest from plotly import optional_imports @@ -14,7 +14,7 @@ from plotly.tests.test_optional.test_matplotlylib.data.annotations import * -@attr("matplotlib") +@pytest.mark.matplotlib def test_annotations(): fig, ax = plt.subplots() ax.plot([1, 2, 3], "b-") diff --git a/packages/python/plotly/plotly/tests/test_optional/test_matplotlylib/test_axis_scales.py b/packages/python/plotly/plotly/tests/test_optional/test_matplotlylib/test_axis_scales.py index 9063ce7319a..e7f0753da3a 100644 --- a/packages/python/plotly/plotly/tests/test_optional/test_matplotlylib/test_axis_scales.py +++ b/packages/python/plotly/plotly/tests/test_optional/test_matplotlylib/test_axis_scales.py @@ -1,6 +1,6 @@ from __future__ import absolute_import -from nose.plugins.attrib import attr +import pytest from plotly import optional_imports from plotly.tests.utils import compare_dict, strip_dict_params @@ -13,7 +13,7 @@ import matplotlib.pyplot as plt -@attr("matplotlib") +@pytest.mark.matplotlib def test_even_linear_scale(): fig, ax = plt.subplots() x = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] diff --git a/packages/python/plotly/plotly/tests/test_optional/test_matplotlylib/test_bars.py b/packages/python/plotly/plotly/tests/test_optional/test_matplotlylib/test_bars.py index 6a6df896150..2c4454cf22e 100644 --- a/packages/python/plotly/plotly/tests/test_optional/test_matplotlylib/test_bars.py +++ b/packages/python/plotly/plotly/tests/test_optional/test_matplotlylib/test_bars.py @@ -1,6 +1,5 @@ from __future__ import absolute_import - -from nose.plugins.attrib import attr +import pytest from plotly import optional_imports from plotly.tests.utils import compare_dict, strip_dict_params @@ -12,8 +11,7 @@ if matplotlylib: import matplotlib.pyplot as plt - -@attr("matplotlib") +@pytest.mark.matplotlib def test_vertical_bar(): fig, ax = plt.subplots() ax.bar(left=D["left"], height=D["height"]) @@ -33,7 +31,7 @@ def test_vertical_bar(): assert equivalent, msg -@attr("matplotlib") +@pytest.mark.matplotlib def test_horizontal_bar(): fig, ax = plt.subplots() ax.barh(bottom=D["bottom"], width=D["width"]) @@ -53,7 +51,7 @@ def test_horizontal_bar(): assert equivalent, msg -@attr("matplotlib") +@pytest.mark.matplotlib def test_h_and_v_bars(): fig, ax = plt.subplots() ax.bar( diff --git a/packages/python/plotly/plotly/tests/test_optional/test_matplotlylib/test_data.py b/packages/python/plotly/plotly/tests/test_optional/test_matplotlylib/test_data.py index 050432c8987..c9f71d63da1 100644 --- a/packages/python/plotly/plotly/tests/test_optional/test_matplotlylib/test_data.py +++ b/packages/python/plotly/plotly/tests/test_optional/test_matplotlylib/test_data.py @@ -1,6 +1,6 @@ from __future__ import absolute_import -from nose.plugins.attrib import attr +import pytest from plotly import optional_imports from plotly.tests.test_optional.optional_utils import run_fig @@ -11,8 +11,7 @@ if matplotlylib: import matplotlib.pyplot as plt - -@attr("matplotlib") +@pytest.mark.matplotlib def test_line_data(): fig, ax = plt.subplots() ax.plot(D["x1"], D["y1"]) @@ -31,7 +30,7 @@ def test_line_data(): ) -@attr("matplotlib") +@pytest.mark.matplotlib def test_lines_data(): fig, ax = plt.subplots() ax.plot(D["x1"], D["y1"]) @@ -63,7 +62,7 @@ def test_lines_data(): ) -@attr("matplotlib") +@pytest.mark.matplotlib def test_bar_data(): fig, ax = plt.subplots() ax.bar(D["x1"], D["y1"]) @@ -74,7 +73,7 @@ def test_bar_data(): ) -@attr("matplotlib") +@pytest.mark.matplotlib def test_bars_data(): fig, ax = plt.subplots() ax.bar(D["x1"], D["y1"], color="r") diff --git a/packages/python/plotly/plotly/tests/test_optional/test_matplotlylib/test_date_times.py b/packages/python/plotly/plotly/tests/test_optional/test_matplotlylib/test_date_times.py index ac4ee079e3d..68546749eb4 100644 --- a/packages/python/plotly/plotly/tests/test_optional/test_matplotlylib/test_date_times.py +++ b/packages/python/plotly/plotly/tests/test_optional/test_matplotlylib/test_date_times.py @@ -3,9 +3,9 @@ import datetime import random from unittest import TestCase +import pytest import pandas as pd -from nose.plugins.attrib import attr import plotly.tools as tls from plotly import optional_imports @@ -17,7 +17,7 @@ import matplotlib.pyplot as plt -@attr("matplotlib") +@pytest.mark.matplotlib class TestDateTimes(TestCase): def test_normal_mpl_dates(self): datetime_format = "%Y-%m-%d %H:%M:%S" diff --git a/packages/python/plotly/plotly/tests/test_optional/test_matplotlylib/test_lines.py b/packages/python/plotly/plotly/tests/test_optional/test_matplotlylib/test_lines.py index 642936aed13..bb69c18ecc3 100644 --- a/packages/python/plotly/plotly/tests/test_optional/test_matplotlylib/test_lines.py +++ b/packages/python/plotly/plotly/tests/test_optional/test_matplotlylib/test_lines.py @@ -1,6 +1,6 @@ from __future__ import absolute_import -from nose.plugins.attrib import attr +import pytest from plotly import optional_imports from plotly.tests.utils import compare_dict, strip_dict_params @@ -13,7 +13,7 @@ import matplotlib.pyplot as plt -@attr("matplotlib") +@pytest.mark.matplotlib def test_simple_line(): fig, ax = plt.subplots() ax.plot(D["x1"], D["y1"], label="simple") @@ -29,7 +29,7 @@ def test_simple_line(): assert equivalent, msg -@attr("matplotlib") +@pytest.mark.matplotlib def test_complicated_line(): fig, ax = plt.subplots() ax.plot(D["x1"], D["y1"], "ro", markersize=10, alpha=0.5, label="one") diff --git a/packages/python/plotly/plotly/tests/test_optional/test_matplotlylib/test_scatter.py b/packages/python/plotly/plotly/tests/test_optional/test_matplotlylib/test_scatter.py index 839880dc594..96984130d87 100644 --- a/packages/python/plotly/plotly/tests/test_optional/test_matplotlylib/test_scatter.py +++ b/packages/python/plotly/plotly/tests/test_optional/test_matplotlylib/test_scatter.py @@ -1,6 +1,5 @@ from __future__ import absolute_import - -from nose.plugins.attrib import attr +import pytest from plotly import optional_imports from plotly.tests.utils import compare_dict, strip_dict_params @@ -13,7 +12,7 @@ import matplotlib.pyplot as plt -@attr("matplotlib") +@pytest.mark.matplotlib def test_simple_scatter(): fig, ax = plt.subplots() ax.scatter(D["x1"], D["y1"]) @@ -33,7 +32,7 @@ def test_simple_scatter(): assert equivalent, msg -@attr("matplotlib") +@pytest.mark.matplotlib def test_double_scatter(): fig, ax = plt.subplots() ax.scatter(D["x1"], D["y1"], color="red", s=121, marker="^", alpha=0.5) diff --git a/packages/python/plotly/plotly/tests/test_optional/test_matplotlylib/test_subplots.py b/packages/python/plotly/plotly/tests/test_optional/test_matplotlylib/test_subplots.py index 4553eadeb43..6d4e0959dd2 100644 --- a/packages/python/plotly/plotly/tests/test_optional/test_matplotlylib/test_subplots.py +++ b/packages/python/plotly/plotly/tests/test_optional/test_matplotlylib/test_subplots.py @@ -1,6 +1,6 @@ from __future__ import absolute_import -from nose.plugins.attrib import attr +import pytest from plotly import optional_imports from plotly.tests.utils import compare_dict, strip_dict_params @@ -14,7 +14,7 @@ import matplotlib.pyplot as plt -@attr("matplotlib") +@pytest.mark.matplotlib def test_blank_subplots(): fig = plt.figure() gs = GridSpec(4, 6) diff --git a/packages/python/plotly/plotly/tests/test_optional/test_offline/test_offline.py b/packages/python/plotly/plotly/tests/test_optional/test_offline/test_offline.py index f16575d7c2e..d36934d1eae 100644 --- a/packages/python/plotly/plotly/tests/test_optional/test_offline/test_offline.py +++ b/packages/python/plotly/plotly/tests/test_optional/test_offline/test_offline.py @@ -4,11 +4,10 @@ """ from __future__ import absolute_import import re -from nose.tools import raises -from nose.plugins.attrib import attr import json as _json from unittest import TestCase +import pytest import plotly from plotly import optional_imports @@ -39,7 +38,7 @@ def test_iplot_works_after_you_call_init_notebook_mode(self): if matplotlylib: - @attr("matplotlib") + @pytest.mark.matplotlib def test_iplot_mpl_works(self): # Generate matplotlib plot for tests fig = plt.figure() @@ -64,7 +63,7 @@ def _read_html(self, file_url): if matplotlylib: - @attr("matplotlib") + @pytest.mark.matplotlib def test_default_mpl_plot_generates_expected_html(self): # Generate matplotlib plot for tests fig = plt.figure() diff --git a/packages/python/plotly/plotly/tests/test_optional/test_utils/test_utils.py b/packages/python/plotly/plotly/tests/test_optional/test_utils/test_utils.py index d26e7ac6cea..24d3702491f 100644 --- a/packages/python/plotly/plotly/tests/test_optional/test_utils/test_utils.py +++ b/packages/python/plotly/plotly/tests/test_optional/test_utils/test_utils.py @@ -9,11 +9,11 @@ import decimal from datetime import datetime as dt from unittest import TestCase +import pytest import numpy as np import pandas as pd import pytz -from nose.plugins.attrib import attr from pandas.util.testing import assert_series_equal import json as _json import os @@ -295,7 +295,7 @@ def test_pil_image_encoding(self): if matplotlylib: - @attr("matplotlib") + @pytest.mark.matplotlib def test_masked_constants_example(): # example from: https://gist.github.com/tschaume/d123d56bf586276adb98 data = { diff --git a/packages/python/plotly/pytest.ini b/packages/python/plotly/pytest.ini new file mode 100644 index 00000000000..3d05496c99b --- /dev/null +++ b/packages/python/plotly/pytest.ini @@ -0,0 +1,5 @@ +# content of pytest.ini +[pytest] +markers = + nodev: mark a test as nodev + matplotlib: mark a test as matplotlib From d369fcf80ca72e9cc2d78add97c59eca45fa76e6 Mon Sep 17 00:00:00 2001 From: Emmanuelle Gouillart Date: Thu, 20 Feb 2020 19:58:12 -0500 Subject: [PATCH 04/10] make black happy --- .../test_figure_widget_backend/test_validate_no_frames.py | 1 + .../tests/test_core/test_graph_objs/test_template.py | 8 ++++++-- .../tests/test_optional/test_matplotlylib/test_bars.py | 1 + .../tests/test_optional/test_matplotlylib/test_data.py | 1 + 4 files changed, 9 insertions(+), 2 deletions(-) diff --git a/packages/python/plotly/plotly/tests/test_core/test_figure_widget_backend/test_validate_no_frames.py b/packages/python/plotly/plotly/tests/test_core/test_figure_widget_backend/test_validate_no_frames.py index 7a9efdcc7a7..81f07496954 100644 --- a/packages/python/plotly/plotly/tests/test_core/test_figure_widget_backend/test_validate_no_frames.py +++ b/packages/python/plotly/plotly/tests/test_core/test_figure_widget_backend/test_validate_no_frames.py @@ -2,6 +2,7 @@ import plotly.graph_objs as go import pytest + class TestNoFrames(TestCase): if "FigureWidget" in go.__dict__.keys(): diff --git a/packages/python/plotly/plotly/tests/test_core/test_graph_objs/test_template.py b/packages/python/plotly/plotly/tests/test_core/test_graph_objs/test_template.py index 06f50fe8fd4..8010e962a92 100644 --- a/packages/python/plotly/plotly/tests/test_core/test_graph_objs/test_template.py +++ b/packages/python/plotly/plotly/tests/test_core/test_graph_objs/test_template.py @@ -107,13 +107,17 @@ def test_defaults_in_property_assignment(self): def test_invalid_defaults_property_name_constructor(self): with pytest.raises(ValueError): - go.Figure(layout={"template": {"layout": {"imagedefaults": {"bogus": 500}}}}) + go.Figure( + layout={"template": {"layout": {"imagedefaults": {"bogus": 500}}}} + ) def test_invalid_defaults_property_value_constructor(self): with pytest.raises(ValueError): go.Figure( layout={ - "template": {"layout": {"imagedefaults": {"sizex": "str not number"}}} + "template": { + "layout": {"imagedefaults": {"sizex": "str not number"}} + } } ) diff --git a/packages/python/plotly/plotly/tests/test_optional/test_matplotlylib/test_bars.py b/packages/python/plotly/plotly/tests/test_optional/test_matplotlylib/test_bars.py index 2c4454cf22e..40d891b941c 100644 --- a/packages/python/plotly/plotly/tests/test_optional/test_matplotlylib/test_bars.py +++ b/packages/python/plotly/plotly/tests/test_optional/test_matplotlylib/test_bars.py @@ -11,6 +11,7 @@ if matplotlylib: import matplotlib.pyplot as plt + @pytest.mark.matplotlib def test_vertical_bar(): fig, ax = plt.subplots() diff --git a/packages/python/plotly/plotly/tests/test_optional/test_matplotlylib/test_data.py b/packages/python/plotly/plotly/tests/test_optional/test_matplotlylib/test_data.py index c9f71d63da1..fc208573b51 100644 --- a/packages/python/plotly/plotly/tests/test_optional/test_matplotlylib/test_data.py +++ b/packages/python/plotly/plotly/tests/test_optional/test_matplotlylib/test_data.py @@ -11,6 +11,7 @@ if matplotlylib: import matplotlib.pyplot as plt + @pytest.mark.matplotlib def test_line_data(): fig, ax = plt.subplots() From 0fb9958f7dab06175cbd73f216f7e542d3079870 Mon Sep 17 00:00:00 2001 From: Emmanuelle Gouillart Date: Thu, 20 Feb 2020 21:13:32 -0500 Subject: [PATCH 05/10] Update packages/python/chart-studio/chart_studio/tests/test_optional/test_matplotlylib/test_plot_mpl.py --- .../tests/test_optional/test_matplotlylib/test_plot_mpl.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/python/chart-studio/chart_studio/tests/test_optional/test_matplotlylib/test_plot_mpl.py b/packages/python/chart-studio/chart_studio/tests/test_optional/test_matplotlylib/test_plot_mpl.py index e1c89017026..4e0dc6fa88c 100644 --- a/packages/python/chart-studio/chart_studio/tests/test_optional/test_matplotlylib/test_plot_mpl.py +++ b/packages/python/chart-studio/chart_studio/tests/test_optional/test_matplotlylib/test_plot_mpl.py @@ -19,7 +19,7 @@ if matplotlylib: import matplotlib.pyplot as plt - +@pytest.mark.matplotlib class PlotMPLTest(TestCase): def setUp(self): py.sign_in("PlotlyImageTest", "786r5mecv0", plotly_domain="https://plot.ly") From f2b60d804e2bc6ad9310a212cb9b18b7fb9fc09f Mon Sep 17 00:00:00 2001 From: Emmanuelle Gouillart Date: Thu, 20 Feb 2020 21:19:06 -0500 Subject: [PATCH 06/10] black --- .../tests/test_optional/test_matplotlylib/test_plot_mpl.py | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/python/chart-studio/chart_studio/tests/test_optional/test_matplotlylib/test_plot_mpl.py b/packages/python/chart-studio/chart_studio/tests/test_optional/test_matplotlylib/test_plot_mpl.py index 4e0dc6fa88c..a4b2bf52a5a 100644 --- a/packages/python/chart-studio/chart_studio/tests/test_optional/test_matplotlylib/test_plot_mpl.py +++ b/packages/python/chart-studio/chart_studio/tests/test_optional/test_matplotlylib/test_plot_mpl.py @@ -19,6 +19,7 @@ if matplotlylib: import matplotlib.pyplot as plt + @pytest.mark.matplotlib class PlotMPLTest(TestCase): def setUp(self): From dee2f7fb459da9d2d6c8eb83c36fdfaf2c2b86a9 Mon Sep 17 00:00:00 2001 From: Emmanuelle Gouillart Date: Mon, 2 Mar 2020 16:26:47 -0500 Subject: [PATCH 07/10] updated contributing notes and chart-studio tox.ini --- contributing.md | 24 +++++++++---------- packages/python/chart-studio/tox.ini | 13 +++++----- .../python/plotly/optional-requirements.txt | 1 - packages/python/plotly/tox.ini | 7 +++--- 4 files changed, 21 insertions(+), 24 deletions(-) diff --git a/contributing.md b/contributing.md index 82ed16b20ba..7565dc641ff 100644 --- a/contributing.md +++ b/contributing.md @@ -1,6 +1,6 @@ # Contributing -The bottom line. Follow your Nose, or our Nose. Write-run-love tests :fist:. +Thank you for contributing to plotly.py! ## Code of Conduct @@ -128,34 +128,34 @@ classes based on the new schema. We take advantage of two tools to run tests: * [`tox`](https://tox.readthedocs.io/en/latest/), which is both a virtualenv management and test tool. -* [`nose`](https://nose.readthedocs.org/en/latest/), which is is an extension of Python's unittest +* [`pytest`](https://docs.pytest.org/en/latest/), a powerful framework for unit testing. -### Running Tests with `nose` +### Running Tests with `pytest` Since our tests cover *all* the functionality, to prevent tons of errors from showing up and having to parse through a messy output, you'll need to install `optional-requirements.txt` as explained above. -After you've done that, go ahead and follow (y)our Nose! +After you've done that, go ahead and run the test suite! ```bash -nosetests -w packages/python/plotly/plotly/tests/ +pytest packages/python/plotly/plotly/tests/ ``` Or for more *verbose* output: ```bash -nosetests -w packages/python/plotly/plotly/tests/ -v +pytest -v packages/python/plotly/plotly/tests/ ``` Either of those will run *every* test we've written for the Python API. You can get more granular by running something like: ```bash -nosetests -w packages/python/plotly/plotly/tests/test_core/ +pytest packages/python/plotly/plotly/tests/test_core/ ``` ... or even more granular by running something like: ```bash -nosetests plotly/tests/test_plotly/test_plot.py +pytest plotly/tests/test_plotly/test_plot.py ``` ### Running tests with `tox` @@ -187,16 +187,16 @@ Where `TOXENV` is the environment list you want to use when invoking `tox` from * `tox` will automatically manage a virtual env for each environment you want to test in. * You only have to run `tox` and know that the module is working in both `Python 2` and `Python 3`. -Finally, `tox` allows you to pass in additional command line arguments that are formatted in (by us) in the `tox.ini` file, see `{posargs}`. This is setup to help with our `nose attr` configuration. To run only tests that are *not* tagged with `slow`, you could use the following command: +Finally, `tox` allows you to pass in additional command line arguments that are formatted in (by us) in the `tox.ini` file, see `{posargs}`. This is setup to help with our configuration of [pytest markers](http://doc.pytest.org/en/latest/example/markers.html), which are set up in `packages/python/plotly/pytest.ini`. To run only tests that are *not* tagged with `nodev`, you could use the following command: ```bash -tox -- -a '!slow' +tox -- -a '!nodev' ``` -Note that anything after `--` is substituted in for `{posargs}` in the tox.ini. For completeness, because it's reasonably confusing, if you want to force a match for *multiple* `nose attr` tags, you comma-separate the tags like so: +Note that anything after `--` is substituted in for `{posargs}` in the tox.ini. For completeness, because it's reasonably confusing, if you want to force a match for *multiple* `pytest` marker tags, you comma-separate the tags like so: ```bash -tox -- -a '!slow','!matplotlib' +tox -- -a '!nodev','!matplotlib' ``` ### Writing Tests diff --git a/packages/python/chart-studio/tox.ini b/packages/python/chart-studio/tox.ini index 4a43598e523..faddb36305f 100644 --- a/packages/python/chart-studio/tox.ini +++ b/packages/python/chart-studio/tox.ini @@ -24,15 +24,14 @@ ; PASSING ADDITONAL ARGUMENTS TO TEST COMMANDS ; The {posargs} is tox-specific and passes in any command line args after `--`. ; For example, given the testing command in *this* file: -; nosetests {posargs} -x plotly/tests/test_core +; pytest {posargs} -x plotly/tests/test_core ; ; The following command: -; tox -- -a '!slow' +; tox -- -k 'not nodev' ; ; Tells tox to call: -; nosetests -a '!slow' -x plotly/tests/test_core +; pytest -k 'not nodev' -x plotly/tests/test_core ; -; Which is a nice way to skip slow tests for faster testing cycles. [tox] ; The py{A,B,C}-{X,Y} generates a matrix of envs: @@ -72,16 +71,16 @@ deps= basepython={env:PLOTLY_TOX_PYTHON_27:} commands= python --version - nosetests {posargs} -x chart_studio/tests/ + pytest {posargs} -x chart_studio/tests/ [testenv:py35-plot_ly] basepython={env:PLOTLY_TOX_PYTHON_35:} commands= python --version - nosetests {posargs} -x chart_studio/tests/ + pytest {posargs} -x chart_studio/tests/ [testenv:py37-plot_ly] basepython={env:PLOTLY_TOX_PYTHON_37:} commands= python --version - nosetests {posargs} -x chart_studio/tests/ + pytest {posargs} -x chart_studio/tests/ diff --git a/packages/python/plotly/optional-requirements.txt b/packages/python/plotly/optional-requirements.txt index d0bb959e0d9..9886dcd1872 100644 --- a/packages/python/plotly/optional-requirements.txt +++ b/packages/python/plotly/optional-requirements.txt @@ -14,7 +14,6 @@ numpy ## testing dependencies ## coverage==4.3.1 mock==2.0.0 -nose==1.3.3 pytest==3.5.1 backports.tempfile==1.0 xarray diff --git a/packages/python/plotly/tox.ini b/packages/python/plotly/tox.ini index 268c1a2aecd..b1f1cca2f71 100644 --- a/packages/python/plotly/tox.ini +++ b/packages/python/plotly/tox.ini @@ -24,15 +24,14 @@ ; PASSING ADDITONAL ARGUMENTS TO TEST COMMANDS ; The {posargs} is tox-specific and passes in any command line args after `--`. ; For example, given the testing command in *this* file: -; nosetests {posargs} -x plotly/tests/test_core +; pytest {posargs} -x plotly/tests/test_core ; ; The following command: -; tox -- -a '!slow' +; tox -- -k 'not nodev' ; ; Tells tox to call: -; nosetests -a '!slow' -x plotly/tests/test_core +; pytest -k 'not nodev' -x plotly/tests/test_core ; -; Which is a nice way to skip slow tests for faster testing cycles. [tox] ; The py{A,B,C}-{X,Y} generates a matrix of envs: From 49ffe9463d427203552959cc1b4babf8b3183c7f Mon Sep 17 00:00:00 2001 From: Emmanuelle Gouillart Date: Tue, 3 Mar 2020 14:00:38 -0500 Subject: [PATCH 08/10] using pytest parametrize --- contributing.md | 6 + .../test_plot_ly/test_image/test_image.py | 114 +++++++----------- 2 files changed, 51 insertions(+), 69 deletions(-) diff --git a/contributing.md b/contributing.md index 7565dc641ff..ceaf5b9f63b 100644 --- a/contributing.md +++ b/contributing.md @@ -158,6 +158,12 @@ pytest packages/python/plotly/plotly/tests/test_core/ pytest plotly/tests/test_plotly/test_plot.py ``` +or for a specfic test function + +```bash +pytest plotly/tests/test_plotly/test_plot.py::test_function +``` + ### Running tests with `tox` Running tests with tox is much more powerful, but requires a bit more setup. diff --git a/packages/python/chart-studio/chart_studio/tests/test_plot_ly/test_image/test_image.py b/packages/python/chart-studio/chart_studio/tests/test_plot_ly/test_image/test_image.py index c4d43a636cd..5403dd6b3a4 100644 --- a/packages/python/chart-studio/chart_studio/tests/test_plot_ly/test_image/test_image.py +++ b/packages/python/chart-studio/chart_studio/tests/test_plot_ly/test_image/test_image.py @@ -5,77 +5,53 @@ import os import itertools import warnings - +import pytest import _plotly_utils.exceptions from chart_studio.plotly import plotly as py -from chart_studio.tests.utils import PlotlyTestCase - - -class TestImage(PlotlyTestCase): - def setUp(self): - super(TestImage, self).setUp() - py.sign_in("PlotlyImageTest", "786r5mecv0") - self.data = [{"x": [1, 2, 3], "y": [3, 1, 6]}] - - -def _generate_image_get_returns_valid_image_test(image_format, width, height, scale): - def test(self): - # TODO: better understand why this intermittently fails. See #649 - num_attempts = 5 - for i in range(num_attempts): - if i > 0: - warnings.warn("image test intermittently failed, retrying...") - try: - image = py.image.get(self.data, image_format, width, height, scale) - if image_format in ["png", "jpeg"]: - assert imghdr.what("", image) == image_format - return - except (KeyError, _plotly_utils.exceptions.PlotlyError): - if i == num_attempts - 1: - raise - - return test - - -def _generate_image_save_as_saves_valid_image(image_format, width, height, scale): - def _test(self): - f, filename = tempfile.mkstemp(".{}".format(image_format)) - py.image.save_as( - self.data, - filename, - format=image_format, - width=width, - height=height, - scale=scale, - ) - if image_format in ["png", "jpeg"]: - assert imghdr.what(filename) == image_format - else: - assert os.path.getsize(filename) > 0 - - os.remove(filename) - - return _test - - -kwargs = { - "format": ["png", "jpeg", "pdf", "svg", "emf"], - "width": [None, 300], - "height": [None, 300], - "scale": [None, 5], -} -for args in itertools.product( - kwargs["format"], kwargs["width"], kwargs["height"], kwargs["scale"] -): - for test_generator in [ - _generate_image_get_returns_valid_image_test, - _generate_image_save_as_saves_valid_image, - ]: +py.sign_in("PlotlyImageTest", "786r5mecv0") +data = [{"x": [1, 2, 3], "y": [3, 1, 6]}] + + +@pytest.mark.parametrize('image_format', ("png", "jpeg", "pdf", "svg", "emf")) +@pytest.mark.parametrize('width', (None, 300)) +@pytest.mark.parametrize('height', (None, 300)) +@pytest.mark.parametrize('scale', (None, 5)) +def test_image_get_returns_valid_image_test(image_format, width, height, scale): + # TODO: better understand why this intermittently fails. See #649 + num_attempts = 5 + for i in range(num_attempts): + if i > 0: + warnings.warn("image test intermittently failed, retrying...") + try: + image = py.image.get(data, image_format, width, height, scale) + if image_format in ["png", "jpeg"]: + assert imghdr.what("", image) == image_format + return + except (KeyError, _plotly_utils.exceptions.PlotlyError): + if i == num_attempts - 1: + raise + + +@pytest.mark.parametrize('image_format', ("png", "jpeg", "pdf", "svg", "emf")) +@pytest.mark.parametrize('width', (None, 300)) +@pytest.mark.parametrize('height', (None, 300)) +@pytest.mark.parametrize('scale', (None, 5)) +def test_image_save_as_saves_valid_image(image_format, width, height, scale): + f, filename = tempfile.mkstemp(".{}".format(image_format)) + py.image.save_as( + data, + filename, + format=image_format, + width=width, + height=height, + scale=scale, + ) + if image_format in ["png", "jpeg"]: + assert imghdr.what(filename) == image_format + else: + assert os.path.getsize(filename) > 0 + + os.remove(filename) - _test = test_generator(*args) - arg_string = ", ".join([str(a) for a in args]) - test_name = test_generator.__name__.replace("_generate", "test") - test_name += "({})".format(arg_string) - setattr(TestImage, test_name, _test) From ae19bc1023ff6f0bb87e066b5637c5cf12895350 Mon Sep 17 00:00:00 2001 From: Emmanuelle Gouillart Date: Tue, 3 Mar 2020 14:27:04 -0500 Subject: [PATCH 09/10] fixture --- .../test_plot_ly/test_image/test_image.py | 47 +++++++++++-------- 1 file changed, 27 insertions(+), 20 deletions(-) diff --git a/packages/python/chart-studio/chart_studio/tests/test_plot_ly/test_image/test_image.py b/packages/python/chart-studio/chart_studio/tests/test_plot_ly/test_image/test_image.py index 5403dd6b3a4..0d088203d88 100644 --- a/packages/python/chart-studio/chart_studio/tests/test_plot_ly/test_image/test_image.py +++ b/packages/python/chart-studio/chart_studio/tests/test_plot_ly/test_image/test_image.py @@ -10,17 +10,27 @@ import _plotly_utils.exceptions from chart_studio.plotly import plotly as py -py.sign_in("PlotlyImageTest", "786r5mecv0") -data = [{"x": [1, 2, 3], "y": [3, 1, 6]}] +from chart_studio.tests.utils import PlotlyTestCase -@pytest.mark.parametrize('image_format', ("png", "jpeg", "pdf", "svg", "emf")) -@pytest.mark.parametrize('width', (None, 300)) -@pytest.mark.parametrize('height', (None, 300)) -@pytest.mark.parametrize('scale', (None, 5)) -def test_image_get_returns_valid_image_test(image_format, width, height, scale): +@pytest.fixture +def setup_image(): + py.sign_in("PlotlyImageTest", "786r5mecv0") + data = [{"x": [1, 2, 3], "y": [3, 1, 6]}] + + return data + + +@pytest.mark.parametrize("image_format", ("png", "jpeg", "pdf", "svg", "emf")) +@pytest.mark.parametrize("width", (None, 300)) +@pytest.mark.parametrize("height", (None, 300)) +@pytest.mark.parametrize("scale", (None, 3)) +def test_image_get_returns_valid_image_test( + setup_image, image_format, width, height, scale +): # TODO: better understand why this intermittently fails. See #649 - num_attempts = 5 + data = setup_image + num_attempts = 2 for i in range(num_attempts): if i > 0: warnings.warn("image test intermittently failed, retrying...") @@ -34,19 +44,17 @@ def test_image_get_returns_valid_image_test(image_format, width, height, scale): raise -@pytest.mark.parametrize('image_format', ("png", "jpeg", "pdf", "svg", "emf")) -@pytest.mark.parametrize('width', (None, 300)) -@pytest.mark.parametrize('height', (None, 300)) -@pytest.mark.parametrize('scale', (None, 5)) -def test_image_save_as_saves_valid_image(image_format, width, height, scale): +@pytest.mark.parametrize("image_format", ("png", "jpeg", "pdf", "svg", "emf")) +@pytest.mark.parametrize("width", (None, 300)) +@pytest.mark.parametrize("height", (None, 300)) +@pytest.mark.parametrize("scale", (None, 3)) +def test_image_save_as_saves_valid_image( + setup_image, image_format, width, height, scale +): + data = setup_image() f, filename = tempfile.mkstemp(".{}".format(image_format)) py.image.save_as( - data, - filename, - format=image_format, - width=width, - height=height, - scale=scale, + data, filename, format=image_format, width=width, height=height, scale=scale, ) if image_format in ["png", "jpeg"]: assert imghdr.what(filename) == image_format @@ -54,4 +62,3 @@ def test_image_save_as_saves_valid_image(image_format, width, height, scale): assert os.path.getsize(filename) > 0 os.remove(filename) - From 5963c98b1305459fc2e0d56deab12e9114752b5e Mon Sep 17 00:00:00 2001 From: Emmanuelle Gouillart Date: Tue, 3 Mar 2020 14:36:30 -0500 Subject: [PATCH 10/10] bug --- .../chart_studio/tests/test_plot_ly/test_image/test_image.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/python/chart-studio/chart_studio/tests/test_plot_ly/test_image/test_image.py b/packages/python/chart-studio/chart_studio/tests/test_plot_ly/test_image/test_image.py index 0d088203d88..594454d7f13 100644 --- a/packages/python/chart-studio/chart_studio/tests/test_plot_ly/test_image/test_image.py +++ b/packages/python/chart-studio/chart_studio/tests/test_plot_ly/test_image/test_image.py @@ -51,7 +51,7 @@ def test_image_get_returns_valid_image_test( def test_image_save_as_saves_valid_image( setup_image, image_format, width, height, scale ): - data = setup_image() + data = setup_image f, filename = tempfile.mkstemp(".{}".format(image_format)) py.image.save_as( data, filename, format=image_format, width=width, height=height, scale=scale,