예제 #1
0
    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'}}}
예제 #2
0
    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
예제 #3
0
 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]
예제 #4
0
    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'
                }
            }
        }
예제 #5
0
    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