]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-121671: Increase test coverage of `ast.get_docstring` (GH-121674)
authorTomas R <tomas.roun8@gmail.com>
Sat, 13 Jul 2024 12:59:15 +0000 (14:59 +0200)
committerGitHub <noreply@github.com>
Sat, 13 Jul 2024 12:59:15 +0000 (14:59 +0200)
Increase test coverage for `ast.get_docstring`

Lib/test/test_ast.py

index 497c3f261a1fcaecc84065b637d066b16941cb42..55725ec36fd3a7feb1989e749f9a5573c2962ba0 100644 (file)
@@ -1821,6 +1821,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"')
@@ -1845,6 +1851,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'