Example #1
0
    def test_dict_match_multi_ok(self):
        context = ExecutionContext()
        source = {'a': 'testing', 'n': 10}
        want = {'n': jp.NUM_LE(20), '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_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)
Example #2
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)
Example #3
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)
Example #4
0
    def test_dict_match_strict_ok(self):
        context = ExecutionContext()
        source = {'n': 10}
        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)).build(True))

        self.assertTrue(result)
        self.assertEquals(expect, result)
Example #5
0
    def test_dict_match_multi_ok(self):
        context = ExecutionContext()
        source = {'a': 'testing', 'n': 10}
        n_pred = jp.NUM_LE(20)
        a_pred = jp.STR_SUBSTR('test')
        want = {'n': n_pred, 'a': a_pred}
        result = jp.DICT_MATCHES(want)(context, source)

        expect = (jp.KeyedPredicateResultBuilder(
            jp.DICT_MATCHES(want)).add_result(
                'n',
                self._match_dict_attribute_result(
                    context, n_pred, 'n', source)).add_result(
                        'a',
                        self._match_dict_attribute_result(
                            context, a_pred, 'a', source)).build(True))

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