def test_set_dict_value_by_path(self): d = { 'foo': { 'bar': { 'baz': 'bazval' } } } path = ['foo', 'bar', 'baz'] res = _set_dict_value_by_path(d, 'blam', path) assert res == { 'foo': { 'bar': { 'baz': 'blam' } } } # make sure we don't modify inputs assert path == ['foo', 'bar', 'baz'] assert d == { 'foo': { 'bar': { 'baz': 'bazval' } } }
def test_set_dict_value_by_path_none(self): d = { 'foo': { 'bar': { 'blam': 'blarg' } } } res = _set_dict_value_by_path(d, 'blam', ['foo', 'bar', 'baz']) assert res == { 'foo': { 'bar': { 'baz': 'blam', 'blam': 'blarg' } } }
def test_set_dict_value_by_path_empty(self): d = {'foo': 'bar'} res = _set_dict_value_by_path(d, 'baz', []) assert res == d
def test_set_dict_value_by_path_deep_none(self): d = {'foo': 'bar'} with pytest.raises(TypeError): _set_dict_value_by_path(d, 'blam', ['foo', 'bar', 'baz'])