def test_scope_override(): class MesosConfig(Struct): ports = Map(String, Integer) config = MesosConfig(ports = {'http': 80, 'health': 8888}) env = Environment({ref('config.ports[http]'): 5000}, config = config) assert env.find(ref('config.ports[http]')) == '5000' assert env.find(ref('config.ports[health]')) == Integer(8888)
def test_scope_override(): class MesosConfig(Struct): ports = Map(String, Integer) config = MesosConfig(ports={'http': 80, 'health': 8888}) env = Environment({ref('config.ports[http]'): 5000}, config=config) assert env.find(ref('config.ports[http]')) == '5000' assert env.find(ref('config.ports[health]')) == Integer(8888)
def test_ref_lookup(): oe = Environment(a = 1) assert oe.find(ref("a")) == '1' oe = Environment(a = {'b': 1}) assert oe.find(ref("a.b")) == '1' oe = Environment(a = {'b': {'c': 1}, 'c': Environment(d = 2)}) assert oe.find(ref('a.b.c')) == '1' assert oe.find(ref('a.c.d')) == '2' for address in ["a", "a.b", "a.c"]: with pytest.raises(Namable.NotFound): oe.find(ref(address)) oe = List(String)(["a", "b", "c"]) assert oe.find(ref('[0]')) == String('a') with pytest.raises(Namable.NotFound): oe.find(ref('[3]')) oe = List(Map(String,Integer))([{'a': 27}]) oe.find(ref('[0][a]')) == Integer(27) Environment(foo = oe).find(ref('foo[0][a]')) == Integer(27)
def test_ref_lookup(): oe = Environment(a=1) assert oe.find(ref("a")) == '1' oe = Environment(a={'b': 1}) assert oe.find(ref("a.b")) == '1' oe = Environment(a={'b': {'c': 1}, 'c': Environment(d=2)}) assert oe.find(ref('a.b.c')) == '1' assert oe.find(ref('a.c.d')) == '2' for address in ["a", "a.b", "a.c"]: with pytest.raises(Namable.NotFound): oe.find(ref(address)) oe = List(String)(["a", "b", "c"]) assert oe.find(ref('[0]')) == String('a') with pytest.raises(Namable.NotFound): oe.find(ref('[3]')) oe = List(Map(String, Integer))([{'a': 27}]) oe.find(ref('[0][a]')) == Integer(27) Environment(foo=oe).find(ref('foo[0][a]')) == Integer(27)
def test_environment_find(): oe1 = Environment(a = { 'b': 1 }) oe2 = Environment(a = { 'b': { 'c': List(Integer)([1,2,3]) } } ) oe = Environment(oe1, oe2) assert oe.find(ref('a.b')) == '1' assert oe.find(ref('a.b.c[0]')) == Integer(1) assert oe.find(ref('a.b.c[1]')) == Integer(2) assert oe.find(ref('a.b.c[2]')) == Integer(3) missing_refs = [ref('b'), ref('b.c'), ref('a.c'), ref('a.b.c[3]')] for r in missing_refs: with pytest.raises(Namable.NotFound): oe.find(r) oe = Environment(a = { 'b': { 'c': 5 } } ) assert oe.find(ref('a.b.c')) == '5'