Exemplo n.º 1
0
    def test_list_match_strict_bad(self):
        context = ExecutionContext()
        source = [1, 2]
        want = [jp.NUM_NE(2)]
        match_pred = jp.LIST_MATCHES(want, strict=True)
        result = match_pred(context, source)

        expect = (jp.SequencedPredicateResultBuilder(match_pred).append_result(
            jp.MapPredicate(jp.NUM_NE(2))(context, source)).append_result(
                jp.UnexpectedPathError(source=source,
                                       target_path='[1]',
                                       path_value=jp.PathValue(
                                           '[1]', 2))).build(False))

        self.assertFalse(result)
        self.assertEquals(expect, result)
Exemplo n.º 2
0
    def test_dict_match_strict_bad(self):
        context = ExecutionContext()
        source = {'n': 10, 'extra': 'EXTRA'}
        pred = jp.NUM_LE(20)
        want = {'n': pred}
        match_pred = jp.DICT_MATCHES(want, strict=True)
        result = match_pred(context, source)

        expect = (jp.KeyedPredicateResultBuilder(match_pred).add_result(
            'n', self._match_dict_attribute_result(
                context, pred, 'n', source)).add_result(
                    'extra',
                    jp.UnexpectedPathError(source=source,
                                           target_path='extra',
                                           path_value=jp.PathValue(
                                               'extra',
                                               'EXTRA'))).build(False))

        self.assertFalse(result)
        self.assertEquals(expect, result)