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_mustache_resolve_cycles():
with pytest.raises(MustacheParser.Uninterpolatable):
MustacheParser.resolve('{{foo[{{bar}}]}} {{baz}}',
Environment(foo = List(String)(["{{foo[{{bar}}]}}", "world"])), Environment(bar = 0))
def test_indexing():
li = List(Integer)([1,2,3])
for bad in ['a', None, type, Integer]:
with pytest.raises(TypeError):
li[bad]
# Indexing should also support slices
li = List(Integer)(range(10))
assert li[0] == Integer(0)
assert li[-1] == Integer(9)
assert li[::2] == (Integer(0), Integer(2), Integer(4), Integer(6), Integer(8))
assert li[8:] == (Integer(8), Integer(9))
assert li[2:0:-1] == (Integer(2), Integer(1))
with pytest.raises(IndexError):
li[10]
def test_basic_lists():
assert List(Integer)([]).check().ok()
assert List(Integer)([1]).check().ok()
assert List(Integer)((1,)).check().ok()
assert List(Integer)(["1",]).check().ok()
assert not List(Integer)([1, "{{two}}"]).check().ok()
assert (List(Integer)([1, "{{two}}"]) % {'two': 2}).check().ok()
with pytest.raises(ValueError):
List(Integer)({'not': 'a', 'list': 'type'})
repr(List(Integer)([1, '{{two}}']))
def test_equals():
assert List(Integer)([1, "{{wut}}"]).bind(wut=23) == List(Integer)([1, 23])
assert not List(Integer)([1, 2]) == List(Integer)([1, 3])
assert List(Integer)([1, 2]) != List(Integer)([1, 3])
assert not List(Integer)([1, "{{wut}}"]).bind(wut=23) != List(Integer)([1, 23])
def test_basic_lists():
assert List(Integer)([]).check().ok()
assert List(Integer)([1]).check().ok()
assert List(Integer)((1,)).check().ok()
assert List(Integer)(["1",]).check().ok()
assert not List(Integer)([1, "{{two}}"]).check().ok()
assert (List(Integer)([1, "{{two}}"]) % {'two': 2}).check().ok()
with pytest.raises(ValueError):
List(Integer)({'not': 'a', 'list': 'type'})
repr(List(Integer)([1, '{{two}}']))
def test_iteration():
li = List(Integer)([1,2,3])
liter = iter(li)
assert next(liter) == Integer(1)
assert next(liter) == Integer(2)
assert next(liter) == Integer(3)
with pytest.raises(StopIteration):
next(liter)
li = List(Integer)([])
with pytest.raises(StopIteration):
next(iter(li))
def test_basic_scoping():
i = Integer('{{intvalue}}')
lst = List(Integer)([i.bind(intvalue = 1), i.bind(intvalue = 2), i])
lsti, _ = lst.bind(intvalue = 3).interpolate()
assert lsti == List(Integer)([Integer(1), Integer(2), Integer(3)])
lsti, _ = lst.in_scope(intvalue = 3).interpolate()
assert lsti == List(Integer)([Integer(1), Integer(2), Integer(3)])
one = ref('[0]')
two = ref('[1]')
three = ref('[2]')
assert lst.find(one) == Integer(1)
assert lst.find(two) == Integer(2)
assert lst.find(three) == Integer('{{intvalue}}')
assert lst.in_scope(intvalue = 3).find(one) == Integer(1)
assert lst.in_scope(intvalue = 3).find(two) == Integer(2)
assert lst.in_scope(intvalue = 3).find(three) == Integer(3)
def test_list_scoping():
assert List(Integer)([1, "{{wut}}"]).interpolate() == (
List(Integer)([Integer(1), Integer('{{wut}}')]), [ref('wut')])
assert List(Integer)([1, "{{wut}}"]).bind(wut = 23).interpolate() == (
List(Integer)([Integer(1), Integer(23)]), [])
assert List(Integer)([1, Integer("{{wut}}").bind(wut = 24)]).bind(wut = 23).interpolate() == (
List(Integer)([Integer(1), Integer(24)]), [])
def test_list_scoping():
assert List(Integer)([1, "{{wut}}"]).interpolate() == (
List(Integer)([Integer(1), Integer('{{wut}}')]), [ref('wut')])
assert List(Integer)([1, "{{wut}}"]).bind(wut = 23).interpolate() == (
List(Integer)([Integer(1), Integer(23)]), [])
assert List(Integer)([1, Integer("{{wut}}").bind(wut = 24)]).bind(wut = 23).interpolate() == (
List(Integer)([Integer(1), Integer(24)]), [])