MCPcopy Index your code
hub / github.com/python-attrs/attrs / test_change

Method test_change

tests/test_funcs.py:687–704  ·  view source on GitHub ↗

Changes work.

(self, C, data)

Source from the content-addressed store, hash-verified

685
686 @given(simple_classes(), st.data())
687 def test_change(self, C, data):
688 """
689 Changes work.
690 """
691 # Take the first attribute, and change it.
692 assume(fields(C)) # Skip classes with no attributes.
693 field_names = [a.name for a in fields(C)]
694 original = C()
695 chosen_names = data.draw(st.sets(st.sampled_from(field_names)))
696 # We pay special attention to private attributes, they should behave
697 # like in `__init__`.
698 change_dict = {
699 name.replace("_", ""): data.draw(st.integers())
700 for name in chosen_names
701 }
702 changed = evolve(original, **change_dict)
703 for name in chosen_names:
704 assert getattr(changed, name) == change_dict[name.replace("_", "")]
705
706 @given(simple_classes())
707 def test_unknown(self, C):

Callers

nothing calls this directly

Calls 3

fieldsFunction · 0.90
evolveFunction · 0.90
CClass · 0.70

Tested by

no test coverage detected