Esempio n. 1
0
def test_get_choice_in_struct():
    class Foo(Struct):
        foo = Required(String)

    class Bar(Struct):
        bar = Required(String)

    Item = Choice("Item", (Foo, Bar))

    class Qux(Struct):
        item = Choice([String, List(Item)])

    b = Qux(item=[Foo(foo="fubar")])
    assert b.get() == frozendict({'item': (frozendict({'foo': u'fubar'}), )})
Esempio n. 2
0
def test_get_choice_in_struct():
  class Foo(Struct):
    foo = Required(String)

  class Bar(Struct):
    bar = Required(String)

  Item = Choice("Item", (Foo, Bar))

  class Qux(Struct):
    item = Choice([String, List(Item)])

  b = Qux(item=[Foo(foo="fubar")])
  assert b.get() == frozendict({'item': (frozendict({'foo': u'fubar'}),)})
Esempio n. 3
0
 def l2t(obj):
   if isinstance(obj, list):
     return tuple(l2t(L) for L in obj)
   elif isinstance(obj, dict):
     return frozendict(obj)
   else:
     return obj
Esempio n. 4
0
def test_config_with_task_links():
    tl = Map(String, String)
    unresolved_tl = {
        "foo": "http://%host%:{{thermos.ports[foo]}}",
        "bar": "http://%host%:{{thermos.ports[bar]}}/{{mesos.instance}}",
    }
    resolved_tl = {"foo": "http://%host%:%port:foo%", "bar": "http://%host%:%port:bar%/%shard_id%"}
    aurora_config = AuroraConfig(HELLO_WORLD(task_links=tl(unresolved_tl)))
    assert aurora_config.task_links() == tl(resolved_tl)
    assert aurora_config.job().taskConfig.taskLinks == frozendict(resolved_tl)

    bad_tl = {"foo": "{{thermos.ports.bad}}"}
    with pytest.raises(AuroraConfig.InvalidConfig):
        AuroraConfig(HELLO_WORLD(task_links=tl(bad_tl))).job()
Esempio n. 5
0
def test_config_with_task_links():
    tl = Map(String, String)
    unresolved_tl = {
        'foo': 'http://%host%:{{thermos.ports[foo]}}',
        'bar': 'http://%host%:{{thermos.ports[bar]}}/{{mesos.instance}}',
    }
    resolved_tl = {
        'foo': 'http://%host%:%port:foo%',
        'bar': 'http://%host%:%port:bar%/%shard_id%'
    }
    aurora_config = AuroraConfig(HELLO_WORLD(task_links=tl(unresolved_tl)))
    assert aurora_config.task_links() == tl(resolved_tl)
    assert aurora_config.job().taskConfig.taskLinks == frozendict(resolved_tl)

    bad_tl = {'foo': '{{thermos.ports.bad}}'}
    with pytest.raises(AuroraConfig.InvalidConfig):
        AuroraConfig(HELLO_WORLD(task_links=tl(bad_tl))).job()
Esempio n. 6
0
 def get(self):
     return frozendict((k.get(), v.get()) for (k, v) in self._map)
Esempio n. 7
0
def test_reprs():
  fd = frozendict(a = 1, b = 2)
  assert repr(fd) == "frozendict({'a': 1, 'b': 2})"
  env = Environment(fd)
  repr(env)
Esempio n. 8
0
 def _init_schema_data(self):
   self._schema_data = {}
   for attr in self.TYPEMAP:
     self._schema_data[attr] = self.TYPEMAP[attr].default
   self._schema_data = frozendict(self._schema_data)
Esempio n. 9
0
 def get(self):
   return frozendict((k, v.get()) for k, v in self._schema_data.items() if v is not Empty)