From: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> Date: Sat, 13 Jul 2024 13:30:40 +0000 (+0200) Subject: [3.13] gh-121671: Increase test coverage of `ast.get_docstring` (GH-121674) (GH-121691) X-Git-Tag: v3.13.0b4~71 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=5e8bb98419b01301a6b12b110526bc9a348eeb0b;p=thirdparty%2FPython%2Fcpython.git [3.13] gh-121671: Increase test coverage of `ast.get_docstring` (GH-121674) (GH-121691) (cherry picked from commit 0a26aa5007cb32610366c31fbac846b5fe2f4f90) Co-authored-by: Tomas R --- diff --git a/Lib/test/test_ast.py b/Lib/test/test_ast.py index 744cd238ea14..4362ea61c6be 100644 --- a/Lib/test/test_ast.py +++ b/Lib/test/test_ast.py @@ -1626,6 +1626,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"') @@ -1650,6 +1656,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'