Skip to content

Commit

Permalink
Merge pull request #133 from melexis/clarify-valueerror
Browse files Browse the repository at this point in the history
Clarify failure reason when absolute path cannot be converted for Code Quality report
  • Loading branch information
Letme authored Jan 17, 2024
2 parents b05b162 + 2959d71 commit 1e34b73
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/mlx/warnings/regex_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,11 @@ def add_code_quality_finding(self, match):
if name.startswith("path"):
path = Path(result)
if path.is_absolute():
path = path.relative_to(Path.cwd())
try:
path = path.relative_to(Path.cwd())
except ValueError as err:
raise ValueError("Failed to convert abolute path to relative path for Code Quality report: "
f"{err}") from err
finding["location"]["path"] = str(path)
break
for name, result in groups.items():
Expand Down
14 changes: 14 additions & 0 deletions tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,20 @@ def test_code_quality(self, path_cwd_mock):
self.assertEqual(2, retval)
self.assertTrue(filecmp.cmp(out_file, ref_file), '{} differs from {}'.format(out_file, ref_file))

def test_code_quality_abspath_failure(self):
filename = 'code_quality.json'
out_file = str(TEST_OUT_DIR / filename)
with self.assertRaises(ValueError) as c_m:
warnings_wrapper([
'--code-quality', out_file,
'--config', 'tests/test_in/config_example.json',
'tests/test_in/mixed_warnings.txt',
])
self.assertTrue(str(c_m.exception).startswith(
"Failed to convert abolute path to relative path for Code Quality report: "
"'/home/user/myproject/helper/SimpleTimer.h'")
)

def test_cq_description_format_missing_envvar(self):
os.environ['FIRST_ENVVAR'] = 'envvar_value'
filename = 'code_quality_format.json'
Expand Down

0 comments on commit 1e34b73

Please sign in to comment.