Skip to content

Commit e005a6d

Browse files
authored
Merge pull request #140 from Nerixyz/fix/split-review
fix(split-review): search by string in names
2 parents 9539823 + 94e0056 commit e005a6d

File tree

2 files changed

+23
-19
lines changed

2 files changed

+23
-19
lines changed

post/clang_tidy_review/clang_tidy_review/__init__.py

+12-12
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ def merge_replacement_files(tmpdir: Path, mergefile: Path):
266266
yaml.safe_dump(output, out)
267267

268268

269-
def load_clang_tidy_warnings(fixes_file) -> Dict:
269+
def load_clang_tidy_warnings(fixes_file: Path) -> Dict:
270270
"""Read clang-tidy warnings from fixes_file. Can be produced by build_clang_tidy_warnings"""
271271
try:
272272
with fixes_file.open() as f:
@@ -955,9 +955,7 @@ def create_review(
955955
files = filter_files(diff, include, exclude)
956956

957957
if files == []:
958-
with message_group("No files to check!"), Path(REVIEW_FILE).open(
959-
"w"
960-
) as review_file:
958+
with message_group("No files to check!"), REVIEW_FILE.open("w") as review_file:
961959
json.dump(
962960
{
963961
"body": "clang-tidy found no files to check",
@@ -972,7 +970,7 @@ def create_review(
972970

973971
line_ranges = get_line_ranges(diff, files)
974972
if line_ranges == "[]":
975-
with message_group("No lines added in this PR!"), Path(REVIEW_FILE).open(
973+
with message_group("No lines added in this PR!"), REVIEW_FILE.open(
976974
"w"
977975
) as review_file:
978976
json.dump(
@@ -1071,7 +1069,7 @@ def create_review(
10711069
review = create_review_file(
10721070
clang_tidy_warnings, diff_lookup, offset_lookup, build_dir
10731071
)
1074-
with Path(REVIEW_FILE).open("w") as review_file:
1072+
with REVIEW_FILE.open("w") as review_file:
10751073
json.dump(review, review_file)
10761074

10771075
return review
@@ -1111,23 +1109,25 @@ def download_artifacts(pull: PullRequest, workflow_id: int):
11111109

11121110
metadata = (
11131111
json.loads(data.read(str(METADATA_FILE)))
1114-
if METADATA_FILE in filenames
1112+
if str(METADATA_FILE) in filenames
11151113
else None
11161114
)
11171115
review = (
1118-
json.loads(data.read(str(REVIEW_FILE))) if REVIEW_FILE in filenames else None
1116+
json.loads(data.read(str(REVIEW_FILE)))
1117+
if str(REVIEW_FILE) in filenames
1118+
else None
11191119
)
11201120
return metadata, review
11211121

11221122

11231123
def load_metadata() -> Optional[Metadata]:
11241124
"""Load metadata from the METADATA_FILE path"""
11251125

1126-
if not pathlib.Path(METADATA_FILE).exists():
1126+
if not METADATA_FILE.exists():
11271127
print(f"WARNING: Could not find metadata file ('{METADATA_FILE}')", flush=True)
11281128
return None
11291129

1130-
with Path(METADATA_FILE).open() as metadata_file:
1130+
with METADATA_FILE.open() as metadata_file:
11311131
return json.load(metadata_file)
11321132

11331133

@@ -1136,7 +1136,7 @@ def save_metadata(pr_number: int) -> None:
11361136

11371137
metadata: Metadata = {"pr_number": pr_number}
11381138

1139-
with Path(METADATA_FILE).open("w") as metadata_file:
1139+
with METADATA_FILE.open("w") as metadata_file:
11401140
json.dump(metadata, metadata_file)
11411141

11421142

@@ -1154,7 +1154,7 @@ def load_review(review_file: pathlib.Path) -> Optional[PRReview]:
11541154

11551155
def load_and_merge_profiling() -> Dict:
11561156
result = {}
1157-
for profile_file in Path(PROFILE_DIR).glob("*.json"):
1157+
for profile_file in PROFILE_DIR.glob("*.json"):
11581158
profile_dict = json.load(profile_file.open())
11591159
filename = profile_dict["file"]
11601160
current_profile = result.get(filename, {})

tests/test_review.py

+11-7
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
import pytest
1313

14+
from pathlib import Path
15+
1416
TEST_DIR = pathlib.Path(__file__).parent
1517
TEST_FILE = TEST_DIR / "src/hello.cxx"
1618
TEST_DIFF = [
@@ -191,7 +193,7 @@ def test_fix_absolute_paths(tmp_path):
191193

192194

193195
def test_save_load_metadata(tmp_path, monkeypatch):
194-
monkeypatch.setattr(ctr, "METADATA_FILE", str(tmp_path / ctr.METADATA_FILE))
196+
monkeypatch.setattr(ctr, "METADATA_FILE", tmp_path / ctr.METADATA_FILE)
195197

196198
ctr.save_metadata(42)
197199
meta = ctr.load_metadata()
@@ -391,7 +393,7 @@ def test_version(monkeypatch):
391393
lambda *args, **kwargs: MockClangTidyVersionProcess(expected_version),
392394
)
393395

394-
version = ctr.clang_tidy_version("not-clang-tidy")
396+
version = ctr.clang_tidy_version(Path("not-clang-tidy"))
395397
assert version == expected_version
396398

397399

@@ -406,25 +408,27 @@ def test_config_file(monkeypatch, tmp_path):
406408

407409
# If you set clang_tidy_checks to something and config_file to something, config_file is sent to clang-tidy.
408410
flag = ctr.config_file_or_checks(
409-
"not-clang-tidy", clang_tidy_checks="readability", config_file=str(config_file)
411+
Path("not-clang-tidy"),
412+
clang_tidy_checks="readability",
413+
config_file=str(config_file),
410414
)
411415
assert flag == f"--config-file={config_file}"
412416

413417
# If you set clang_tidy_checks and config_file to an empty string, neither are sent to the clang-tidy.
414418
flag = ctr.config_file_or_checks(
415-
"not-clang-tidy", clang_tidy_checks="", config_file=""
419+
Path("not-clang-tidy"), clang_tidy_checks="", config_file=""
416420
)
417421
assert flag is None
418422

419423
# If you get config_file to something, config_file is sent to clang-tidy.
420424
flag = ctr.config_file_or_checks(
421-
"not-clang-tidy", clang_tidy_checks="", config_file=str(config_file)
425+
Path("not-clang-tidy"), clang_tidy_checks="", config_file=str(config_file)
422426
)
423427
assert flag == f"--config-file={config_file}"
424428

425429
# If you get clang_tidy_checks to something and config_file to nothing, clang_tidy_checks is sent to clang-tidy.
426430
flag = ctr.config_file_or_checks(
427-
"not-clang-tidy", clang_tidy_checks="readability", config_file=""
431+
Path("not-clang-tidy"), clang_tidy_checks="readability", config_file=""
428432
)
429433
assert flag == "--checks=readability"
430434

@@ -465,7 +469,7 @@ def test_decorate_comment_body():
465469

466470

467471
def test_timing_summary(monkeypatch):
468-
monkeypatch.setattr(ctr, "PROFILE_DIR", str(TEST_DIR / "src/clang-tidy-profile"))
472+
monkeypatch.setattr(ctr, "PROFILE_DIR", TEST_DIR / "src/clang-tidy-profile")
469473
profiling = ctr.load_and_merge_profiling()
470474
assert "time.clang-tidy.total.wall" in profiling["hello.cxx"].keys()
471475
assert "time.clang-tidy.total.user" in profiling["hello.cxx"].keys()

0 commit comments

Comments
 (0)