Пример #1
0
def test_lines_to_statements(file_name):
    lines = add_context(file=file_name, lines=(
        'line1\n',
        '  line2  \n',
        'line3 part1\\\n',
        'line3 part2\n',
        'line \\ number 4\n',
        'line5 part1\\\n',
        '  line5\\ part2\\\n',
        'line5 part3\n',
        'line6',
    ))
    expected = (
        line_in_context('line1', context(file_name, 1)),
        line_in_context('  line2  ', context(file_name, 2)),
        line_in_context('line3 part1\nline3 part2', context(file_name, 3)),
        line_in_context('line \\ number 4', context(file_name, 5)),
        line_in_context(
            'line5 part1\n  line5\\ part2\nline5 part3',
            context(file_name, 6)
        ),
        line_in_context('line6', context(file_name, 9)),
    )
    result = tuple(lines_to_statements(lines))
    assert expected == result
Пример #2
0
def test_statement_to_object(file_name):
    statements = add_context(file_name, (
        '# some comment',
        'a_command with:args',
    ))
    expected_objects = (
        comment(' some comment', context(file_name, 1)),
        command('a_command', 'with:args', context(file_name, 2)),
    )
    for sttmt, expected in _it.izip(statements, expected_objects):
        result = statement_to_object(sttmt)
        assert expected == result
Пример #3
0
def test_add_context(file_name):
    lines = (
        'line1',
        'line2',
        'line3',
    )
    expected = (
        line_in_context(context=context(file=file_name, line=1), line='line1'),
        line_in_context(context=context(file=file_name, line=2), line='line2'),
        line_in_context(context=context(file=file_name, line=3), line='line3'),
    )
    result = tuple(add_context(file=file_name, lines=lines))
    assert expected == result
Пример #4
0
def test_add_context_nested(file_name, some_context):
    lines = (
        'line1',
        'line2',
        'line3',
    )
    ctx = (
        nested_context(file_name, cnt, some_context) for cnt in _it.count(1)
    )
    expected = (
        line_in_context(context=next(ctx), line='line1'),
        line_in_context(context=next(ctx), line='line2'),
        line_in_context(context=next(ctx), line='line3'),
    )
    result = tuple(
        add_context(file=file_name, lines=lines, nest_in=some_context)
    )
    assert expected == result