Skip to content

Commit

Permalink
expand regex pattern and add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jhaigh0 committed Jun 10, 2024
1 parent a1352db commit dc9d5f2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
16 changes: 14 additions & 2 deletions web/services/github_issue_manager/github_issue_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@
from github import Github, Auth

logger = logging.getLogger()
line_exp = re.compile(r"\s*File \".*(mantidqt|mantidqtinterfaces|"
r"workbench|scripts)(\/|\\)(.*)(\", line \d+, in \S+)")
line_exp = re.compile(r"\s*File \".*(mantid|mantidqt|mantidqtinterfaces|"
r"workbench|scripts|plugins)"
r"(\/|\\)(.*)(\", line \d+, in \S+)")
alt_line_exp = re.compile(r"\s*(at line \d+ in )\'.*(mantid|mantidqt|"
r"mantidqtinterfaces|workbench|scripts|plugins)"
r"(\/|\\)(.*)\'")
ISSUE_TEXT = Template("""
Name: $name
Email: $email
Expand Down Expand Up @@ -124,6 +128,14 @@ def _stacktrace_line_trimer(line: str) -> str:
os.path.normpath("".join(match.group(1, 2, 3)))
)
return path.as_posix() + match.group(4)

match = alt_line_exp.match(line)
if match:
path = pathlib.PureWindowsPath(
os.path.normpath("".join(match.groups(2, 3, 4)))
)
return match.group(1) + path.as_posix()

return line


Expand Down
6 changes: 5 additions & 1 deletion web/services/github_issue_manager/test_trim_stacktrace.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ def test_line_trimmer_file_lines(self):
r'File "D:\Mantid\Software\MantidInstall\bin\lib\site-packages\mantidqt\widgets\codeeditor\execution.py", line 153, in execute':
r'mantidqt/widgets/codeeditor/execution.py", line 153, in execute',
r'File "/opt/mantidworkbenchnightly/scripts/ExternalInterfaces/mslice/presenters/workspace_manager_presenter.py", line 112, in _save_to_ads':
r'scripts/ExternalInterfaces/mslice/presenters/workspace_manager_presenter.py", line 112, in _save_to_ads'
r'scripts/ExternalInterfaces/mslice/presenters/workspace_manager_presenter.py", line 112, in _save_to_ads',
r"at line 152 in '/usr/local/anaconda/envs/mantid-dev/plugins/python/algorithms/ConvertWANDSCDtoQ.py'":
r'at line 152 in plugins/python/algorithms/ConvertWANDSCDtoQ.py',
r'File "/opt/mantidworkbench6.9/lib/python3.10/site-packages/mantid/simpleapi.py", line 1083, in __call__':
r'mantid/simpleapi.py", line 1083, in __call__'
}
for original, expected_trim in examples.items():
self.assertEqual(_stacktrace_line_trimer(original), expected_trim)
Expand Down

0 comments on commit dc9d5f2

Please sign in to comment.