Skip to content

Commit e1d5d10

Browse files
committed
Increase test coverage for ast.get_docstring
1 parent 4e36dd7 commit e1d5d10

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

Lib/test/test_ast.py

+9
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)