Exemple #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)
Exemple #2
0
def test_comment_at_first_character_python_indented_comments():
    """Don't handle indented comments."""
    text = cleandoc("""
        # Hello
          # world
        """)
    expected = "# Hello"

    assert PythonCommentStyle.comment_at_first_character(text) == expected
Exemple #3
0
def test_create_comment_python_dont_strip_newlines():
    """Include newlines in the comment."""
    text = "\nhello\n"
    expected = cleandoc("""
        #
        # hello
        #
        """)

    assert PythonCommentStyle.create_comment(text) == expected
Exemple #4
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)
Exemple #5
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
Exemple #6
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
Exemple #7
0
def test_comment_at_first_character_python():
    """Find the comment block at the first character."""
    text = cleandoc("""
        # Hello
        # world
        Spam
        """)
    expected = cleandoc("""
        # Hello
        # world
        """)

    assert PythonCommentStyle.comment_at_first_character(text) == expected
Exemple #8
0
def test_create_comment_python():
    """Create a simple Python comment."""
    text = cleandoc("""
        Hello

        world
        """)
    expected = cleandoc("""
        # Hello
        #
        # world
        """)

    assert PythonCommentStyle.create_comment(text) == expected
Exemple #9
0
def test_comment_at_first_character_python_no_comment():
    """The text does not start with a comment character."""
    with pytest.raises(CommentParseError):
        PythonCommentStyle.comment_at_first_character(" # Hello world")
Exemple #10
0
def test_parse_comment_python_multi_error():
    """Raise CommentParseError when trying to parse a multi-line Python
    comment.
    """
    with pytest.raises(CommentParseError):
        PythonCommentStyle._parse_comment_multi("Hello world")
Exemple #11
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)
Exemple #12
0
def test_create_comment_python_force_multi():
    """Raise CommentCreateError when creating a multi-line Python comment."""
    with pytest.raises(CommentCreateError):
        PythonCommentStyle.create_comment("hello", force_multi=True)
Exemple #13
0
def test_create_comment_python_strip_newlines():
    """Don't include unnecessary newlines in the comment."""
    text = "\nhello\n"
    expected = "# hello"

    assert PythonCommentStyle.create_comment(text) == expected