示例#1
0
def test_generate():
    target = Target(
        template_name="foo.txt.tpl", filename="foo{{ x }}.txt", scopes={"x": Scope.from_string("numbers...")}
    )
    environment = Environment(loader=DictLoader({"foo.txt.tpl": "foo {{ x }}"}))
    context = {"numbers": [42, 7]}
    result = target.generate(environment, context)

    assert next(result) == ("foo42.txt", "foo 42")
    assert next(result) == ("foo7.txt", "foo 7")

    with raises(StopIteration):
        next(result)
示例#2
0
def test_generate():
    target = Target(
        template_name='foo.txt.tpl',
        filename='foo{{ x }}.txt',
        scopes={'x': Scope.from_string('numbers...')},
    )
    environment = Environment(loader=DictLoader({
        'foo.txt.tpl': 'foo {{ x }}',
    }))
    context = {'numbers': [42, 7]}
    result = target.generate(environment, context)

    assert next(result) == ('foo42.txt', 'foo 42')
    assert next(result) == ('foo7.txt', 'foo 7')

    with raises(StopIteration):
        next(result)
示例#3
0
def test_from_string_indexes():
    scope = Scope.from_string('a.2.c')
    assert scope == Scope(['a', 2, 'c'])
示例#4
0
def test_from_string_iterable():
    scope = Scope.from_string('a.2.c...')
    assert scope == Scope(['a', 2, 'c'], is_iterable=True)
示例#5
0
def test_from_string_path():
    scope = Scope.from_string('a.b.c')
    assert scope == Scope(['a', 'b', 'c'])
示例#6
0
def test_from_string_single():
    scope = Scope.from_string('a')
    assert scope == Scope(['a'])
示例#7
0
def test_from_string_empty_iterable():
    scope = Scope.from_string('...')
    assert scope == Scope(is_iterable=True)
示例#8
0
def test_from_string_empty():
    scope = Scope.from_string('')
    assert scope == Scope()
示例#9
0
def test_from_string_invalid():
    with pytest.raises(InvalidScope) as error:
        Scope.from_string('&$#@')

    assert error.value.scope == '&$#@'