Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for file line count status check #1723

Merged
merged 9 commits into from
Mar 5, 2024
6 changes: 6 additions & 0 deletions buildtest/builders/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
contains_check,
exists_check,
file_count_check,
file_linecount_check,
file_regex_check,
is_dir_check,
is_file_check,
Expand Down Expand Up @@ -248,6 +249,7 @@
"is_file",
"file_count",
"linecount",
"file_linecount",
]
self.metadata["check"] = {name: None for name in status_check_names}
self.metadata["metrics"] = {}
Expand Down Expand Up @@ -1144,6 +1146,10 @@
if self.status.get("linecount"):
self.metadata["check"]["linecount"] = linecount_check(builder=self)

if self.status.get("file_linecount"):
self.metadata["check"]["file_linecount"] = file_linecount_check(

Check warning on line 1150 in buildtest/builders/base.py

View check run for this annotation

Codecov / codecov/patch

buildtest/builders/base.py#L1149-L1150

Added lines #L1149 - L1150 were not covered by tests
builder=self
)
# filter out any None values from status check
status_checks = [
value for value in self.metadata["check"].values() if value is not None
Expand Down
35 changes: 35 additions & 0 deletions buildtest/buildsystem/checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -673,3 +673,38 @@
f"[blue]{builder}[/]: Performing line count check on file: {fname} with {builder.status['linecount']['count']} (ref count) == {len(content.splitlines())} (actual count). linecount Check: {comparison}"
)
return comparison


def file_linecount_check(builder):
"""This method is used to perform line count check when ``file_linecount`` property is specified

Args:
builder (buildtest.builders.base.BuilderBase): An instance of BuilderBase class used for printing the builder name
"""
assert_check = []
for file_check in builder.status["file_linecount"]:
resolved_fname = resolve_path(file_check["file"])
if not resolved_fname:
msg = (

Check warning on line 688 in buildtest/buildsystem/checks.py

View check run for this annotation

Codecov / codecov/patch

buildtest/buildsystem/checks.py#L684-L688

Added lines #L684 - L688 were not covered by tests
f"[blue]{builder}[/]: Unable to resolve file path: {file_check['file']}"
)
logger.error(msg)
console.print(msg, style="red")
assert_check.append(False)
continue

Check warning on line 694 in buildtest/buildsystem/checks.py

View check run for this annotation

Codecov / codecov/patch

buildtest/buildsystem/checks.py#L691-L694

Added lines #L691 - L694 were not covered by tests

if not is_file(resolved_fname):
msg = f"[blue]{builder}[/]: File: {resolved_fname} is not a file"
logger.error(msg)
console.print(msg, style="red")
assert_check.append(False)
continue

Check warning on line 701 in buildtest/buildsystem/checks.py

View check run for this annotation

Codecov / codecov/patch

buildtest/buildsystem/checks.py#L696-L701

Added lines #L696 - L701 were not covered by tests

content = read_file(resolved_fname)
comparison = len(content.splitlines()) == file_check["count"]
console.print(

Check warning on line 705 in buildtest/buildsystem/checks.py

View check run for this annotation

Codecov / codecov/patch

buildtest/buildsystem/checks.py#L703-L705

Added lines #L703 - L705 were not covered by tests
f"[blue]{builder}[/]: Performing line count check on file: {resolved_fname} with {file_check['count']} (ref count) == {len(content.splitlines())} (actual count). linecount Check: {comparison}"
)
assert_check.append(comparison)

Check warning on line 708 in buildtest/buildsystem/checks.py

View check run for this annotation

Codecov / codecov/patch

buildtest/buildsystem/checks.py#L708

Added line #L708 was not covered by tests

return all(assert_check)

Check warning on line 710 in buildtest/buildsystem/checks.py

View check run for this annotation

Codecov / codecov/patch

buildtest/buildsystem/checks.py#L710

Added line #L710 was not covered by tests
Loading
Loading