[3.11] gh-100871: Improve copy module tests (GH-100872) (#100976)

(cherry picked from commit 729ab9b622)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
This commit is contained in:
Nikita Sobolev 2023-01-12 14:15:00 +03:00 committed by GitHub
parent e8097d49f6
commit db2643737d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 44 additions and 2 deletions

View file

@ -5,6 +5,7 @@ import operator
import sys
import unittest
import weakref
import copy
from pickle import loads, dumps
from test import support
@ -242,6 +243,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()