MCPcopy
hub / github.com/python-attrs/attrs / test_copy_two_arg_reduce

Method test_copy_two_arg_reduce

tests/test_dunders.py:715–734  ·  view source on GitHub ↗

If __getstate__ returns None, the tuple returned by object.__reduce__ won't contain the state dictionary; this test ensures that the custom __reduce__ generated when cache_hash=True works in that case.

(self, frozen)

Source from the content-addressed store, hash-verified

713 assert original_hash != hash(obj_rt)
714
715 def test_copy_two_arg_reduce(self, frozen):
716 """
717 If __getstate__ returns None, the tuple returned by object.__reduce__
718 won't contain the state dictionary; this test ensures that the custom
719 __reduce__ generated when cache_hash=True works in that case.
720 """
721
722 @attr.s(frozen=frozen, cache_hash=True, unsafe_hash=True)
723 class C:
724 x = attr.ib()
725
726 def __getstate__(self):
727 return None
728
729 # By the nature of this test it doesn't really create an object that's
730 # in a valid state - it basically does the equivalent of
731 # `object.__new__(C)`, so it doesn't make much sense to assert anything
732 # about the result of the copy. This test will just check that it
733 # doesn't raise an *error*.
734 copy.deepcopy(C(1))
735
736 def _roundtrip_pickle(self, obj):
737 pickle_str = pickle.dumps(obj)

Callers

nothing calls this directly

Calls 1

CClass · 0.70

Tested by

no test coverage detected