]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.12] gh-121671: Increase test coverage of `ast.get_docstring` (GH-121674) (GH-121690)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Sat, 13 Jul 2024 13:20:00 +0000 (15:20 +0200)
committerGitHub <noreply@github.com>
Sat, 13 Jul 2024 13:20:00 +0000 (13:20 +0000)
(cherry picked from commit 0a26aa5007cb32610366c31fbac846b5fe2f4f90)

Co-authored-by: Tomas R <tomas.roun8@gmail.com>
Lib/test/test_ast.py

index a357fbfd228c025faefe5b544df71d26daf04211..fc823a4ed7b2bc7d573db9e8f6a2a1cebc6a179a 100644 (file)
@@ -1366,6 +1366,12 @@ Module(
         node = ast.parse('async def foo():\n  """spam\n  ham"""')
         self.assertEqual(ast.get_docstring(node.body[0]), 'spam\nham')
 
+        node = ast.parse('async def foo():\n  """spam\n  ham"""')
+        self.assertEqual(ast.get_docstring(node.body[0], clean=False), 'spam\n  ham')
+
+        node = ast.parse('x')
+        self.assertRaises(TypeError, ast.get_docstring, node.body[0])
+
     def test_get_docstring_none(self):
         self.assertIsNone(ast.get_docstring(ast.parse('')))
         node = ast.parse('x = "not docstring"')
@@ -1390,6 +1396,9 @@ Module(
         node = ast.parse('async def foo():\n  x = "not docstring"')
         self.assertIsNone(ast.get_docstring(node.body[0]))
 
+        node = ast.parse('async def foo():\n  42')
+        self.assertIsNone(ast.get_docstring(node.body[0]))
+
     def test_multi_line_docstring_col_offset_and_lineno_issue16806(self):
         node = ast.parse(
             '"""line one\nline two"""\n\n'