Exemplo n.º 1
0
    def test_collect_from_nested_list_found(self):
        # """Ambiguous path through nested lists."""
        context = ExecutionContext()
        source = {'outer': [_LETTER_DICT, _NUMBER_DICT]}
        pred = PathPredicate(PATH_SEP.join(['outer', 'a']))
        values = pred(context, source)
        self.assertEqual([
            PathValue(PATH_SEP.join(['outer[0]', 'a']), 'A'),
            PathValue(PATH_SEP.join(['outer[1]', 'a']), 1)
        ], values.path_values)

        pred = PathPredicate(PATH_SEP.join(['outer', 'z']))
        values = pred(context, source)
        self.assertEqual([PathValue(PATH_SEP.join(['outer[0]', 'z']), 'Z')],
                         values.path_values)
        self.assertEqual([
            MissingPathError(_NUMBER_DICT,
                             'z',
                             path_value=PathValue('outer[1]', _NUMBER_DICT))
        ], values.path_failures)

        pred = PathPredicate(PATH_SEP.join(['outer', 'three']))
        values = pred(context, source)
        self.assertEqual([PathValue(PATH_SEP.join(['outer[1]', 'three']), 3)],
                         values.path_values)
        self.assertEqual([
            MissingPathError(_LETTER_DICT,
                             'three',
                             path_value=PathValue('outer[0]', _LETTER_DICT))
        ], values.path_failures)
Exemplo n.º 2
0
 def test_collect_from_nested_list_not_found(self):
   # """Path through nested lists that cannot be resolved."""
   source = {'outer': [_LETTER_DICT, _NUMBER_DICT]}
   pred = PathPredicate(PATH_SEP.join(['outer', 'X']))
   values = pred(source)
   self.assertEqual([], values.path_values)
   self.assertEqual(
       [MissingPathError(
           _LETTER_DICT, 'X',
           path_value=PathValue('outer[0]', _LETTER_DICT)),
        MissingPathError(
            _NUMBER_DICT, 'X',
            path_value=PathValue('outer[1]', _NUMBER_DICT))],
       values.path_failures)
Exemplo n.º 3
0
 def test_collect_from_nested_dict_not_found(self):
   # """Nested dictionary attribute lookup with missing element."""
   source = _LETTER_DICT
   pred = PathPredicate(PATH_SEP.join(['a', 'b']))
   values = pred(source)
   self.assertEqual([], values.path_values)
   self.assertEqual(
       [MissingPathError('A', 'b', path_value=PathValue('a', 'A'))],
       values.path_failures)
Exemplo n.º 4
0
 def test_collect_from_dict_not_found(self):
   # """Normal dictionary attribute lookup with missing attribute."""
   source = _LETTER_DICT
   pred = PathPredicate('Z')
   values = pred(source)
   self.assertEqual([], values.path_values)
   self.assertEqual([MissingPathError(_LETTER_DICT, 'Z',
                                      path_value=('', _LETTER_DICT))],
                    values.path_failures)
Exemplo n.º 5
0
 def test_collect_from_list_not_found(self):
   # """Ambiguous path passes through a list element but cannot be resolved."""
   source = [_LETTER_DICT]
   pred = PathPredicate('Z')
   values = pred(source)
   self.assertEqual([], values.path_values)
   self.assertEqual(
       [MissingPathError(
           _LETTER_DICT, 'Z', path_value=PathValue('[0]', _LETTER_DICT))],
       values.path_failures)