def test_get_dict_value_by_path(self): d = {'foo': {'bar': {'baz': 'bazval'}}} path = ['foo', 'bar', 'baz'] res = _get_dict_value_by_path(d, path) assert res == 'bazval' # make sure we don't modify inputs assert path == ['foo', 'bar', 'baz'] assert d == {'foo': {'bar': {'baz': 'bazval'}}}
def test_get_dict_value_by_path_none(self): d = { 'foo': { 'bar': { 'blam': 'blarg' } } } res = _get_dict_value_by_path(d, ['foo', 'bar', 'baz']) assert res is None
def test_get_dict_value_by_path_obj(self): e1 = Mock() e2 = Mock() d = { 'k1': { 'k2': { 'Marker': 'marker2', 'Data': [e1, e2], 'Foo2': 'bar2' } } } res = _get_dict_value_by_path(d, ['k1', 'k2', 'Data']) assert res == [e1, e2]
def test_get_dict_value_by_path(self): d = { 'foo': { 'bar': { 'baz': 'bazval' } } } path = ['foo', 'bar', 'baz'] res = _get_dict_value_by_path(d, path) assert res == 'bazval' # make sure we don't modify inputs assert path == ['foo', 'bar', 'baz'] assert d == { 'foo': { 'bar': { 'baz': 'bazval' } } }
def test_get_dict_value_by_path_deep_none(self): d = {'baz': 'blam'} res = _get_dict_value_by_path(d, ['foo', 'bar', 'baz']) assert res is None