From f0b8bfafa28fbb932f327994a09e221405ad34b9 Mon Sep 17 00:00:00 2001 From: Joras Oliveira <43121361+JorasOliveira@users.noreply.github.com> Date: Fri, 20 Oct 2023 03:54:47 -0300 Subject: [PATCH] Fix issue #2109: Added requested tests (#2492) * Fix issue #2109: Added requested tests * isolated test that only works when not using pypy * Apply formatting * formatting * formatting * added requested changes and merged latest main branch * implemented requested changes, added more scenarios to test --------- Co-authored-by: Dan Lawrence --- test/surface_test.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/test/surface_test.py b/test/surface_test.py index 68a053fdf8..4c61d72bf4 100644 --- a/test/surface_test.py +++ b/test/surface_test.py @@ -621,8 +621,24 @@ def test_get_rect(self): size = (16, 16) surf = pygame.Surface(size) rect = surf.get_rect() + rect_kwargs = surf.get_rect(topleft=(1.0, 1.0), center=(100, 100)) + self.assertEqual(rect.topleft, (0.0, 0.0)) self.assertEqual(rect.size, size) + self.assertIsInstance(rect, pygame.Rect) + self.assertEqual(rect_kwargs.center, (100, 100)) + self.assertNotEqual(rect_kwargs.topleft, (1.0, 1.0)) + self.assertRaises(TypeError, surf.get_rect, 5) + self.assertRaises(TypeError, surf.get_rect, 5.0) + self.assertRaises(TypeError, surf.get_rect, "potato") + self.assertRaises(TypeError, surf.get_rect, center=5) + self.assertRaises(TypeError, surf.get_rect, center=(5,)) + self.assertRaises(TypeError, surf.get_rect, center="5") + if ( + not IS_PYPY + ): # PyPy doesn't raise an AttributeError, so for PyPy we can just skip it. + with self.assertRaises(AttributeError): + surf.get_rect(centre=(100, 100)) ######################################################################## @@ -631,10 +647,21 @@ def test_get_frect(self): size = (16.0, 16.0) surf = pygame.Surface(size) frect = surf.get_frect() + frect_kwargs = surf.get_frect(topleft=(1.0, 1.0), center=(100, 100)) self.assertEqual(frect.topleft, (0.0, 0.0)) self.assertEqual(frect.size, size) self.assertIsInstance(frect, pygame.FRect) + self.assertEqual(frect_kwargs.center, (100, 100)) + self.assertNotEqual(frect_kwargs.topleft, (1.0, 1.0)) + self.assertRaises(TypeError, surf.get_frect, 5) + self.assertRaises(TypeError, surf.get_frect, center=5) + self.assertRaises(TypeError, surf.get_frect, center="5") + if ( + not IS_PYPY + ): # PyPy doesn't raise an AttributeError, so for PyPy we can just skip it. + with self.assertRaises(AttributeError): + surf.get_frect(centre=(100, 100)) ########################################################################