Skip to content

Commit 0a26aa5

Browse files
authored
gh-121671: Increase test coverage of ast.get_docstring (GH-121674)
Increase test coverage for `ast.get_docstring`
1 parent fc21781 commit 0a26aa5

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

Lib/test/test_ast.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1821,6 +1821,12 @@ def test_get_docstring(self):
18211821
node = ast.parse('async def foo():\n """spam\n ham"""')
18221822
self.assertEqual(ast.get_docstring(node.body[0]), 'spam\nham')
18231823

1824+
node = ast.parse('async def foo():\n """spam\n ham"""')
1825+
self.assertEqual(ast.get_docstring(node.body[0], clean=False), 'spam\n ham')
1826+
1827+
node = ast.parse('x')
1828+
self.assertRaises(TypeError, ast.get_docstring, node.body[0])
1829+
18241830
def test_get_docstring_none(self):
18251831
self.assertIsNone(ast.get_docstring(ast.parse('')))
18261832
node = ast.parse('x = "not docstring"')
@@ -1845,6 +1851,9 @@ def test_get_docstring_none(self):
18451851
node = ast.parse('async def foo():\n x = "not docstring"')
18461852
self.assertIsNone(ast.get_docstring(node.body[0]))
18471853

1854+
node = ast.parse('async def foo():\n 42')
1855+
self.assertIsNone(ast.get_docstring(node.body[0]))
1856+
18481857
def test_multi_line_docstring_col_offset_and_lineno_issue16806(self):
18491858
node = ast.parse(
18501859
'"""line one\nline two"""\n\n'

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy