mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
[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:
parent
e8097d49f6
commit
db2643737d
2 changed files with 44 additions and 2 deletions
|
@ -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()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue