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 coverage for buildtest report clear #1299

Merged
merged 4 commits into from
Dec 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions buildtest/cli/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -769,6 +769,7 @@ def report_cmd(args, report_file=None):
"""Entry point for ``buildtest report`` command"""

consoleColor = checkColor(args.color)

if args.report_subcommand in ["clear", "c"]:
# if BUILDTEST_REPORTS file is not present then we have no report files to delete since it tracks all report files that are created
if not is_file(BUILDTEST_REPORTS):
Expand Down
27 changes: 23 additions & 4 deletions tests/cli/test_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from buildtest.cli.report import Report, report_cmd, report_summary
from buildtest.defaults import BUILD_REPORT, BUILDTEST_REPORTS, BUILDTEST_ROOT
from buildtest.exceptions import BuildTestError
from buildtest.utils.file import is_file
from rich.color import Color


Expand Down Expand Up @@ -261,12 +262,19 @@ class args:

report_cmd(args)

backupfile = tempfile.NamedTemporaryFile()
shutil.copy2(BUILDTEST_REPORTS, backupfile.name)

# now removing report summary it should print a message
os.remove(BUILDTEST_REPORTS)

with pytest.raises(SystemExit):
report_cmd(args)

# move back the removed BUILDTEST_REPORTS file
shutil.move(backupfile.name, BUILDTEST_REPORTS)
assert is_file(BUILDTEST_REPORTS)


@pytest.mark.cli
def test_report_clear():
Expand All @@ -282,15 +290,26 @@ class args:
no_header = None
color = None

backupfile = BUILD_REPORT + ".bak"
shutil.copy2(BUILD_REPORT, backupfile)
backupfile_report = tempfile.NamedTemporaryFile()
shutil.copy2(BUILD_REPORT, backupfile_report.name)

backupfile_list_report = tempfile.NamedTemporaryFile()
shutil.copy2(BUILDTEST_REPORTS, backupfile_list_report.name)

report_cmd(args)

# buildtest report clear will raise an error since file doesn't exist
with pytest.raises(SystemExit):
report_cmd(args)

shutil.move(backupfile, BUILD_REPORT)
assert BUILD_REPORT
assert not is_file(BUILD_REPORT)
# move back the backe-up files since report_cmd() function removes the files BUILD_REPORT and BUILDTEST_REPORTS
shutil.move(backupfile_report.name, BUILD_REPORT)

shutil.move(backupfile_list_report.name, BUILDTEST_REPORTS)

assert is_file(BUILD_REPORT)
prathmesh4321 marked this conversation as resolved.
Show resolved Hide resolved
assert is_file(BUILDTEST_REPORTS)


@pytest.mark.cli
Expand Down