Created
November 27, 2022 03:38
-
-
Save bdbaddog/ef6d5fdd1d6b2ede49d9bea86b6ac045 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
x1 = """\ | |
Traceback (most recent call last): | |
File "<stdin>", line 9, in <module> | |
File "/home/mats/github/scons/testing/framework/TestCommon.py", line 753, in run | |
super().run(**kw) | |
File "/home/mats/github/scons/testing/framework/TestCmd.py", line 1653, in run | |
p = self.start(program=program, | |
File "/home/mats/github/scons/testing/framework/TestCommon.py", line 696, in start | |
raise e | |
File "/home/mats/github/scons/testing/framework/TestCommon.py", line 679, in start | |
return super().start(program, interpreter, arguments, | |
File "<stdin>", line 4, in raise_exception | |
TypeError: forced TypeError | |
""" | |
x2 = """\ | |
Traceback (most recent call last): | |
File "<stdin>", line 9, in <module> | |
File "/home/mats/github/scons/testing/framework/TestCommon.py", line 753, in run | |
super().run(**kw) | |
File "/home/mats/github/scons/testing/framework/TestCmd.py", line 1653, in run | |
p = self.start(program=program, | |
^^^^^^^^^^^^^^^^^^^^^^^^^^^ | |
File "/home/mats/github/scons/testing/framework/TestCommon.py", line 696, in start | |
raise e | |
File "/home/mats/github/scons/testing/framework/TestCommon.py", line 679, in start | |
return super().start(program, interpreter, arguments, | |
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | |
File "<stdin>", line 4, in raise_exception | |
TypeError: forced TypeError | |
""" | |
# try to add an optional group to pick up the "underlining" (^^^) in x2, | |
# but still matches x1 | |
expect_old = \ | |
fr"""Traceback \(most recent call last\): | |
File "<stdin>", line \d+, in (\?|<module>) | |
File "[^"]+TestCommon.py", line \d+, in run | |
super\(\).run\(\*\*kw\) | |
File "[^"]+TestCmd.py", line \d+, in run | |
p = self.start\(program=program, | |
(?:.*) | |
File "[^"]+TestCommon.py", line \d+, in start | |
raise e | |
File "[^"]+TestCommon.py", line \d+, in start | |
return super\(\).start\(program, interpreter, arguments, | |
(?:.*) File "<stdin>", line \d+, in raise_exception | |
TypeError: forced TypeError | |
""" | |
expect = \ | |
fr"""Traceback \(most recent call last\): | |
File \"<stdin>\", line \d+, in (\?|<module>) | |
File \"[^\"]+TestCommon.py\", line \d+, in run | |
super\(\).run\(\*\*kw\) | |
File \"[^\"]+TestCmd.py\", line \d+, in run | |
p = self.start\(program=program, | |
(?:\s*\^*\s)? File \"[^\"]+TestCommon.py\", line \d+, in start | |
raise e | |
File \"[^\"]+TestCommon.py\", line \d+, in start | |
return super\(\).start\(program, interpreter, arguments, | |
(?:\s*\^*\s)? File \"<stdin>\", line \d+, in raise_exception | |
TypeError: forced TypeError""" | |
rv1 = re.match(expect, x1) | |
if rv1: | |
print("pattern 1 matches") | |
else: | |
print("pattern 1 does not match") | |
rv2 = re.match(expect, x2) | |
if rv2: | |
print("pattern 2 matches") | |
else: | |
print("pattern 2 does not match") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
that was tricky.. got it..
https://gist.github.com/bdbaddog/ef6d5fdd1d6b2ede49d9bea86b6ac045