def test_shallow_update(): pd1 = ParamDict(a=3, b=4) pd2 = ParamDict(b=14, c=15) pd1orig = pd1.copy() pd1.update_shallow(pd2) assert all(k in pd1 for k in pd1orig) assert all(k in pd1 for k in pd2) assert all(pd1[k] == pd2[k] for k in pd2) assert all(pd1[k] == pd1orig[k] for k in pd1orig if not k in pd2)
def test_shallow_replace(): pd1 = ParamDict(a=3, b=4) pd2 = ParamDict(b=14) pd3 = ParamDict(c=15) pd1orig = pd1.copy() pd1.replace_shallow(pd2) assert all(k in pd1 for k in pd1orig) assert all(pd1[k] == pd2[k] for k in pd2) assert all(pd1[k] == pd1orig[k] for k in pd1orig if not k in pd2) with pytest.raises(RuntimeError): pd1.replace_shallow(pd3)