Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_invalid_pattern(pattern):
'''Construct template with invalid pattern.'''
with pytest.raises(ValueError):
Template('test', pattern)
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'}
def test_format(pattern, data, expected):
'''Format data against pattern.'''
template = Template('test', pattern)
formatted = template.format(data)
assert formatted == expected
def templates():
'''Return candidate templates.'''
return [
lucidity.Template('model', '/jobs/{job.code}/assets/model/{lod}'),
lucidity.Template('rig', '/jobs/{job.code}/assets/rig/{rig_type}')
]
def test_matching_parse(pattern, path, expected):
'''Extract data from matching path.'''
template = Template('test', pattern)
data = template.parse(path)
assert data == expected
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)
def test_repr():
'''Represent template.'''
assert (repr(Template('test', '/foo/{bar}/{baz:\d+}'))
== 'Template(name=\'test\', pattern=\'/foo/{bar}/{baz:\\\d+}\')')
def test_valid_pattern(pattern):
'''Construct template with valid pattern.'''
Template('test', pattern)
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'}
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)