summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorIrit Katriel <iritkatriel@yahoo.com>2020-05-18 18:14:12 (GMT)
committerGitHub <noreply@github.com>2020-05-18 18:14:12 (GMT)
commite6578a226d8a8a13d1062d154fad0fef28ee2416 (patch)
tree49fc3caf99ad4a057ebea2d2be2c6e4d9727ede6 /Lib/test
parent63b8e0cba3d43e53a8dd8878ee1443c8427f462d (diff)
downloadcpython-e6578a226d8a8a13d1062d154fad0fef28ee2416.zip
cpython-e6578a226d8a8a13d1062d154fad0fef28ee2416.tar.gz
cpython-e6578a226d8a8a13d1062d154fad0fef28ee2416.tar.bz2
bpo-40662: Fixed ast.get_source_segment for ast nodes that have incomplete location information (GH-20157)
Co-authored-by: Pablo Galindo <Pablogsal@gmail.com>
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_ast.py11
1 files changed, 11 insertions, 0 deletions
diff --git a/Lib/test/test_ast.py b/Lib/test/test_ast.py
index 6b71ada..e55d10b 100644
--- a/Lib/test/test_ast.py
+++ b/Lib/test/test_ast.py
@@ -1851,6 +1851,17 @@ class EndPositionTests(unittest.TestCase):
cdef = ast.parse(s).body[0]
self.assertEqual(ast.get_source_segment(s, cdef.body[0], padded=True), s_method)
+ def test_source_segment_missing_info(self):
+ s = 'v = 1\r\nw = 1\nx = 1\n\ry = 1\r\n'
+ v, w, x, y = ast.parse(s).body
+ del v.lineno
+ del w.end_lineno
+ del x.col_offset
+ del y.end_col_offset
+ self.assertIsNone(ast.get_source_segment(s, v))
+ self.assertIsNone(ast.get_source_segment(s, w))
+ self.assertIsNone(ast.get_source_segment(s, x))
+ self.assertIsNone(ast.get_source_segment(s, y))
class NodeVisitorTests(unittest.TestCase):
def test_old_constant_nodes(self):