From db943d1425e4de465e5df85df83c5d28e2f627de Mon Sep 17 00:00:00 2001 From: Jan-Eric Nitschke Date: Thu, 11 Sep 2025 07:31:27 +0200 Subject: [PATCH 1/2] Add tests for Turtle.dot signature --- Lib/test/test_turtle.py | 45 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 41 insertions(+), 4 deletions(-) diff --git a/Lib/test/test_turtle.py b/Lib/test/test_turtle.py index d02cac284a909a..be7867d552f003 100644 --- a/Lib/test/test_turtle.py +++ b/Lib/test/test_turtle.py @@ -60,12 +60,25 @@ def patch_screen(): We must patch the _Screen class itself instead of the _Screen instance because instantiating it requires a display. """ + # Create a mock screen that delegates color validation to the real TurtleScreen methods + mock_screen = unittest.mock.MagicMock() + mock_screen.__class__ = turtle._Screen + mock_screen.mode.return_value = "standard" + mock_screen._colormode = 1.0 + + def mock_iscolorstring(color): + valid_colors = {'red', 'green', 'blue', 'black', 'white', 'yellow', + 'orange', 'purple', 'pink', 'brown', 'gray', 'grey', + 'cyan', 'magenta'} + + return color in valid_colors or (isinstance(color, str) and color.startswith('#')) + + mock_screen._iscolorstring = mock_iscolorstring + mock_screen._colorstr = turtle._Screen._colorstr.__get__(mock_screen) + return unittest.mock.patch( "turtle._Screen.__new__", - **{ - "return_value.__class__": turtle._Screen, - "return_value.mode.return_value": "standard", - }, + return_value=mock_screen ) @@ -635,6 +648,30 @@ def test_poly_context_when_creating_poly(self): self.assertTrue(self.turtle._creatingPoly) self.assertFalse(self.turtle._creatingPoly) + def test_dot_signature(self): + self.turtle.dot() + self.turtle.dot(10) + self.turtle.dot(size=10) + # self.assertRaises(ValueError, self.turtle.dot, 0) + # self.assertRaises(ValueError, self.turtle.dot, -1) + self.turtle.dot((0, 0, 0)) + self.turtle.dot(size=(0, 0, 0)) + self.turtle.dot("blue") + self.turtle.dot("") + self.turtle.dot(size="blue") + self.turtle.dot(20, "blue") + self.turtle.dot(20, "blue") + self.turtle.dot(20, (0, 0, 0)) + self.turtle.dot(20, 0, 0, 0) + with self.assertRaises(TypeError): + self.turtle.dot(color="blue") + self.assertRaises(turtle.TurtleGraphicsError, self.turtle.dot, "_not_a_color_") + self.assertRaises(turtle.TurtleGraphicsError, self.turtle.dot, 0, (0, 0, 0, 0)) + self.assertRaises(turtle.TurtleGraphicsError, self.turtle.dot, 0, 0, 0, 0, 0) + self.assertRaises(turtle.TurtleGraphicsError, self.turtle.dot, 0, (-1, 0, 0)) + self.assertRaises(turtle.TurtleGraphicsError, self.turtle.dot, 0, -1, 0, 0) + self.assertRaises(turtle.TurtleGraphicsError, self.turtle.dot, 0, (0, 257, 0)) + self.assertRaises(turtle.TurtleGraphicsError, self.turtle.dot, 0, 0, 257, 0) class TestModuleLevel(unittest.TestCase): def test_all_signatures(self): From 0a0cd10149988cd4a5cc9d5f7976e56335d51929 Mon Sep 17 00:00:00 2001 From: Jan-Eric Nitschke Date: Thu, 11 Sep 2025 17:15:08 +0200 Subject: [PATCH 2/2] Remove commented out lines in test --- Lib/test/test_turtle.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/Lib/test/test_turtle.py b/Lib/test/test_turtle.py index be7867d552f003..12d2eed874148c 100644 --- a/Lib/test/test_turtle.py +++ b/Lib/test/test_turtle.py @@ -652,8 +652,6 @@ def test_dot_signature(self): self.turtle.dot() self.turtle.dot(10) self.turtle.dot(size=10) - # self.assertRaises(ValueError, self.turtle.dot, 0) - # self.assertRaises(ValueError, self.turtle.dot, -1) self.turtle.dot((0, 0, 0)) self.turtle.dot(size=(0, 0, 0)) self.turtle.dot("blue")