def test_module_config_on_configure_observer_error():
    reached_a = False
    reached_b = False
    def mycallback(oc, nc):
        nonlocal reached_a
        nonlocal reached_b
        reached_a = True
        raise KeyError("mycallback")
        reached_b = True
    module_config = ModuleConfig("""\
a = Int(default=2)
b = Int(default=5)
""",
        on_configure=[mycallback])
    module_config.configure()
    assert reached_a
    assert not reached_b
Beispiel #2
0
from zirkon.program_config import ModuleConfig


CONF = ModuleConfig("""
size = Int(default=0)
""")


_LST = None

def create_lst(old_config, new_config):
    global _LST
    if _LST is None or old_config is None or old_config["size"] != new_config["size"]:
        _LST = [0 for _ in range(new_config["size"])]

CONF.add_on_configure_observer(create_lst)

def get_size():
    return CONF["size"]

def get_lst():
    return _LST

Beispiel #3
0
from zirkon.program_config import ModuleConfig

CONF = ModuleConfig("""\
opt0 = Str()
""", register=False)

CONF.relocate()
def test_module_config_on_configure_observer_run():
    cb0 = MyCallback(0, 0)
    cb1 = MyCallback(1, 1)
    assert cb0.ab == (0, 0)
    assert cb1.ab == (1, 1)
    module_config = ModuleConfig("""\
a = Int(default=2)
b = Int(default=5)
""",
        on_configure=[cb0, cb1])
    assert cb0.ab == (0, 0)
    assert cb1.ab == (1, 1)
    module_config.configure()
    assert cb0.ab == (2, 5)
    assert cb1.ab == (2, 5)
    cfg = Config.from_string("""\
a = 100
b = 3""")
    module_config.configure(cfg)
    assert cb0.ab == (100, 3)
    assert cb1.ab == (100, 3)
    cfg["a"] = 200
    module_config.configure(cfg)
    assert cb0.ab == (200, 3)
    assert cb1.ab == (200, 3)
    module_config.remove_on_configure_observer(cb1)
    cfg["a"] = 300
    module_config.configure(cfg)
    assert cb0.ab == (300, 3)
    assert cb1.ab == (200, 3)