summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_tokenize.py
diff options
context:
space:
mode:
authorThomas Kluyver <takowl@gmail.com>2018-06-05 17:26:39 (GMT)
committerCarol Willing <carolcode@willingconsulting.com>2018-06-05 17:26:39 (GMT)
commitc56b17bd8c7a3fd03859822246633d2c9586f8bd (patch)
tree346fb8b3a6614679232792b3f46398b33e5f3c0e /Lib/test/test_tokenize.py
parentc2745d2d05546d76f655ab450eb23d1af39e0b1c (diff)
downloadcpython-c56b17bd8c7a3fd03859822246633d2c9586f8bd.zip
cpython-c56b17bd8c7a3fd03859822246633d2c9586f8bd.tar.gz
cpython-c56b17bd8c7a3fd03859822246633d2c9586f8bd.tar.bz2
bpo-12486: Document tokenize.generate_tokens() as public API (#6957)
* Document tokenize.generate_tokens() * Add news file * Add test for generate_tokens * Document behaviour around ENCODING token * Add generate_tokens to __all__
Diffstat (limited to 'Lib/test/test_tokenize.py')
-rw-r--r--Lib/test/test_tokenize.py17
1 files changed, 15 insertions, 2 deletions
diff --git a/Lib/test/test_tokenize.py b/Lib/test/test_tokenize.py
index 3520a67..93e40de 100644
--- a/Lib/test/test_tokenize.py
+++ b/Lib/test/test_tokenize.py
@@ -1,8 +1,8 @@
from test import support
from tokenize import (tokenize, _tokenize, untokenize, NUMBER, NAME, OP,
STRING, ENDMARKER, ENCODING, tok_name, detect_encoding,
- open as tokenize_open, Untokenizer)
-from io import BytesIO
+ open as tokenize_open, Untokenizer, generate_tokens)
+from io import BytesIO, StringIO
import unittest
from unittest import TestCase, mock
from test.test_grammar import (VALID_UNDERSCORE_LITERALS,
@@ -919,6 +919,19 @@ async def f():
DEDENT '' (7, 0) (7, 0)
""")
+class GenerateTokensTest(TokenizeTest):
+ def check_tokenize(self, s, expected):
+ # Format the tokens in s in a table format.
+ # The ENDMARKER is omitted.
+ result = []
+ f = StringIO(s)
+ for type, token, start, end, line in generate_tokens(f.readline):
+ if type == ENDMARKER:
+ break
+ type = tok_name[type]
+ result.append(f" {type:10} {token!r:13} {start} {end}")
+ self.assertEqual(result, expected.rstrip().splitlines())
+
def decistmt(s):
result = []