Ejemplo n.º 1
0
def test_parse_comment_python_single_line_is_not_comment():
    """Raise CommentParseError when a single line is not a comment."""
    text = cleandoc("""
        # Hello
        world
        """)

    with pytest.raises(CommentParseError):
        PythonCommentStyle.parse_comment(text)
Ejemplo n.º 2
0
def test_parse_comment_python_fail_on_newline():
    """If a provided comment does not start with the comment character, fail."""
    text = dedent("""

        #
        # hello
        #

        """)
    with pytest.raises(CommentParseError):
        assert PythonCommentStyle.parse_comment(text)
Ejemplo n.º 3
0
def test_parse_comment_python_indented():
    """Preserve indentations in Python comments."""
    text = cleandoc("""
        # def foo():
        #     print("foo")
        """)
    expected = cleandoc("""
        def foo():
            print("foo")
        """)

    assert PythonCommentStyle.parse_comment(text) == expected
Ejemplo n.º 4
0
def test_parse_comment_python_strip_newlines():
    """When given a comment, remove newlines before and after before parsing."""
    text = dedent("""

        #
        # hello
        #

        """)
    expected = "\nhello\n"

    assert PythonCommentStyle.parse_comment(text) == expected
Ejemplo n.º 5
0
def test_parse_comment_python():
    """Parse a simple Python comment."""
    text = cleandoc("""
        # Hello
        #
        # world
        """)
    expected = cleandoc("""
        Hello

        world
        """)

    assert PythonCommentStyle.parse_comment(text) == expected
Ejemplo n.º 6
0
def test_parse_comment_python_not_a_comment():
    """Raise CommentParseError when a comment isn't provided."""
    text = "Hello world"

    with pytest.raises(CommentParseError):
        PythonCommentStyle.parse_comment(text)