Exemplo n.º 1
0
def test_reset_after_adding_config():
    class MyConfig(_ConfigBase):
        foo = _ConfigValue("foo")
        bar = _ConfigValue("bar")

    c = VersionedConfig(MyConfig({"foo": "baz"}), version=1)

    c.update(version=2, bar="bazzinga")

    c.reset()
    assert c.bar is None
Exemplo n.º 2
0
def test_callback_reset():
    test_var = {"foo": 0}

    def set_global(dict_key, old_value, new_value):
        # TODO make test_var `nonlocal` once we drop py2 -- it can just be a
        # basic variable then instead of a dictionary
        test_var[dict_key] += 1

    class MyConfig(_ConfigBase):
        foo = _ConfigValue("foo", callbacks=[set_global])

    c = VersionedConfig(MyConfig({"foo": "bar"}), version=None)
    assert test_var["foo"] == 1
    c.update(version=2, **{"foo": "baz"})
    assert test_var["foo"] == 2
    c.reset()
    assert test_var["foo"] == 3