Skip to content

Fix exception type when Window.show_view is passed a non-View #1876

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

Merged
merged 4 commits into from
Aug 15, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 3 additions & 2 deletions arcade/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -721,8 +721,9 @@ def show_view(self, new_view: 'View'):
:param View new_view: View to show
"""
if not isinstance(new_view, View):
raise ValueError("Must pass an arcade.View object to "
f"Window.show_view() {type(new_view)}")
raise TypeError(
f"Window.show_view() takes an arcade.View,"
f"but it got a {type(new_view)}.")

# Store the Window that is showing the "new_view" View.
if new_view.window is None:
Expand Down
6 changes: 6 additions & 0 deletions tests/unit/window/test_window.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import pytest

import arcade
import pyglet

Expand All @@ -14,6 +16,10 @@ def test_window(window: arcade.Window):
w = arcade.get_window()
assert w is not None

for not_a_view in ("string", 1, ("not", "a", "view")):
with pytest.raises(TypeError):
w.show_view(not_a_view)

# NOTE: Window managers can enforce difference sizes
# Make sure the arguments get passed to the window
# assert w.width == width
Expand Down