Add test asserting that evolve() correctly updates dicts

See: #759
This commit is contained in:
Stefan Scherfke 2021-02-19 09:15:45 +01:00
parent fe6eb31200
commit baa8f8c5b2
1 changed files with 16 additions and 0 deletions

View File

@ -622,3 +622,19 @@ class TestEvolve(object):
c2 = evolve(c1, a={"c": {"e": 23}}, b=42)
assert c2 == C(N1(N2(23), 2), 42)
def test_recursive_dict_val(self):
"""
evolve() only attempts recursion when the current value is an ``attrs``
class. Dictionaries as values can be replaced like any other value.
"""
@attr.s
class C(object):
a = attr.ib(type=dict)
b = attr.ib(type=int)
c1 = C({"spam": 1}, 2)
c2 = evolve(c1, a={"eggs": 2}, b=42)
assert c2 == C({"eggs": 2}, 42)