def test_attach_comment_with_one_line_comment_changes_only_text(
         self, stmt: py.Statement, line: py.Line, comment: str):
     clone = line.clone()
     stmt.comments = [comment]
     lines = stmt.attach_comment(line)
     assert len(lines) == 1, "no additional lines must be created"
     l = lines[0]
     assert l is line, "the same Line object must be returned"
     assert (l.text == f"{clone.text}  # {comment}"
             ), "the comment is appended to Line.text"
     assert l.indent_level == clone.indent_level, "Line.indent_level must not change"
    def test_attach_comment_with_multiline_comment_adds_lines_above(
            self, stmt: py.Statement, line: py.Line, comments: List[str]):
        clone = line.clone()
        stmt.comments = comments
        lines = stmt.attach_comment(line)
        assert len(lines) == 1 + len(comments)

        l = lines[-1]
        assert l is line, "the same Line object must be returned last"
        assert l.text == clone.text, "Line.text must not change"
        assert l.indent_level == clone.indent_level, "Line.indent_level must not change"

        assert lines[:-1] == [
            py.Line(f"# {s}", clone.indent_level) for s in comments
        ], "all lines but the last are standalone comment lines"
 def test_attach_comment_without_comment_changes_nothing(
         self, stmt: py.Statement, line: py.Line):
     clone = line.clone()
     stmt.comments.clear(
     )  # Some comments may have been generated by Hypothesis.
     lines = stmt.attach_comment(line)
     assert len(lines) == 1, "no additional lines must be created"
     l = lines[0]
     assert l is line, "the same Line object must be returned"
     assert l.text == clone.text, "Line.text must not change"
     assert l.indent_level == clone.indent_level, "Line.indent_level must not change"
 def test_comment_lines(self, stmt: py.Statement, level: int,
                        comments: List[str]):
     stmt.comments = comments
     x = py.Line.INDENT_UNIT
     assert [str(l) for l in stmt.comment_lines(level)
             ] == [x * level + f"# {line}" for line in comments]