コード例 #1
0
def test_matcher_construction():
    matcher = Matcher([('test', [(1.0, [()]), (1.0, [
        (r'^abc$', r'^1234$'),
    ])]), ('test3', [
        (r'(?P<resolution>%s)', ['480p', '720p', '1080p']),
    ])])

    assert matcher.find_group('test2') == (None, None)
コード例 #2
0
    def __init__(self, debug=False):
        if not SceneParser.matcher:
            SceneParser.matcher = Matcher(PATTERN_GROUPS)
            Logr.info("Fragment matcher for %s created",
                      self.__class__.__name__)

        super(SceneParser, self).__init__(SceneParser.matcher, debug)
コード例 #3
0
ファイル: test_matcher.py プロジェクト: fuzeman/Caper
def test_matcher_construction():
    matcher = Matcher([
        ('test', [
            (1.0, [
                ()
            ]),
            (1.0, [
                (r'^abc$', r'^1234$'),
            ])
        ]),
        ('test3', [
            (r'(?P<resolution>%s)', [
                '480p',
                '720p',
                '1080p'
            ]),
        ])
    ])

    assert matcher.find_group('test2') == (None, None)
コード例 #4
0
def test_value_match():
    matcher = Matcher([('test', [(1.0, [
        r'^(?P<a>abc)$',
    ]), (0.8, [
        r'^(?P<b>1234)$',
    ])]), ('test2', [
        (1.0, [
            r'^(?P<a>abcdefg)$',
        ]),
    ])])

    assert_that(matcher.value_match('abc'),
                matches_dict({'test': {
                    'a': 'abc'
                }}))

    assert_that(matcher.value_match('abcdefg', 'test2'),
                matches_dict({'test2': {
                    'a': 'abcdefg'
                }}))

    assert_that(matcher.value_match('abcd'), none())
コード例 #5
0
ファイル: test_matcher.py プロジェクト: fuzeman/Caper
def test_value_match():
    matcher = Matcher([
        ('test', [
            (1.0, [
                r'^(?P<a>abc)$',
            ]),
            (0.8, [
                r'^(?P<b>1234)$',
            ])
        ]),
        ('test2', [
            (1.0, [
                r'^(?P<a>abcdefg)$',
            ]),
        ])
    ])

    assert_that(matcher.value_match('abc'), matches_dict({'test': {'a': 'abc'}}))

    assert_that(matcher.value_match('abcdefg', 'test2'), matches_dict({'test2': {'a': 'abcdefg'}}))

    assert_that(matcher.value_match('abcd'), none())
コード例 #6
0
ファイル: test_matcher.py プロジェクト: fuzeman/Caper
def test_fragment_match():
    matcher = Matcher([
        ('test', [
            (1.0, [
                (r'^abc$', r'^123$'),
            ]),
            (0.8, [
                (r'^abc$', r'^1234$'),
            ])
        ])
    ])

    assert matcher.fragment_match(create_fragments('abc.123')[0], 'test')[0] == 1

    assert matcher.fragment_match(create_fragments('abc.12')[0], 'test')[0] == 0

    assert matcher.fragment_match(create_fragments('abc')[0], 'test')[0] == 0

    assert matcher.fragment_match(create_fragments('abc.1234')[0], 'test')[0] == 0.8

    assert matcher.fragment_match(create_fragments('abc.456')[0], 'test')[0] == 0

    assert matcher.fragment_match(create_fragments('def.123')[0], 'test')[0] == 0

    matcher = Matcher([
        ('test', [
            (1.0, [
                ()
            ]),
            (1.0, [
                (r'^abc$', r'^1234$'),
            ])
        ])
    ])

    assert matcher.fragment_match(create_fragments('abc.1234')[0], 'test')[0] == 1
コード例 #7
0
def test_fragment_match():
    matcher = Matcher([('test', [(1.0, [
        (r'^abc$', r'^123$'),
    ]), (0.8, [
        (r'^abc$', r'^1234$'),
    ])])])

    assert matcher.fragment_match(create_fragments('abc.123')[0],
                                  'test')[0] == 1

    assert matcher.fragment_match(create_fragments('abc.12')[0],
                                  'test')[0] == 0

    assert matcher.fragment_match(create_fragments('abc')[0], 'test')[0] == 0

    assert matcher.fragment_match(create_fragments('abc.1234')[0],
                                  'test')[0] == 0.8

    assert matcher.fragment_match(create_fragments('abc.456')[0],
                                  'test')[0] == 0

    assert matcher.fragment_match(create_fragments('def.123')[0],
                                  'test')[0] == 0

    matcher = Matcher([('test', [(1.0, [()]), (1.0, [
        (r'^abc$', r'^1234$'),
    ])])])

    assert matcher.fragment_match(create_fragments('abc.1234')[0],
                                  'test')[0] == 1
コード例 #8
0
 def __init__(self, pattern_groups, debug=False):
     super(DummyParser, self).__init__(Matcher(pattern_groups), debug)