cpython: b784c842a63c (original) (raw)
Mercurial > cpython
changeset 96707:b784c842a63c 3.4
Issue #20387: Add test capturing failure to roundtrip indented code in tokenize module. [#20387]
Jason R. Coombs jaraco@jaraco.com | |
---|---|
date | Sat, 20 Jun 2015 19:52:22 -0400 |
parents | 8bf1c158332f |
children | 49323e5f6391 |
files | Lib/test/test_tokenize.py |
diffstat | 1 files changed, 17 insertions(+), 0 deletions(-)[+] [-] Lib/test/test_tokenize.py 17 |
line wrap: on
line diff
--- a/Lib/test/test_tokenize.py +++ b/Lib/test/test_tokenize.py @@ -1229,6 +1229,22 @@ class UntokenizeTest(TestCase): self.assertEqual(untokenize(iter(tokens)), b'Hello ') +class TestRoundtrip(TestCase):
- def roundtrip(self, code):
if isinstance(code, str):[](#l1.9)
code = code.encode('utf-8')[](#l1.10)
return untokenize(tokenize(BytesIO(code).readline))[](#l1.11)
- def test_indentation_semantics_retained(self):
"""[](#l1.14)
Ensure that although whitespace might be mutated in a roundtrip,[](#l1.15)
the semantic meaning of the indentation remains consistent.[](#l1.16)
"""[](#l1.17)
code = "if False:\n\tx=3\n\tx=3\n"[](#l1.18)
codelines = roundtrip(code).split('\n')[](#l1.19)
self.assertEqual(codelines[1], codelines[2])[](#l1.20)
+ + test = {"doctests" : doctests, 'decistmt': decistmt} def test_main(): @@ -1239,6 +1255,7 @@ def test_main(): support.run_unittest(TestDetectEncoding) support.run_unittest(TestTokenize) support.run_unittest(UntokenizeTest)