def test_generate_scoped_contexts_no_scopes(context): target = Target(template_name="foo.txt.tpl", filename="foo.txt", scopes={}) result = target.generate_scoped_contexts(context) assert next(result) == context with raises(StopIteration): next(result)
def test_generate_scoped_contexts_simple_scopes(context): target = Target( template_name="foo.txt.tpl", filename="foo.txt", scopes={"one": Scope(["a", "b"]), "two": Scope(["f"]), "three": Scope(["h"])}, ) result = target.generate_scoped_contexts(context) assert next(result) == {"one": "c", "two": "g", "three": ["i", "j", "k"]} with raises(StopIteration): next(result)
def test_generate_scoped_contexts_no_scopes(context): target = Target( template_name='foo.txt.tpl', filename='foo.txt', scopes={}, ) result = target.generate_scoped_contexts(context) assert next(result) == context with raises(StopIteration): next(result)
def test_generate_scoped_contexts_iterable_scopes(context): target = Target( template_name='foo.txt.tpl', filename='foo.txt', scopes={ 'one': Scope(['a', 'b']), 'two': Scope(['f']), 'three': Scope(['h'], is_iterable=True), 'four': Scope(['l'], is_iterable=True), }, ) result = target.generate_scoped_contexts(context) assert next(result) == { 'one': 'c', 'two': 'g', 'three': 'i', 'four': 'm', } assert next(result) == { 'one': 'c', 'two': 'g', 'three': 'j', 'four': 'm', } assert next(result) == { 'one': 'c', 'two': 'g', 'three': 'k', 'four': 'm', } assert next(result) == { 'one': 'c', 'two': 'g', 'three': 'i', 'four': 'n', } assert next(result) == { 'one': 'c', 'two': 'g', 'three': 'j', 'four': 'n', } assert next(result) == { 'one': 'c', 'two': 'g', 'three': 'k', 'four': 'n', } with raises(StopIteration): next(result)
def test_generate_scoped_contexts_simple_scopes(context): target = Target( template_name='foo.txt.tpl', filename='foo.txt', scopes={ 'one': Scope(['a', 'b']), 'two': Scope(['f']), 'three': Scope(['h']), }, ) result = target.generate_scoped_contexts(context) assert next(result) == { 'one': 'c', 'two': 'g', 'three': ['i', 'j', 'k'], } with raises(StopIteration): next(result)
def test_generate_scoped_contexts_iterable_scopes(context): target = Target( template_name="foo.txt.tpl", filename="foo.txt", scopes={ "one": Scope(["a", "b"]), "two": Scope(["f"]), "three": Scope(["h"], is_iterable=True), "four": Scope(["l"], is_iterable=True), }, ) result = target.generate_scoped_contexts(context) assert next(result) == {"one": "c", "two": "g", "three": "i", "four": "m"} assert next(result) == {"one": "c", "two": "g", "three": "j", "four": "m"} assert next(result) == {"one": "c", "two": "g", "three": "k", "four": "m"} assert next(result) == {"one": "c", "two": "g", "three": "i", "four": "n"} assert next(result) == {"one": "c", "two": "g", "three": "j", "four": "n"} assert next(result) == {"one": "c", "two": "g", "three": "k", "four": "n"} with raises(StopIteration): next(result)