summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorYury Selivanov <yselivanov@sprymix.com>2015-05-18 16:50:52 (GMT)
committerYury Selivanov <yselivanov@sprymix.com>2015-05-18 16:50:52 (GMT)
commit8085b80c187865e6feab652465d0f6742b9083a1 (patch)
tree08000252dd137273867ac5e61710fa8c64fdc159 /Lib/test
parenta2c145c2f3def66a39295422a3d99b0b357978d5 (diff)
downloadcpython-8085b80c187865e6feab652465d0f6742b9083a1.zip
cpython-8085b80c187865e6feab652465d0f6742b9083a1.tar.gz
cpython-8085b80c187865e6feab652465d0f6742b9083a1.tar.bz2
Issue 24226: Fix parsing of many sequential one-line 'def' statements.
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_coroutines.py23
-rw-r--r--Lib/test/test_tokenize.py11
2 files changed, 34 insertions, 0 deletions
diff --git a/Lib/test/test_coroutines.py b/Lib/test/test_coroutines.py
index 7efd5c9..e79896a 100644
--- a/Lib/test/test_coroutines.py
+++ b/Lib/test/test_coroutines.py
@@ -1,4 +1,5 @@
import contextlib
+import inspect
import sys
import types
import unittest
@@ -87,6 +88,28 @@ class AsyncBadSyntaxTest(unittest.TestCase):
import test.badsyntax_async9
+class TokenizerRegrTest(unittest.TestCase):
+
+ def test_oneline_defs(self):
+ buf = []
+ for i in range(500):
+ buf.append('def i{i}(): return {i}'.format(i=i))
+ buf = '\n'.join(buf)
+
+ # Test that 500 consequent, one-line defs is OK
+ ns = {}
+ exec(buf, ns, ns)
+ self.assertEqual(ns['i499'](), 499)
+
+ # Test that 500 consequent, one-line defs *and*
+ # one 'async def' following them is OK
+ buf += '\nasync def foo():\n return'
+ ns = {}
+ exec(buf, ns, ns)
+ self.assertEqual(ns['i499'](), 499)
+ self.assertTrue(inspect.iscoroutinefunction(ns['foo']))
+
+
class CoroutineTest(unittest.TestCase):
def test_gen_1(self):
diff --git a/Lib/test/test_tokenize.py b/Lib/test/test_tokenize.py
index ed75171..43fadaf 100644
--- a/Lib/test/test_tokenize.py
+++ b/Lib/test/test_tokenize.py
@@ -1289,6 +1289,17 @@ class TestTokenize(TestCase):
self.assertTrue(encoding_used, encoding)
+ def test_oneline_defs(self):
+ buf = []
+ for i in range(500):
+ buf.append('def i{i}(): return {i}'.format(i=i))
+ buf.append('OK')
+ buf = '\n'.join(buf)
+
+ # Test that 500 consequent, one-line defs is OK
+ toks = list(tokenize(BytesIO(buf.encode('utf-8')).readline))
+ self.assertEqual(toks[-2].string, 'OK') # [-1] is always ENDMARKER
+
def assertExactTypeEqual(self, opstr, *optypes):
tokens = list(tokenize(BytesIO(opstr.encode('utf-8')).readline))
num_optypes = len(optypes)