How to use pystachio - 10 common examples

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_re():
  assert MustacheParser.split("{{foo}}") == [ref("foo")]
  assert MustacheParser.split("{{_}}") == [ref("_")]
  with pytest.raises(Ref.InvalidRefError):
    MustacheParser.split("{{4}}")
  def chrange(a,b):
    return ''.join(map(lambda ch: str(chr(ch)), range(ord(a), ord(b)+1)))
  slash_w = chrange('a','z') + chrange('A','Z') + chrange('0','9') + '_'
  assert MustacheParser.split("{{%s}}" % slash_w) == [ref(slash_w)]

  # bracketing
  assert MustacheParser.split("{{{foo}}") == ['{', ref('foo')]
  assert MustacheParser.split("{{foo}}}") == [ref('foo'), '}']
  assert MustacheParser.split("{{{foo}}}") == ['{', ref('foo'), '}']
  assert MustacheParser.split("{{}}") == ['{{}}']
  assert MustacheParser.split("{{{}}}") == ['{{{}}}']
  assert MustacheParser.split("{{{{foo}}}}") == ['{{', ref("foo"), '}}']

  invalid_refs = ['!@', '-', '$', ':']
  for val in invalid_refs:
github apache / aurora / tests / python / twitter / aurora / common / test_cluster.py View on Github external
def test_simple():
  class AudubonTrait(Cluster.Trait):
    master_role = String
    slave_role  = Default(String, 'slave')
    version     = Required(Integer)

  west = Cluster(name = 'west',
                 master_role = 'west.master',
                 slave_role = 'west.slave',
                 version = 10)
  east = Cluster(name = 'east', version = 11)

  assert east.name == 'east'
  with pytest.raises(AttributeError):
    east.slave_role
  assert east.with_traits(AudubonTrait).slave_role == 'slave'
  assert west.with_traits(AudubonTrait).slave_role == 'west.slave'
  assert east.with_traits(AudubonTrait).master_role is None

  with pytest.raises(TypeError):
github wickman / pystachio / tests / test_parsing.py View on Github external
def test_mustache_re():
  assert MustacheParser.split("{{foo}}") == [ref("foo")]
  assert MustacheParser.split("{{_}}") == [ref("_")]
  with pytest.raises(Ref.InvalidRefError):
    MustacheParser.split("{{4}}")
  def chrange(a,b):
    return ''.join(map(lambda ch: str(chr(ch)), range(ord(a), ord(b)+1)))
  slash_w = chrange('a','z') + chrange('A','Z') + chrange('0','9') + '_'
  assert MustacheParser.split("{{%s}}" % slash_w) == [ref(slash_w)]

  # bracketing
  assert MustacheParser.split("{{{foo}}") == ['{', ref('foo')]
  assert MustacheParser.split("{{foo}}}") == [ref('foo'), '}']
  assert MustacheParser.split("{{{foo}}}") == ['{', ref('foo'), '}']
  assert MustacheParser.split("{{}}") == ['{{}}']
  assert MustacheParser.split("{{{}}}") == ['{{{}}}']
  assert MustacheParser.split("{{{{foo}}}}") == ['{{', ref("foo"), '}}']

  invalid_refs = ['!@', '-', '$', ':']
  for val in invalid_refs:
    with pytest.raises(Ref.InvalidRefError):
      MustacheParser.split("{{%s}}" % val)
github wickman / pystachio / tests / test_parsing.py View on Github external
def test_mustache_joining():
  oe = Environment(foo = "foo herp",
                   bar = "bar derp",
                   baz = "baz blerp")

  joined, unbound = MustacheParser.join(MustacheParser.split("{{foo}}"), oe)
  assert joined == "foo herp"
  assert unbound == []

  splits = MustacheParser.split('blech {{foo}} {{bar}} bonk {{&baz}} bling')
  joined, unbound = MustacheParser.join(splits, oe)
  assert joined == 'blech foo herp bar derp bonk {{baz}} bling'
  assert unbound == []

  splits = MustacheParser.split('{{foo}} {{bar}} {{unbound}}')
  joined, unbound = MustacheParser.join(splits, oe)
  assert joined == 'foo herp bar derp {{unbound}}'
  assert unbound == [Ref.from_address('unbound')]
github wickman / pystachio / tests / test_parsing.py View on Github external
def test_mustache_re():
  assert MustacheParser.split("{{foo}}") == [ref("foo")]
  assert MustacheParser.split("{{_}}") == [ref("_")]
  with pytest.raises(Ref.InvalidRefError):
    MustacheParser.split("{{4}}")
  def chrange(a,b):
    return ''.join(map(lambda ch: str(chr(ch)), range(ord(a), ord(b)+1)))
  slash_w = chrange('a','z') + chrange('A','Z') + chrange('0','9') + '_'
  assert MustacheParser.split("{{%s}}" % slash_w) == [ref(slash_w)]

  # bracketing
  assert MustacheParser.split("{{{foo}}") == ['{', ref('foo')]
  assert MustacheParser.split("{{foo}}}") == [ref('foo'), '}']
  assert MustacheParser.split("{{{foo}}}") == ['{', ref('foo'), '}']
  assert MustacheParser.split("{{}}") == ['{{}}']
  assert MustacheParser.split("{{{}}}") == ['{{{}}}']
  assert MustacheParser.split("{{{{foo}}}}") == ['{{', ref("foo"), '}}']

  invalid_refs = ['!@', '-', '$', ':']
  for val in invalid_refs:
    with pytest.raises(Ref.InvalidRefError):
      MustacheParser.split("{{%s}}" % val)
