Skip to content

Commit 7574767

Browse files
committed
Fix pytest.raises usage and improve tests
1 parent 88fdd44 commit 7574767

File tree

2 files changed

+19
-13
lines changed

2 files changed

+19
-13
lines changed

seaborn/_marks/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ def _resolve(
178178
try:
179179
feature = scale(value)
180180
except Exception as err:
181-
raise PlotSpecError._during("Scale operation", name) from err
181+
raise PlotSpecError._during("Scaling operation", name) from err
182182

183183
if return_array:
184184
feature = np.asarray(feature)

tests/_core/test_plot.py

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@
1919
from seaborn._core.moves import Move, Shift, Dodge
2020
from seaborn._core.rules import categorical_order
2121
from seaborn._core.exceptions import PlotSpecError
22-
from seaborn._stats.aggregation import Agg
2322
from seaborn._marks.base import Mark
2423
from seaborn._stats.base import Stat
24+
from seaborn._marks.dot import Dot
25+
from seaborn._stats.aggregation import Agg
2526
from seaborn.external.version import Version
2627

2728
assert_vector_equal = functools.partial(
@@ -1261,8 +1262,8 @@ def test_scale_setup(self):
12611262
msg = "Scale setup failed for the `color` variable."
12621263
with pytest.raises(PlotSpecError, match=msg) as err:
12631264
p.plot()
1264-
assert isinstance(err.__cause__, ValueError)
1265-
assert bad_palette in str(err.__cause__)
1265+
assert isinstance(err.value.__cause__, ValueError)
1266+
assert bad_palette in str(err.value.__cause__)
12661267

12671268
def test_coordinate_scaling(self):
12681269

@@ -1273,24 +1274,29 @@ def test_coordinate_scaling(self):
12731274
msg = "Scaling operation failed for the `x` variable."
12741275
with pytest.raises(PlotSpecError, match=msg) as err:
12751276
p.plot()
1276-
# Don't test the cause contents b/c matplotlib own them here.
1277-
assert hasattr(err, "__cause__")
1277+
# Don't test the cause contents b/c matplotlib owns them here.
1278+
assert hasattr(err.value, "__cause__")
12781279

12791280
def test_semantic_scaling(self):
12801281

1281-
class ErrorRaisingScale(Continuous):
1282+
class ErrorRaising(Continuous):
1283+
1284+
def _setup(self, data, prop, axis=None):
12821285

1283-
def _setup(self, data, prop, axis):
12841286
def f(x):
12851287
raise ValueError("This is a test")
1286-
return f
1288+
1289+
new = super()._setup(data, prop, axis)
1290+
new._pipeline = [f]
1291+
return new
12871292

12881293
x = y = color = [1, 2]
1289-
p = Plot(x, y, color=color).add(MockMark()).scale(color=ErrorRaisingScale())
1290-
with pytest.raises(PlotSpecError) as err:
1294+
p = Plot(x, y, color=color).add(Dot()).scale(color=ErrorRaising())
1295+
msg = "Scaling operation failed for the `color` variable."
1296+
with pytest.raises(PlotSpecError, match=msg) as err:
12911297
p.plot()
1292-
assert isinstance(err.__cause__, ValueError)
1293-
assert str(err.__cause__) == "This is a test"
1298+
assert isinstance(err.value.__cause__, ValueError)
1299+
assert str(err.value.__cause__) == "This is a test"
12941300

12951301

12961302
class TestFacetInterface:

0 commit comments

Comments
 (0)