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

Method test_copy_hash_cleared

tests/test_dunders.py:662–686  ·  view source on GitHub ↗

Test that the default hash is recalculated after a copy operation.

(self, cache_hash, frozen, slots)

Source from the content-addressed store, hash-verified

660
661 @pytest.mark.parametrize("cache_hash", [True, False])
662 def test_copy_hash_cleared(self, cache_hash, frozen, slots):
663 """
664 Test that the default hash is recalculated after a copy operation.
665 """
666
667 kwargs = {"frozen": frozen, "slots": slots, "cache_hash": cache_hash}
668
669 # Give it an explicit hash if we don't have an implicit one
670 if not frozen:
671 kwargs["unsafe_hash"] = True
672
673 @attr.s(**kwargs)
674 class C:
675 x = attr.ib()
676
677 a = C(IncrementingHasher())
678 # Ensure that any hash cache would be calculated before copy
679 orig_hash = hash(a)
680 b = copy.deepcopy(a)
681
682 if kwargs["cache_hash"]:
683 # For cache_hash classes, this call is cached
684 assert orig_hash == hash(a)
685
686 assert orig_hash != hash(b)
687
688 @pytest.mark.parametrize(
689 ("klass", "cached"),

Callers

nothing calls this directly

Calls 2

IncrementingHasherClass · 0.85
CClass · 0.70

Tested by

no test coverage detected