Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

attempt to replace nose with pytest #2217

Merged
merged 10 commits into from
Mar 3, 2020
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,40 +7,37 @@
"""
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")

if matplotlylib:
import matplotlib.pyplot as plt


emmanuelle marked this conversation as resolved.
Show resolved Hide resolved
@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])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -38,15 +37,13 @@ def is_trivial(obj):


class GetFigureTest(PlotlyTestCase):
@attr("slow")
def test_get_figure(self):
un = "PlotlyImageTest"
ak = "786r5mecv0"
file_id = 13183
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"
Expand All @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand All @@ -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
Expand All @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -54,19 +53,16 @@ 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(
random_filename(), random_filename()
)
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()
Expand All @@ -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(
Expand All @@ -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)
Expand Down Expand Up @@ -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"]]
Expand All @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -33,15 +32,13 @@ 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)

# 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])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)}],
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)),
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import sys
from unittest import TestCase
from nose.tools import raises
import pytest

import plotly.graph_objs as go

Expand Down Expand Up @@ -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]]
Loading