Skip to content

Commit 6c01e81

Browse files
committed
refactor: get tests/**/*.py to pass ruff check .
1 parent 5b9b731 commit 6c01e81

File tree

65 files changed

+297
-440
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+297
-440
lines changed

tests/percy/plotly-express.py

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@
99
# this directory
1010
dir_name = os.path.join("tests", "percy")
1111

12-
# #### Scatter and Line plots
13-
12+
# Scatter and Line plots
1413

1514
iris = px.data.iris()
1615
fig = px.scatter(iris, x="sepal_width", y="sepal_length")
@@ -196,8 +195,7 @@
196195
fig = px.area(gapminder, x="year", y="pop", color="continent", line_group="country")
197196
fig.write_html(os.path.join(dir_name, "area.html"))
198197

199-
# #### Visualize Distributions
200-
198+
# Visualize Distributions
201199

202200
iris = px.data.iris()
203201
fig = px.density_contour(iris, x="sepal_width", y="sepal_length")
@@ -286,8 +284,7 @@
286284
)
287285
fig.write_html(os.path.join(dir_name, "violin.html"))
288286

289-
# #### Ternary Coordinates
290-
287+
# Ternary Coordinates
291288

292289
election = px.data.election()
293290
fig = px.scatter_ternary(
@@ -318,8 +315,7 @@
318315
fig = px.imshow(img_rgb)
319316
fig.write_html(os.path.join(dir_name, "imshow.html"))
320317

321-
# #### 3D Coordinates
322-
318+
# 3D Coordinates
323319

324320
election = px.data.election()
325321
fig = px.scatter_3d(
@@ -342,8 +338,7 @@
342338
)
343339
fig.write_html(os.path.join(dir_name, "line_3d.html"))
344340

345-
# #### Polar Coordinates
346-
341+
# Polar Coordinates
347342

348343
wind = px.data.wind()
349344
fig = px.scatter_polar(
@@ -380,8 +375,7 @@
380375
)
381376
fig.write_html(os.path.join(dir_name, "bar_polar.html"))
382377

383-
# #### Maps
384-
378+
# Maps
385379

386380
carshare = px.data.carshare()
387381
fig = px.scatter_map(

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-
import plotly.tools as tls
43
from plotly.exceptions import PlotlyError
54
import plotly.colors as colors
65

tests/test_core/test_errors/test_dict_path_errors.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import plotly.graph_objects as go
2-
from _plotly_utils.exceptions import PlotlyKeyError
32
import pytest
43
import sys
54

@@ -23,7 +22,7 @@ def test_raises_on_bad_index(some_fig):
2322
# Check indexing errors can be detected when path used as key to go.Figure
2423
raised = False
2524
try:
26-
x0 = some_fig["layout.shapes[2].x0"]
25+
some_fig["layout.shapes[2].x0"]
2726
except KeyError as e:
2827
raised = True
2928
assert (
@@ -43,7 +42,7 @@ def test_raises_on_bad_dot_property(some_fig):
4342
# go.Figure
4443
raised = False
4544
try:
46-
x2000 = some_fig["layout.shapes[1].x2000"]
45+
some_fig["layout.shapes[1].x2000"]
4746
except KeyError as e:
4847
raised = True
4948
assert (
@@ -62,7 +61,7 @@ def test_raises_on_bad_ancestor_dot_property(some_fig):
6261
# Check . property lookup errors but not on the last part of the path
6362
raised = False
6463
try:
65-
x2000 = some_fig["layout.shapa[1].x2000"]
64+
some_fig["layout.shapa[1].x2000"]
6665
except KeyError as e:
6766
raised = True
6867
assert (
@@ -181,7 +180,7 @@ def test_raises_on_bad_indexed_underscore_property(some_fig):
181180
# BaseFigure and throws the error for the last good property found in
182181
# the path
183182
try:
184-
fig2 = go.Figure(layout=dict(title=dict(txt="two")))
183+
go.Figure(layout=dict(title=dict(txt="two")))
185184
except ValueError as e_correct:
186185
raised = True
187186
e_correct_substr = error_substr(
@@ -195,7 +194,7 @@ def test_raises_on_bad_indexed_underscore_property(some_fig):
195194

196195
raised = False
197196
try:
198-
fig2 = go.Figure(layout_title_txt="two")
197+
go.Figure(layout_title_txt="two")
199198
except TypeError as e:
200199
raised = True
201200
# when the Figure constructor sees the same ValueError above, a
@@ -421,14 +420,14 @@ def test_subscript_error_exception_types(some_fig):
421420
with pytest.raises(ValueError):
422421
some_fig.update_layout(width_yo=100)
423422
with pytest.raises(KeyError):
424-
yo = some_fig["layout_width_yo"]
423+
some_fig["layout_width_yo"]
425424

426425
some_fig.update_layout(width=100)
427426
# when width is specified
428427
with pytest.raises(ValueError):
429428
some_fig.update_layout(width_yo=100)
430429
with pytest.raises(KeyError):
431-
yo = some_fig["layout_width_yo"]
430+
some_fig["layout_width_yo"]
432431

433432

434433
def form_error_string(call, exception, subs):

tests/test_core/test_figure_messages/test_add_traces.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
1-
import sys
21
from unittest import TestCase
32

43
import plotly.graph_objs as go
54
from plotly.subplots import make_subplots
65

7-
if sys.version_info >= (3, 3):
8-
from unittest.mock import MagicMock
9-
else:
10-
from mock import MagicMock
6+
from unittest.mock import MagicMock
117

128

139
class TestAddTracesMessage(TestCase):
@@ -56,8 +52,6 @@ def test_add_traces(self):
5652
self.assertEqual(self.figure.data[-1].line.color, "cyan")
5753

5854
# Check message
59-
new_uid1 = self.figure.data[-2].uid
60-
new_uid2 = self.figure.data[-1].uid
6155
self.figure._send_addTraces_msg.assert_called_once_with(
6256
[
6357
{"type": "sankey", "arrangement": "snap"},

tests/test_core/test_figure_messages/test_batch_animate.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
1-
import sys
21
from unittest import TestCase
32

43
import plotly.graph_objs as go
54

6-
if sys.version_info >= (3, 3):
7-
from unittest.mock import MagicMock
8-
else:
9-
from mock import MagicMock
5+
from unittest.mock import MagicMock
106

117

128
class TestBatchAnimateMessage(TestCase):

tests/test_core/test_figure_messages/test_move_delete_traces.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
1-
import sys
21
from unittest import TestCase
32
import pytest
43

54
import plotly.graph_objs as go
65

7-
if sys.version_info >= (3, 3):
8-
from unittest.mock import MagicMock
9-
else:
10-
from mock import MagicMock
6+
from unittest.mock import MagicMock
117

128

139
class TestMoveDeleteTracesMessages(TestCase):

tests/test_core/test_figure_messages/test_on_change.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
1-
import sys
21
from unittest import TestCase
32
import pytest
43

54
import plotly.graph_objs as go
65

7-
if sys.version_info >= (3, 3):
8-
from unittest.mock import MagicMock
9-
else:
10-
from mock import MagicMock
6+
from unittest.mock import MagicMock
117

128

139
class TestOnChangeCallbacks(TestCase):
@@ -35,12 +31,12 @@ def test_raise_on_frame_hierarchy(self):
3531
with pytest.raises(ValueError):
3632
self.figure.frames[0].layout.xaxis.on_change(fn, "range")
3733

38-
def test_validate_property_path_nested(self):
34+
def test_validate_property_path_nested_1(self):
3935
fn = MagicMock()
4036
with pytest.raises(ValueError):
4137
self.figure.layout.xaxis.on_change(fn, "bogus")
4238

43-
def test_validate_property_path_nested(self):
39+
def test_validate_property_path_nested_2(self):
4440
fn = MagicMock()
4541
with pytest.raises(ValueError):
4642
self.figure.layout.on_change(fn, "xaxis.title_font.bogus")

tests/test_core/test_figure_messages/test_plotly_relayout.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
1-
import sys
21
from unittest import TestCase
32

43
import plotly.graph_objs as go
54

6-
if sys.version_info >= (3, 3):
7-
from unittest.mock import MagicMock
8-
else:
9-
from mock import MagicMock
5+
from unittest.mock import MagicMock
106

117

128
class TestRelayoutMessage(TestCase):

tests/test_core/test_figure_messages/test_plotly_restyle.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
1-
import sys
21
from unittest import TestCase
32

43
import plotly.graph_objs as go
54

6-
if sys.version_info >= (3, 3):
7-
from unittest.mock import MagicMock
8-
else:
9-
from mock import MagicMock
5+
from unittest.mock import MagicMock
106

117

128
class TestRestyleMessage(TestCase):

tests/test_core/test_figure_messages/test_plotly_update.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
1-
import sys
21
from unittest import TestCase
32

43
import plotly.graph_objs as go
54
from plotly.basedatatypes import Undefined
65

7-
if sys.version_info >= (3, 3):
8-
from unittest.mock import MagicMock
9-
else:
10-
from mock import MagicMock
6+
from unittest.mock import MagicMock
117

128

139
class TestBatchUpdateMessage(TestCase):

tests/test_core/test_figure_widget_backend/test_missing_anywidget.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
import pytest
22

33
# Use wildcard import to make sure FigureWidget is always included
4-
from plotly.graph_objects import *
5-
from plotly.missing_anywidget import FigureWidget as FigureWidgetMissingAnywidget
4+
from plotly.graph_objects import FigureWidget
65

76
try:
8-
import anywidget as _anywidget
9-
7+
from plotly.missing_anywidget import FigureWidget as FigureWidgetMissingAnywidget
108
missing_anywidget = False
119
except Exception:
1210
missing_anywidget = True

tests/test_core/test_figure_widget_backend/test_validate_initialization.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
import plotly.graph_objs as go
3-
import pytest
43

54
try:
65
go.FigureWidget()

tests/test_core/test_graph_objs/test_annotations.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,8 @@
66
77
"""
88

9-
from unittest import skip
10-
11-
from plotly.exceptions import (
12-
PlotlyError,
13-
PlotlyDictKeyError,
14-
PlotlyDictValueError,
15-
PlotlyListEntryError,
16-
)
17-
from plotly.graph_objs import Annotation, Annotations, Data, Figure, Layout
9+
10+
from plotly.graph_objs import Annotations, Data
1811

1912

2013
def setup():

tests/test_core/test_graph_objs/test_append_trace.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
import plotly.tools as tls
1616

17-
import copy
1817

1918

2019
def test_print_grid_before_make_subplots():

tests/test_core/test_graph_objs/test_data.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,9 @@
66
77
"""
88

9-
from unittest import skip
109

1110

12-
from plotly.exceptions import (
13-
PlotlyError,
14-
PlotlyDictKeyError,
15-
PlotlyDictValueError,
16-
PlotlyDataTypeError,
17-
PlotlyListEntryError,
18-
)
19-
from plotly.graph_objs import Annotations, Data, Figure, Layout
11+
from plotly.graph_objs import Annotations, Data
2012

2113

2214
def setup():

tests/test_core/test_graph_objs/test_error_bars.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
"""
88

99
from plotly.graph_objs import ErrorX, ErrorY
10-
from plotly.exceptions import PlotlyDictKeyError
1110

1211

1312
def test_instantiate_error_x():

tests/test_core/test_graph_objs/test_figure_properties.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,19 +82,19 @@ def test_property_assignment_dots(self):
8282
self.figure["frames[0].layout.yaxis.title.text"] = "f2"
8383
self.assertEqual(self.figure["frames.0.layout.yaxis.title.text"], "f2")
8484

85-
def test_access_invalid_attr(self):
85+
def test_access_invalid_attr_1(self):
8686
with pytest.raises(AttributeError):
8787
self.figure.bogus
8888

89-
def test_access_invalid_item(self):
89+
def test_access_invalid_item_1(self):
9090
with pytest.raises(KeyError):
9191
self.figure["bogus"]
9292

93-
def test_assign_invalid_attr(self):
93+
def test_assign_invalid_attr_2(self):
9494
with pytest.raises(AttributeError):
9595
self.figure.bogus = "val"
9696

97-
def test_access_invalid_item(self):
97+
def test_access_invalid_item_2(self):
9898
with pytest.raises(KeyError):
9999
self.figure["bogus"] = "val"
100100

tests/test_core/test_graph_objs/test_layout_subplots.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ def test_initial_access_subplots(self):
3434
self.assertIs(self.layout.mapbox, self.layout.mapbox1)
3535
self.assertIs(self.layout.polar, self.layout.polar1)
3636

37-
def test_initial_access_subplot2(self):
37+
def test_initial_access_subplot2_1(self):
3838
with pytest.raises(AttributeError):
3939
self.layout.xaxis2
4040

41-
def test_initial_access_subplot2(self):
41+
def test_initial_access_subplot2_2(self):
4242
with pytest.raises(KeyError):
4343
self.layout["xaxis2"]
4444

tests/test_core/test_graph_objs/test_scatter.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
"""
88

99
from plotly.graph_objs import Scatter
10-
from plotly.exceptions import PlotlyError
1110

1211

1312
def test_trivial():

0 commit comments

Comments
 (0)