How to use the pystachio.base.Environment 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_base.py View on Github external
def test_environment_merge():
  oe1 = Environment(a = 1)
  oe2 = Environment(b = 2)
  assert Environment(oe1, oe2)._table == {
    ref('a'): '1',
    ref('b'): '2'
  }

  oe1 = Environment(a = 1, b = 2)
  oe2 = Environment(a = 1, b = {'c': 2})
  assert Environment(oe1, oe2)._table == {
    ref('a'): '1',
    ref('b'): '2',
    ref('b.c'): '2'
  }

  oe1 = Environment(a = 1, b = 2)
  oe2 = Environment(a = 1, b = {'c': 2})
github wickman / pystachio / tests / test_base.py View on Github external
def test_environment_merge():
  oe1 = Environment(a = 1)
  oe2 = Environment(b = 2)
  assert Environment(oe1, oe2)._table == {
    ref('a'): '1',
    ref('b'): '2'
  }

  oe1 = Environment(a = 1, b = 2)
  oe2 = Environment(a = 1, b = {'c': 2})
  assert Environment(oe1, oe2)._table == {
    ref('a'): '1',
    ref('b'): '2',
    ref('b.c'): '2'
  }

  oe1 = Environment(a = 1, b = 2)
  oe2 = Environment(a = 1, b = {'c': 2})
  assert Environment(oe2, oe1)._table == {
github wickman / pystachio / tests / test_base.py View on Github external
assert oe._table == dtd({'a': 2}), "last update should win"

  oe = Environment({'b': 1}, a = 2)
  assert oe._table == dtd({'a': 2, 'b': 1})

  oe = Environment(oe, a = 3)
  assert oe._table == dtd({'a': 3, 'b': 1})

  bad_values = [None, 3, 'a', type, ()]
  for value in bad_values:
    with pytest.raises(ValueError):
      Environment(value)
  bad_values = [None, type, ()]
  for value in bad_values:
    with pytest.raises(ValueError):
      Environment(foo = value)
github wickman / pystachio / tests / test_base.py View on Github external
def test_environment_merge():
  oe1 = Environment(a = 1)
  oe2 = Environment(b = 2)
  assert Environment(oe1, oe2)._table == {
    ref('a'): '1',
    ref('b'): '2'
  }

  oe1 = Environment(a = 1, b = 2)
  oe2 = Environment(a = 1, b = {'c': 2})
  assert Environment(oe1, oe2)._table == {
    ref('a'): '1',
    ref('b'): '2',
    ref('b.c'): '2'
  }

  oe1 = Environment(a = 1, b = 2)
  oe2 = Environment(a = 1, b = {'c': 2})
  assert Environment(oe2, oe1)._table == {
    ref('a'): '1',
    ref('b'): '2',
    ref('b.c'): '2'
  }

  oe1 = Environment(a = { 'b': 1 })
  oe2 = Environment(a = { 'c': 2 })
github wickman / pystachio / pystachio / base.py View on Github external
def translate_to_scopes(*args, **kw):
    scopes = [arg if isinstance(arg, Namable) else Environment.wrap(arg)
              for arg in args]
    if kw:
      scopes.append(Environment(kw))
    return tuple(scopes)
github wickman / pystachio / pystachio / base.py View on Github external
def wrap(value):
    if isinstance(value, dict):
      return Environment(value)
    elif isinstance(value, (Environment, Object)):
      return value
    else:
      if isinstance(value, Compatibility.numeric + Compatibility.stringy):
        return str(value)
      else:
        raise ValueError(
          'Environment values must be strings, numbers, Objects or other Environments. '
          'Got %s instead.' % type(value))
github wickman / pystachio / pystachio / base.py View on Github external
def _assimilate_dictionary(self, d):
    for key, val in d.items():
      val = Environment.wrap(val)
      rkey = Ref.wrap(key)
      if isinstance(val, Environment):
        for vkey, vval in val._table.items():
          self._table[rkey + vkey] = vval
      else:
        self._table[rkey] = val