summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorTomas R <tomas.roun8@gmail.com>2024-07-13 12:59:15 (GMT)
committerGitHub <noreply@github.com>2024-07-13 12:59:15 (GMT)
commit0a26aa5007cb32610366c31fbac846b5fe2f4f90 (patch)
tree06f46c7f6fec309f29465652635d41a869601ab1 /Lib
parentfc2178117538c161471711073887f34bcd464cc1 (diff)
downloadcpython-0a26aa5007cb32610366c31fbac846b5fe2f4f90.zip
cpython-0a26aa5007cb32610366c31fbac846b5fe2f4f90.tar.gz
cpython-0a26aa5007cb32610366c31fbac846b5fe2f4f90.tar.bz2
gh-121671: Increase test coverage of `ast.get_docstring` (GH-121674)
Increase test coverage for `ast.get_docstring`
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_ast.py9
1 files changed, 9 insertions, 0 deletions
diff --git a/Lib/test/test_ast.py b/Lib/test/test_ast.py
index 497c3f2..55725ec 100644
--- a/Lib/test/test_ast.py
+++ b/Lib/test/test_ast.py
@@ -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'