github wickman / pystachio / tests / test_parsing.py View on Github external
def test_mustache_re():
  assert MustacheParser.split("{{foo}}") == [ref("foo")]
  assert MustacheParser.split("{{_}}") == [ref("_")]
  with pytest.raises(Ref.InvalidRefError):
    MustacheParser.split("{{4}}")
  def chrange(a,b):
    return ''.join(map(lambda ch: str(chr(ch)), range(ord(a), ord(b)+1)))
  slash_w = chrange('a','z') + chrange('A','Z') + chrange('0','9') + '_'
  assert MustacheParser.split("{{%s}}" % slash_w) == [ref(slash_w)]

  # bracketing
  assert MustacheParser.split("{{{foo}}") == ['{', ref('foo')]
  assert MustacheParser.split("{{foo}}}") == [ref('foo'), '}']
  assert MustacheParser.split("{{{foo}}}") == ['{', ref('foo'), '}']
  assert MustacheParser.split("{{}}") == ['{{}}']
  assert MustacheParser.split("{{{}}}") == ['{{{}}}']
  assert MustacheParser.split("{{{{foo}}}}") == ['{{', ref("foo"), '}}']

  invalid_refs = ['!@', '-', '$', ':']
github wickman / pystachio / tests / test_parsing.py View on Github external
bar = "bar derp",
                   baz = "baz blerp")

  joined, unbound = MustacheParser.join(MustacheParser.split("{{foo}}"), oe)
  assert joined == "foo herp"
  assert unbound == []

  splits = MustacheParser.split('blech {{foo}} {{bar}} bonk {{&baz}} bling')
  joined, unbound = MustacheParser.join(splits, oe)
  assert joined == 'blech foo herp bar derp bonk {{baz}} bling'
  assert unbound == []

  splits = MustacheParser.split('{{foo}} {{bar}} {{unbound}}')
  joined, unbound = MustacheParser.join(splits, oe)
  assert joined == 'foo herp bar derp {{unbound}}'
  assert unbound == [Ref.from_address('unbound')]
github wickman / pystachio / tests / test_choice.py View on Github external
one = IntStr(123)
  two = IntStr("123")
  three = IntStr("abc")

  assert one == IntStr(123)
  assert two == IntStr("123")
  assert three == IntStr("abc")

  assert one == two
  assert not one == three
  assert one != three
  assert not one != two

  assert one.unwrap() == Integer(123)
  assert two.unwrap() == Integer(123)
  assert three.unwrap() == String("abc")
github wickman / pystachio / tests / test_choice.py View on Github external
def test_choice_default():
  """Ensure that choices with a default work correctly."""
  class Dumb(Struct):
    one = String

  class ChoiceDefaultStruct(Struct):
    a = Default(Choice("IntOrDumb", [Dumb, Integer]), 28)
    b = Integer

  class OtherStruct(Struct):
    first = ChoiceDefaultStruct
    second = String

  v = OtherStruct(second="hello")
  assert v.check()
  assert json.loads(v.json_dumps()) == {"second": "hello"}
  w = v(first=ChoiceDefaultStruct())
  assert w.check()
  assert json.loads(w.json_dumps()) == {'first': {'a': 28}, 'second': 'hello'}
  x = v(first=ChoiceDefaultStruct(a=296, b=36))
  assert x.check()
  assert json.loads(x.json_dumps()) == {'first': {'a': 296, 'b': 36},
                      'second': 'hello'}
  y = v(first=ChoiceDefaultStruct(a=Dumb(one="Oops"), b=37))
  assert y.check()
  assert json.loads(y.json_dumps()) == {'first': {'a': {'one': 'Oops'}, 'b': 37},
                                        'second': 'hello'}
github apache / aurora / tests / python / twitter / mesos / parsers / test_mesos_to_pystachio.py View on Github external
def test_config_with_other_replacements():
  hwc = copy.deepcopy(HELLO_WORLD)
  hwc['task']['start_command'] = 'echo %shard_id% %task_id% %port:http%'
  job = convert(hwc)
  main_process = [proc for proc in job.task().processes() if proc.name() == job.name()]
  assert len(main_process) == 1
  main_process = main_process[0]
  assert main_process.cmdline() == String(
      "echo {{mesos.instance}} {{thermos.task_id}} {{thermos.ports[http]}}")