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)
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
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
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)
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
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
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
def test_create_comment_python(): """Create a simple Python comment.""" text = cleandoc(""" Hello world """) expected = cleandoc(""" # Hello # # world """) assert PythonCommentStyle.create_comment(text) == expected
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")
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")
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)
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)
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