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

Avocado Jobs Keys #6076

Merged
merged 1 commit into from
Dec 18, 2024
Merged
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
72 changes: 50 additions & 22 deletions avocado/plugins/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,28 +50,56 @@
LOG_UI.info("%-12s: %s", key, value)

@staticmethod
def _print_job_tests(tests):
test_matrix = []
def _format_test_status(status):
"""Format the test status with appropriate decorator."""
if status is None:
raise ValueError("Test status is missing - corrupted test data")

Check warning on line 56 in avocado/plugins/jobs.py

View check run for this annotation

Codecov / codecov/patch

avocado/plugins/jobs.py#L55-L56

Added lines #L55 - L56 were not covered by tests

decorator = output.TEST_STATUS_DECORATOR_MAPPING.get(status)
if decorator is None:
raise ValueError(f"Unknown test status '{status}' - corrupted test data")

Check warning on line 60 in avocado/plugins/jobs.py

View check run for this annotation

Codecov / codecov/patch

avocado/plugins/jobs.py#L58-L60

Added lines #L58 - L60 were not covered by tests

return decorator(status, "") if decorator else "<unknown>"

Check warning on line 62 in avocado/plugins/jobs.py

View check run for this annotation

Codecov / codecov/patch

avocado/plugins/jobs.py#L62

Added line #L62 was not covered by tests

@staticmethod
def _format_end_time(test):
"""Format the test end time."""
date_fmt = "%Y/%m/%d %H:%M:%S"
for test in tests:
status = test.get("status")
decorator = output.TEST_STATUS_DECORATOR_MAPPING.get(status)
# Retrieve "end" for backward compatibility
end = datetime.fromtimestamp(test.get("actual_end", test.get("end")))
test_matrix.append(
(
test.get("id"),
end.strftime(date_fmt),
f"{float(test.get('time')):5f}",
decorator(status, ""),
)
)
end_timestamp = test.get("actual_end", test.get("end"))
if end_timestamp is not None:
return datetime.fromtimestamp(end_timestamp).strftime(date_fmt)
return "<unknown>"

Check warning on line 71 in avocado/plugins/jobs.py

View check run for this annotation

Codecov / codecov/patch

avocado/plugins/jobs.py#L68-L71

Added lines #L68 - L71 were not covered by tests

@staticmethod
def _format_run_time(test):
"""Format the test run time."""
time_taken = test.get("time")
if time_taken is not None:
return f"{float(time_taken):5f}"
return "<unknown>"

Check warning on line 79 in avocado/plugins/jobs.py

View check run for this annotation

Codecov / codecov/patch

avocado/plugins/jobs.py#L76-L79

Added lines #L76 - L79 were not covered by tests

@staticmethod
def _create_matrix_row(test):
"""Create a matrix row for a single test."""
return (

Check warning on line 84 in avocado/plugins/jobs.py

View check run for this annotation

Codecov / codecov/patch

avocado/plugins/jobs.py#L84

Added line #L84 was not covered by tests
test.get("id", "<unknown>"),
Jobs._format_end_time(test),
Jobs._format_run_time(test),
Jobs._format_test_status(test.get("status")),
)

@staticmethod
def _print_job_tests(tests):
"""Print formatted test results in a table."""
test_matrix = [Jobs._create_matrix_row(test) for test in tests]

Check warning on line 94 in avocado/plugins/jobs.py

View check run for this annotation

Codecov / codecov/patch

avocado/plugins/jobs.py#L94

Added line #L94 was not covered by tests

header = (
output.TERM_SUPPORT.header_str("Test ID"),
output.TERM_SUPPORT.header_str("End Time"),
output.TERM_SUPPORT.header_str("Run Time"),
output.TERM_SUPPORT.header_str("Status"),
)

for line in astring.iter_tabular_output(test_matrix, header=header, strip=True):
LOG_UI.debug(line)

Expand Down Expand Up @@ -118,13 +146,13 @@
job = json.load(fp)
LOG_UI.info(
"%-40s %-26s %3s (%s/%s/%s/%s)",
job["job_id"],
job["start"],
job["total"],
job["pass"],
job["skip"],
job["errors"],
job["failures"],
job.get("job_id", "<unknown>"),
job.get("start", "<unknown>"),
job.get("total", "<unknown>"),
job.get("pass", "<unknown>"),
job.get("skip", "<unknown>"),
job.get("errors", "<unknown>"),
job.get("failures", "<unknown>"),
)

return exit_codes.AVOCADO_ALL_OK
Expand Down
Loading