def test_get_nonexistent_value(self): l = ['a', 'd'] p = DictPath(':', l) with self.assertRaises(KeyError): p.get_value(dict())
def test_get_value_escaped(self): v = 42 l = ['a', 'b:b', 'c'] d = {'a': {'b:b': {'c': v}}} p = DictPath(':', l) self.assertEqual(p.get_value(d), v)
def _resolve(self, ref, context): path = DictPath(self._delim, ref) try: return path.get_value(context) except KeyError as e: raise UndefinedVariableError(ref)
def test_get_value_listindex_str(self): v = 42 s = 'a:1:c' d = {'a': [None, {'c': v}, None]} p = DictPath(':', s) self.assertEqual(p.get_value(d), v)
def test_get_value_escaped(self): v = 42 l = ['a', 'b:b', 'c'] d = {'a':{'b:b':{'c':v}}} p = DictPath(':', l) self.assertEqual(p.get_value(d), v)
def test_get_value_listindex_list(self): v = 42 l = ['a', 1, 'c'] d = {'a':[None, {'c':v}, None]} p = DictPath(':', l) self.assertEqual(p.get_value(d), v)
def test_get_value_listindex_str(self): v = 42 s = 'a:1:c' d = {'a':[None, {'c':v}, None]} p = DictPath(':', s) self.assertEqual(p.get_value(d), v)
def resolve(self, context, *args, **kwargs): path = DictPath(kwargs['delim'], self.string) try: return path.get_value(context) except KeyError as e: raise UndefinedVariableError(self.string)
def test_get_value_listindex_list(self): v = 42 l = ["a", 1, "c"] d = {"a": [None, {"c": v}, None]} p = DictPath(":", l) self.assertEqual(p.get_value(d), v)
def test_get_value_escaped(self): v = 42 l = ["a", "b:b", "c"] d = {"a": {"b:b": {"c": v}}} p = DictPath(":", l) self.assertEqual(p.get_value(d), v)
def test_get_nonexistent_value(self): l = ["a", "d"] p = DictPath(":", l) with self.assertRaises(KeyError): p.get_value(dict())
def test_get_value_listindex_str(self): v = 42 s = "a:1:c" d = {"a": [None, {"c": v}, None]} p = DictPath(":", s) self.assertEqual(p.get_value(d), v)
def test_get_value_listindex_list(self): v = 42 l = ['a', 1, 'c'] d = {'a': [None, {'c': v}, None]} p = DictPath(':', l) self.assertEqual(p.get_value(d), v)
def _resolve(self, ref, context): path = DictPath(self._settings.delimiter, ref) try: return path.get_value(context) except (KeyError, TypeError) as e: raise ResolveError(ref)