diff options
author | Nikita Sobolev <mail@sobolevn.me> | 2023-01-11 17:14:41 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-11 17:14:41 (GMT) |
commit | 729ab9b622957fef0e9b494af9a71ab02986c741 (patch) | |
tree | 490f0bc8f8c6782d91142eb760d1559174c54623 /Lib/test/test_slice.py | |
parent | 762745a124cbc297cf2fe6f3ec9ca1840bb2e873 (diff) | |
download | cpython-729ab9b622957fef0e9b494af9a71ab02986c741.zip cpython-729ab9b622957fef0e9b494af9a71ab02986c741.tar.gz cpython-729ab9b622957fef0e9b494af9a71ab02986c741.tar.bz2 |
gh-100871: Improve `copy` module tests (GH-100872)
CC @AlexWaygood as the reviewer of https://github.com/python/cpython/pull/100818
Automerge-Triggered-By: GH:AlexWaygood
Diffstat (limited to 'Lib/test/test_slice.py')
-rw-r--r-- | Lib/test/test_slice.py | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/Lib/test/test_slice.py b/Lib/test/test_slice.py index c4bc8c8..03fde32 100644 --- a/Lib/test/test_slice.py +++ b/Lib/test/test_slice.py @@ -5,6 +5,7 @@ import operator import sys import unittest import weakref +import copy from pickle import loads, dumps from test import support @@ -244,6 +245,41 @@ class SliceTest(unittest.TestCase): self.assertEqual(s.indices(15), t.indices(15)) self.assertNotEqual(id(s), id(t)) + def test_copy(self): + s = slice(1, 10) + c = copy.copy(s) + self.assertIs(s, c) + + s = slice(1, 10, 2) + c = copy.copy(s) + self.assertIs(s, c) + + # Corner case for mutable indices: + s = slice([1, 2], [3, 4], [5, 6]) + c = copy.copy(s) + self.assertIs(s, c) + self.assertIs(s.start, c.start) + self.assertIs(s.stop, c.stop) + self.assertIs(s.step, c.step) + + def test_deepcopy(self): + s = slice(1, 10) + c = copy.deepcopy(s) + self.assertEqual(s, c) + + s = slice(1, 10, 2) + c = copy.deepcopy(s) + self.assertEqual(s, c) + + # Corner case for mutable indices: + s = slice([1, 2], [3, 4], [5, 6]) + c = copy.deepcopy(s) + self.assertIsNot(s, c) + self.assertEqual(s, c) + self.assertIsNot(s.start, c.start) + self.assertIsNot(s.stop, c.stop) + self.assertIsNot(s.step, c.step) + def test_cycle(self): class myobj(): pass o = myobj() |