コード例 #1
0
def test_cell_ends_with_function_or_class():
    text = """class A:
    __init__():
    '''A docstring
with two lines or more'''
        self.a = 0
"""
    assert cell_ends_with_function_or_class(text.splitlines())

    lines = ["#", "#"]
    assert not cell_ends_with_function_or_class(lines)

    text = """# two blank line after this class
class A:
    pass


# so we do not need to insert two blank lines below this cell
    """
    assert not cell_ends_with_function_or_class(text.splitlines())

    text = """# All lines
# are commented"""
    assert not cell_ends_with_function_or_class(text.splitlines())

    text = """# Two blank lines after function
def f(x):
    return x


# And a comment here"""
    assert not cell_ends_with_function_or_class(text.splitlines())

    assert not cell_ends_with_function_or_class(["", "#"])
コード例 #2
0
def test_pep8_lines_between_cells_bis():
    prev_lines = """def f(x):
    return x""".splitlines()

    next_lines = """# A markdown cell

# An instruction
a = 5
""".splitlines()

    assert cell_ends_with_function_or_class(prev_lines)
    assert cell_has_code(next_lines)
    assert pep8_lines_between_cells(prev_lines, next_lines, ".py") == 2

    next_lines = """# A markdown cell

# Only markdown here
# And here
""".splitlines()

    assert cell_ends_with_function_or_class(prev_lines)
    assert not cell_has_code(next_lines)
    assert pep8_lines_between_cells(prev_lines, next_lines, ".py") == 1