コード例 #1
0
    def test_dict_match_multi_bad(self):
        context = ExecutionContext()
        source = {'a': 'testing', 'n': 10}
        want = {'n': jp.NUM_NE(10), 'a': jp.STR_SUBSTR('test')}
        result = jp.DICT_MATCHES(want)(context, source)

        expect = (jp.KeyedPredicateResultBuilder(
            jp.DICT_MATCHES(want)).add_result(
                'a',
                jp.PathPredicateResultBuilder(
                    source=source,
                    pred=jp.STR_SUBSTR('test')).add_result_candidate(
                        path_value=jp.PathValue('a', 'testing'),
                        final_result=jp.STR_SUBSTR('test')(
                            context, 'testing')).build(True)).add_result(
                                'n',
                                jp.PathPredicateResultBuilder(
                                    source=source,
                                    pred=jp.NUM_NE(10)).add_result_candidate(
                                        jp.PathValue('n', 10),
                                        jp.NUM_NE(10)(
                                            context,
                                            10)).build(False)).build(False))

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

        expect = (jp.KeyedPredicateResultBuilder(match_pred).add_result(
            'n',
            jp.PathPredicateResultBuilder(
                source=source, pred=jp.NUM_LE(20)).add_result_candidate(
                    jp.PathValue('n', 10),
                    jp.NUM_LE(20)(context, 10)).build(True)).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)
コード例 #3
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)
コード例 #4
0
    def test_dict_match_strict_ok(self):
        context = ExecutionContext()
        source = {'n': 10}
        want = {'n': jp.NUM_LE(20)}
        match_pred = jp.DICT_MATCHES(want, strict=True)
        result = match_pred(context, source)

        expect = (jp.KeyedPredicateResultBuilder(match_pred).add_result(
            'n',
            jp.PathPredicateResultBuilder(
                source=source, pred=jp.NUM_LE(20)).add_result_candidate(
                    jp.PathValue('n', 10),
                    jp.NUM_LE(20)(context, 10)).build(True)).build(True))

        self.assertTrue(result)
        self.assertEquals(expect, result)
コード例 #5
0
    def test_dict_match_simple_bad(self):
        context = ExecutionContext()
        source = {'n': 10}
        want = {'n': jp.NUM_NE(10)}
        result = jp.DICT_MATCHES(want)(context, source)

        expect = (jp.KeyedPredicateResultBuilder(
            jp.DICT_MATCHES(want)).add_result(
                'n',
                jp.PathPredicateResultBuilder(
                    source=source, pred=jp.NUM_NE(10)).add_result_candidate(
                        jp.PathValue('n', 10),
                        jp.NUM_NE(10)(context, 10)).build(False)).build(False))

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