Пример #1
0
def test_jinja2_usage():
    d = BaseConf(task=MyTask())
    d.foo = "data"

    template = Template("{{ foo }}")
    value = template.render(**d)
    assert value == u"obj"
Пример #2
0
def test_set_get():
    d = BaseConf()
    d.foo = "data"
    assert d.foo == "data"

    d = BaseConf(task=MyTask())
    d.foo = "data"
    assert d.foo == "obj"

    d.setdefault("foo", "bla")
    assert d.foo == "obj"

    d.setdefault("bla", "bla")
    assert d.bla == "bla"

    assert d.get("not_exist", "default") == "default"
Пример #3
0
def test_get_from_multiple_tasks():
    class Task1(Task):
        @conf
        def foo(self):
            return 'task1'

    class Task2(Task):
        @conf
        def foo(self):
            return 'task1'

    c = BaseConf(tasks=[Task1(), Task2()])
    assert c.foo == 'task1'
Пример #4
0
def test_get_from_task():
    class MyTask(Task):
        @conf
        def foo(self):
            return 'task'

    c = BaseConf(tasks=[MyTask()])
    c.foo = 'user'
    assert c.foo == 'task'

    c.setdefault('foo', 'bla')
    assert c.foo == 'task'

    c.setdefault('bar', 'default')
    assert c.bar == 'default'

    assert c.get('not_exist', 'default') == 'default'
Пример #5
0
def test_set_get():
    c = BaseConf()
    c.foo = 'data'
    assert c.foo == 'data'