Example #1
0
def test_invalid_parse_in_strict_mode(pattern, path):
    '''Fail to extract data in strict mode when invalid duplicates detected.'''
    template = Template(
        'test', pattern, duplicate_placeholder_mode=Template.STRICT
    )
    with pytest.raises(ParseError) as exception:
        template.parse(path)

    assert 'Different extracted values' in str(exception.value)
def test_invalid_parse_in_strict_mode(pattern, path, template_resolver):
    '''Fail to extract data in strict mode when invalid duplicates detected.'''
    template = Template('test',
                        pattern,
                        duplicate_placeholder_mode=Template.STRICT,
                        template_resolver=template_resolver)
    with pytest.raises(ParseError) as exception:
        template.parse(path)

    assert 'Different extracted values' in str(exception.value)
Example #3
0
def test_anchor(path, anchor, expected):
    '''Parse path with specific anchor setting.'''
    pattern = '/static/{variable}'
    template = Template('test', pattern, anchor=anchor)

    if not expected:
        with pytest.raises(ParseError):
            template.parse(path)
    else:
        data = template.parse(path)
        assert data == {'variable': 'value'}
Example #4
0
def test_anchor(path, anchor, expected):
    '''Parse path with specific anchor setting.'''
    pattern = '/static/{variable}'
    template = Template('test', pattern, anchor=anchor)

    if not expected:
        with pytest.raises(ParseError):
            template.parse(path)
    else:
        data = template.parse(path)
        assert data == {'variable': 'value'}
Example #5
0
def test_valid_parse_in_strict_mode(pattern, path, expected):
    '''Extract data in strict mode when no invalid duplicates detected.'''
    template = Template(
        'test', pattern, duplicate_placeholder_mode=Template.STRICT
    )
    data = template.parse(path)
    assert data == expected
def test_valid_parse_in_strict_mode(pattern, path, expected,
                                    template_resolver):
    '''Extract data in strict mode when no invalid duplicates detected.'''
    template = Template('test',
                        pattern,
                        duplicate_placeholder_mode=Template.STRICT,
                        template_resolver=template_resolver)
    data = template.parse(path)
    assert data == expected
Example #7
0
def test_non_matching_parse(pattern, path):
    '''Extract data from non-matching path.'''
    template = Template('test', pattern)
    with pytest.raises(ParseError):
        data = template.parse(path)
Example #8
0
def test_matching_parse(pattern, path, expected):
    '''Extract data from matching path.'''
    template = Template('test', pattern)
    data = template.parse(path)
    assert data == expected
Example #9
0
def test_escaping_pattern():
    '''Escape regex components in pattern.'''
    template = Template('test', '{filename}.{index:\d\\{4\\}}.{ext}')
    expected = {'filename': 'filename', 'index': '0001', 'ext': 'ext'}
    assert template.parse('filename.0001.ext') == expected
Example #10
0
def test_non_matching_parse(pattern, path):
    '''Extract data from non-matching path.'''
    template = Template('test', pattern)
    with pytest.raises(ParseError):
        data = template.parse(path)
Example #11
0
def test_matching_parse(pattern, path, expected):
    '''Extract data from matching path.'''
    template = Template('test', pattern)
    data = template.parse(path)
    assert data == expected
Example #12
0
def test_escaping_pattern():
    '''Escape regex components in pattern.'''
    template = Template('test', '{filename}.{index:\d\\{4\\}}.{ext}')
    expected = {'filename': 'filename', 'index': '0001', 'ext': 'ext'}
    assert template.parse('filename.0001.ext') == expected