Skip to content

Fix and improve pygame.Window tests #3474

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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: 5 additions & 0 deletions src_c/window.c
Original file line number Diff line number Diff line change
Expand Up @@ -911,6 +911,11 @@ window_get_opengl(pgWindowObject *self, void *v)
hasGL = self->context != NULL;
}
else {
/* This is not a reliable way to test that OPENGL was requested by the
* user. SDL can implicitly create and use an opengl context in some
* platforms and in that case hasGL=1 even when the user didn't
* request for it. As borrowed windows are deprecated functionality we
* can ignore this issue. */
hasGL = (SDL_GetWindowFlags(self->_win) & SDL_WINDOW_OPENGL) > 0;
}
return PyBool_FromLong(hasGL);
Expand Down
9 changes: 5 additions & 4 deletions test/window_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,9 @@ def test_size(self):
self.win.size = (640, 480)

def test_position(self):
self.win.position = (12, 34)
self.assertTupleEqual(self.win.position, (12, 34))
new_pos = (self.win.position[0] + 20, self.win.position[1] + 10)
self.win.position = new_pos
self.assertTupleEqual(self.win.position, new_pos)

self.win.position = pygame.WINDOWPOS_CENTERED

Expand Down Expand Up @@ -323,13 +324,13 @@ def test_window_object_repr(self):
pygame.init()

def test_from_display_module(self):
pygame.display.set_mode((640, 480))
surf = pygame.display.set_mode((640, 480))

win1 = Window.from_display_module()
win2 = Window.from_display_module()

self.assertIs(win1, win2)
self.assertFalse(win1.opengl)
self.assertIs(win1.get_surface(), surf)

pygame.display.quit()
pygame.init()
Expand Down
Loading