summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2016-06-05 07:37:19 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2016-06-05 07:37:19 (GMT)
commitb07b57c52269e3a966e888a8ef43561be60bdbb7 (patch)
tree86da80d9d61962502062a304e4b087f527f5f930
parentff5cd4576f7be50ef245124971078d80786e19cb (diff)
parent3c5fa560ed6ae990e92afb0d2f77463c0ca73ab0 (diff)
downloadcpython-b07b57c52269e3a966e888a8ef43561be60bdbb7.zip
cpython-b07b57c52269e3a966e888a8ef43561be60bdbb7.tar.gz
cpython-b07b57c52269e3a966e888a8ef43561be60bdbb7.tar.bz2
Issue #21916: Added more tests for the turtle module.
Original patch by Jelle Zijlstra.
-rw-r--r--Lib/test/test_turtle.py36
1 files changed, 36 insertions, 0 deletions
diff --git a/Lib/test/test_turtle.py b/Lib/test/test_turtle.py
index b0993b3..2fd10cc 100644
--- a/Lib/test/test_turtle.py
+++ b/Lib/test/test_turtle.py
@@ -1,3 +1,4 @@
+import pickle
import unittest
from test import support
@@ -129,6 +130,41 @@ class VectorComparisonMixin:
class TestVec2D(VectorComparisonMixin, unittest.TestCase):
+ def test_constructor(self):
+ vec = Vec2D(0.5, 2)
+ self.assertEqual(vec[0], 0.5)
+ self.assertEqual(vec[1], 2)
+ self.assertIsInstance(vec, Vec2D)
+
+ self.assertRaises(TypeError, Vec2D)
+ self.assertRaises(TypeError, Vec2D, 0)
+ self.assertRaises(TypeError, Vec2D, (0, 1))
+ self.assertRaises(TypeError, Vec2D, vec)
+ self.assertRaises(TypeError, Vec2D, 0, 1, 2)
+
+ def test_repr(self):
+ vec = Vec2D(0.567, 1.234)
+ self.assertEqual(repr(vec), '(0.57,1.23)')
+
+ def test_equality(self):
+ vec1 = Vec2D(0, 1)
+ vec2 = Vec2D(0.0, 1)
+ vec3 = Vec2D(42, 1)
+ self.assertEqual(vec1, vec2)
+ self.assertEqual(vec1, tuple(vec1))
+ self.assertEqual(tuple(vec1), vec1)
+ self.assertNotEqual(vec1, vec3)
+ self.assertNotEqual(vec2, vec3)
+
+ def test_pickling(self):
+ vec = Vec2D(0.5, 2)
+ for proto in range(pickle.HIGHEST_PROTOCOL + 1):
+ with self.subTest(proto=proto):
+ pickled = pickle.dumps(vec, protocol=proto)
+ unpickled = pickle.loads(pickled)
+ self.assertEqual(unpickled, vec)
+ self.assertIsInstance(unpickled, Vec2D)
+
def _assert_arithmetic_cases(self, test_cases, lambda_operator):
for test_case in test_cases:
with self.subTest(case=test_case):