Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 01fdf1b

Browse files
aditya-singh597Aditya Singh
andauthored
Add tests for invalid properties and duplicate aliases in Artist.set (#31041)
* Add test for invalid property names passed to setp * Fix blank line spacing for ruff * Add tests for error handling in Artist.set * Fix trailing whitespace in test_artist --------- Co-authored-by: Aditya Singh <[email protected]>
1 parent be57aac commit 01fdf1b

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

lib/matplotlib/tests/test_artist.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,26 @@ def test_setp():
259259
assert sio.getvalue() == ' zorder: float\n'
260260

261261

262+
def test_artist_set_invalid_property_raises():
263+
"""
264+
Test that set() raises AttributeError for invalid property names.
265+
"""
266+
line = mlines.Line2D([0, 1], [0, 1])
267+
268+
with pytest.raises(AttributeError, match="unexpected keyword argument"):
269+
line.set(not_a_property=1)
270+
271+
272+
def test_artist_set_duplicate_aliases_raises():
273+
"""
274+
Test that set() raises TypeError when both a property and its alias are provided.
275+
"""
276+
line = mlines.Line2D([0, 1], [0, 1])
277+
278+
with pytest.raises(TypeError, match="aliases of one another"):
279+
line.set(lw=2, linewidth=3)
280+
281+
262282
def test_None_zorder():
263283
fig, ax = plt.subplots()
264284
ln, = ax.plot(range(5), zorder=None)

0 commit comments

Comments
 (0)