コード例 #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
ファイル: test_target.py プロジェクト: faelenor/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)
コード例 #4
0
ファイル: test_target.py プロジェクト: faelenor/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)
コード例 #5
0
ファイル: test_target.py プロジェクト: faelenor/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)
コード例 #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)