https://github.com/python/cpython/commit/e32b752808ceddea8cdcdcb52f57cd01abc42b10
commit: e32b752808ceddea8cdcdcb52f57cd01abc42b10
branch: 3.12
author: Miss Islington (bot) <[email protected]>
committer: encukou <[email protected]>
date: 2024-07-13T13:20:00Z
summary:

[3.12] gh-121671: Increase test coverage of `ast.get_docstring` (GH-121674) 
(GH-121690)

(cherry picked from commit 0a26aa5007cb32610366c31fbac846b5fe2f4f90)

Co-authored-by: Tomas R <[email protected]>

files:
M Lib/test/test_ast.py

diff --git a/Lib/test/test_ast.py b/Lib/test/test_ast.py
index a357fbfd228c02..fc823a4ed7b2bc 100644
--- a/Lib/test/test_ast.py
+++ b/Lib/test/test_ast.py
@@ -1366,6 +1366,12 @@ def test_get_docstring(self):
         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 @@ def test_get_docstring_none(self):
         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'

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]

Reply via email to