Skip to content

Commit

Permalink
Fix issue #2109: Added requested tests (#2492)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
JorasOliveira and MyreMylar authored Oct 20, 2023
1 parent c8d952a commit f0b8bfa
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions test/surface_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))

########################################################################

Expand All @@ -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))

########################################################################

Expand Down

0 comments on commit f0b8bfa

Please sign in to comment.