diff options
author | Jason R. Coombs <jaraco@jaraco.com> | 2015-06-20 23:52:22 (GMT) |
---|---|---|
committer | Jason R. Coombs <jaraco@jaraco.com> | 2015-06-20 23:52:22 (GMT) |
commit | 5713b3c5bf0c27d5443e6d3a1cd2ce3495778597 (patch) | |
tree | 4930f3172c49eb4f0a93d6cf4f30556f69594616 | |
parent | 7cf36387e4a4e7f9686274cdfaeaeddc76ff5902 (diff) | |
download | cpython-5713b3c5bf0c27d5443e6d3a1cd2ce3495778597.zip cpython-5713b3c5bf0c27d5443e6d3a1cd2ce3495778597.tar.gz cpython-5713b3c5bf0c27d5443e6d3a1cd2ce3495778597.tar.bz2 |
Issue #20387: Add test capturing failure to roundtrip indented code in tokenize module.
-rw-r--r-- | Lib/test/test_tokenize.py | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/Lib/test/test_tokenize.py b/Lib/test/test_tokenize.py index 3e8a654..00a2c2b 100644 --- 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): + code = code.encode('utf-8') + return untokenize(tokenize(BytesIO(code).readline)) + + def test_indentation_semantics_retained(self): + """ + Ensure that although whitespace might be mutated in a roundtrip, + the semantic meaning of the indentation remains consistent. + """ + code = "if False:\n\tx=3\n\tx=3\n" + codelines = roundtrip(code).split('\n') + self.assertEqual(codelines[1], codelines[2]) + + __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) + support.run_unittest(TestRoundtrip) if __name__ == "__main__": test_main() |