diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2017-05-14 06:05:13 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-05-14 06:05:13 (GMT) |
commit | 4ab6abfca4d6e444cca04821b24701cde6993f4e (patch) | |
tree | 3fa4eb3ddab7c00ec87cf3a369a03b5e5fcce518 /Lib/test | |
parent | 821a9d146bc04a1bc1a9807962990a1f59d692b8 (diff) | |
download | cpython-4ab6abfca4d6e444cca04821b24701cde6993f4e.zip cpython-4ab6abfca4d6e444cca04821b24701cde6993f4e.tar.gz cpython-4ab6abfca4d6e444cca04821b24701cde6993f4e.tar.bz2 |
bpo-30299: Display a bytecode when compile a regex in debug mode. (#1491)
`re.compile(..., re.DEBUG)` now displays the compiled bytecode in
human readable form.
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_re.py | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/Lib/test/test_re.py b/Lib/test/test_re.py index 5d36b54..1bb2654 100644 --- a/Lib/test/test_re.py +++ b/Lib/test/test_re.py @@ -1688,10 +1688,12 @@ class ReTests(unittest.TestCase): self.assertEqual(m.group(1), "") self.assertEqual(m.group(2), "y") + @cpython_only def test_debug_flag(self): pat = r'(\.)(?:[ch]|py)(?(1)$|: )' with captured_stdout() as out: re.compile(pat, re.DEBUG) + self.maxDiff = None dump = '''\ SUBPATTERN 1 0 0 LITERAL 46 @@ -1707,6 +1709,31 @@ GROUPREF_EXISTS 1 ELSE LITERAL 58 LITERAL 32 + + 0. INFO 8 0b1 2 5 (to 9) + prefix_skip 0 + prefix [0x2e] ('.') + overlap [0] + 9: MARK 0 +11. LITERAL 0x2e ('.') +13. MARK 1 +15. BRANCH 10 (to 26) +17. IN 6 (to 24) +19. LITERAL 0x63 ('c') +21. LITERAL 0x68 ('h') +23. FAILURE +24: JUMP 9 (to 34) +26: branch 7 (to 33) +27. LITERAL 0x70 ('p') +29. LITERAL 0x79 ('y') +31. JUMP 2 (to 34) +33: FAILURE +34: GROUPREF_EXISTS 0 6 (to 41) +37. AT END +39. JUMP 5 (to 45) +41: LITERAL 0x3a (':') +43. LITERAL 0x20 (' ') +45: SUCCESS ''' self.assertEqual(out.getvalue(), dump) # Debug output is output again even a second time (bypassing |