예제 #1
0
파일: test_target.py 프로젝트: ereOn/pygen
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)
예제 #2
0
파일: test_target.py 프로젝트: ereOn/pygen
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)
예제 #3
0
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)
예제 #4
0
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)
예제 #5
0
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)
예제 #6
0
파일: test_target.py 프로젝트: ereOn/pygen
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)