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)
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)
def test_from_string_indexes(): scope = Scope.from_string('a.2.c') assert scope == Scope(['a', 2, 'c'])
def test_from_string_iterable(): scope = Scope.from_string('a.2.c...') assert scope == Scope(['a', 2, 'c'], is_iterable=True)
def test_from_string_path(): scope = Scope.from_string('a.b.c') assert scope == Scope(['a', 'b', 'c'])
def test_from_string_single(): scope = Scope.from_string('a') assert scope == Scope(['a'])
def test_from_string_empty_iterable(): scope = Scope.from_string('...') assert scope == Scope(is_iterable=True)
def test_from_string_empty(): scope = Scope.from_string('') assert scope == Scope()
def test_from_string_invalid(): with pytest.raises(InvalidScope) as error: Scope.from_string('&$#@') assert error.value.scope == '&$#@'