Skip to content

Commit d6459ad

Browse files
authored
Merge pull request #3474 from pygame-community/ankith26-window-tests
Fix and improve `pygame.Window` tests
2 parents 5541963 + 94f71fc commit d6459ad

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

src_c/window.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -920,6 +920,11 @@ window_get_opengl(pgWindowObject *self, void *v)
920920
hasGL = self->context != NULL;
921921
}
922922
else {
923+
/* This is not a reliable way to test that OPENGL was requested by the
924+
* user. SDL can implicitly create and use an opengl context in some
925+
* platforms and in that case hasGL=1 even when the user didn't
926+
* request for it. As borrowed windows are deprecated functionality we
927+
* can ignore this issue. */
923928
hasGL = (SDL_GetWindowFlags(self->_win) & SDL_WINDOW_OPENGL) > 0;
924929
}
925930
return PyBool_FromLong(hasGL);

test/window_test.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,9 @@ def test_size(self):
150150
self.win.size = (640, 480)
151151

152152
def test_position(self):
153-
self.win.position = (12, 34)
154-
self.assertTupleEqual(self.win.position, (12, 34))
153+
new_pos = (self.win.position[0] + 20, self.win.position[1] + 10)
154+
self.win.position = new_pos
155+
self.assertTupleEqual(self.win.position, new_pos)
155156

156157
self.win.position = pygame.WINDOWPOS_CENTERED
157158

@@ -323,13 +324,13 @@ def test_window_object_repr(self):
323324
pygame.init()
324325

325326
def test_from_display_module(self):
326-
pygame.display.set_mode((640, 480))
327+
surf = pygame.display.set_mode((640, 480))
327328

328329
win1 = Window.from_display_module()
329330
win2 = Window.from_display_module()
330331

331332
self.assertIs(win1, win2)
332-
self.assertFalse(win1.opengl)
333+
self.assertIs(win1.get_surface(), surf)
333334

334335
pygame.display.quit()
335336
pygame.init()

0 commit comments

Comments
 (0)