Exemple #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'}), )})
Exemple #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'}),)})
Exemple #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
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()
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()
Exemple #6
0
 def get(self):
     return frozendict((k.get(), v.get()) for (k, v) in self._map)
Exemple #7
0
def test_reprs():
  fd = frozendict(a = 1, b = 2)
  assert repr(fd) == "frozendict({'a': 1, 'b': 2})"
  env = Environment(fd)
  repr(env)
Exemple #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)
Exemple #9
0
 def get(self):
   return frozendict((k, v.get()) for k, v in self._schema_data.items() if v is not Empty)