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_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})
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 == {
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)
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 })
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)
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))
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