How to use the pystachio.container.List function in pystachio

To help you get started, we’ve selected a few pystachio examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github wickman / pystachio / tests / test_parsing.py View on Github external
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))
github wickman / pystachio / tests / test_container_types.py View on Github external
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]
github wickman / pystachio / tests / test_container_types.py View on Github external
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}}']))
github wickman / pystachio / tests / test_container_types.py View on Github external
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])
github wickman / pystachio / tests / test_container_types.py View on Github external
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}}']))
github wickman / pystachio / tests / test_container_types.py View on Github external
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))
github wickman / pystachio / tests / test_container_types.py View on Github external
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)
github wickman / pystachio / tests / test_container_types.py View on Github external
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)]), [])
github wickman / pystachio / tests / test_container_types.py View on Github external
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)]), [])