Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve tests of copy module #100871

Closed
sobolevn opened this issue Jan 9, 2023 · 1 comment
Closed

Improve tests of copy module #100871

sobolevn opened this issue Jan 9, 2023 · 1 comment
Assignees
Labels
tests Tests in the Lib/test dir type-bug An unexpected behavior, bug, or error

Comments

@sobolevn
Copy link
Member

sobolevn commented Jan 9, 2023

After working on #100817 I've noticed that there are multiple things that can be improved in terms of copy module tests:

  1. First of all, I had submitted some broken code in gh-100817: Speed up copy.deepcopy calls on slice objects #100818 but, our test cases were not able to detect it. Solution: add a new test case in test_slice.py with copy and deepcopy calls. I think it should be in test_slice and not in test_copy, because there's nothing special about it: copy does not change its behaviour or special case it.
  2. This test ensures that after modifing copyreg we can now copy an object, but does not assert the result:
    def test_copy_registry(self):
    class C(object):
    def __new__(cls, foo):
    obj = object.__new__(cls)
    obj.foo = foo
    return obj
    def pickle_C(obj):
    return (C, (obj.foo,))
    x = C(42)
    self.assertRaises(TypeError, copy.copy, x)
    copyreg.pickle(C, pickle_C, C)
    y = copy.copy(x)
    def test_copy_reduce_ex(self):
    Right now it can be whatever. The same happens in
    def test_deepcopy_registry(self):
    class C(object):
    def __new__(cls, foo):
    obj = object.__new__(cls)
    obj.foo = foo
    return obj
    def pickle_C(obj):
    return (C, (obj.foo,))
    x = C(42)
    self.assertRaises(TypeError, copy.deepcopy, x)
    copyreg.pickle(C, pickle_C, C)
    y = copy.deepcopy(x)
    def test_deepcopy_reduce_ex(self):
    Solution: add required assertions
  3. test_deepcopy_atomic misses several important types: bytes, types.EllipsisType, NotImplementedType.
    def test_deepcopy_atomic(self):
    class NewStyle:
    pass
    def f():
    pass
    tests = [None, 42, 2**100, 3.14, True, False, 1j,
    "hello", "hello\u1234", f.__code__,
    NewStyle, range(10), max, property()]
    for x in tests:
    self.assertIs(copy.deepcopy(x), x)

PR is incoming.

Linked PRs

@sobolevn sobolevn added type-bug An unexpected behavior, bug, or error tests Tests in the Lib/test dir labels Jan 9, 2023
@sobolevn sobolevn self-assigned this Jan 9, 2023
sobolevn added a commit to sobolevn/cpython that referenced this issue Jan 9, 2023
miss-islington pushed a commit that referenced this issue Jan 11, 2023
CC @AlexWaygood as the reviewer of #100818

Automerge-Triggered-By: GH:AlexWaygood
sobolevn added a commit to sobolevn/cpython that referenced this issue Jan 12, 2023
CC @AlexWaygood as the reviewer of python#100818

Automerge-Triggered-By: GH:AlexWaygood.
(cherry picked from commit 729ab9b)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
sobolevn added a commit to sobolevn/cpython that referenced this issue Jan 12, 2023
CC @AlexWaygood as the reviewer of python#100818

Automerge-Triggered-By: GH:AlexWaygood.
(cherry picked from commit 729ab9b)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
AlexWaygood pushed a commit that referenced this issue Jan 12, 2023
(cherry picked from commit 729ab9b)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
AlexWaygood pushed a commit that referenced this issue Jan 12, 2023
(cherry picked from commit 729ab9b)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
@AlexWaygood
Copy link
Member

Thanks @sobolevn!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tests Tests in the Lib/test dir type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

2 participants