-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
scripts: twister: Add TestCase status and reason printing #78345
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,9 @@ | |
""" | ||
Status classes to be used instead of str statuses. | ||
""" | ||
from __future__ import annotations | ||
|
||
from colorama import Fore | ||
from enum import Enum | ||
|
||
|
||
|
@@ -19,6 +21,21 @@ def _missing_(cls, value): | |
if value is None: | ||
return TwisterStatus.NONE | ||
|
||
@staticmethod | ||
def get_color(status: TwisterStatus) -> str: | ||
match(status): | ||
case TwisterStatus.PASS: | ||
color = Fore.GREEN | ||
case TwisterStatus.SKIP | TwisterStatus.FILTER | TwisterStatus.BLOCK: | ||
color = Fore.YELLOW | ||
case TwisterStatus.FAIL | TwisterStatus.ERROR: | ||
color = Fore.RED | ||
case TwisterStatus.STARTED | TwisterStatus.NONE: | ||
color = Fore.MAGENTA | ||
case _: | ||
color = Fore.RESET | ||
return color | ||
Comment on lines
+26
to
+37
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. isn't dictionary lookup simpler for this purpose ?
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be less concise, as I wouldn't be able to use ORs ( There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
hmm, less concise ? I think this is more pythonic way, and you can even have another palette (grayscale), set it off assigning None, etc.
besides, no problem, just imo. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe concise wasn't the right word - the Status-Colour relationship is a many-to-one relationship (many statuses can have the same colour), which is immediately apparent in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
yeah, in case of the match/case construct it is even harder: it needs to be executed for all statuses first to build status2color{} and filter it on values=='yellow'. |
||
|
||
# All statuses below this comment can be used for TestCase | ||
BLOCK = 'blocked' | ||
STARTED = 'started' | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: If you use
match
keyword, than Twister requires Python 3.10. Therefore, usingfrom __future__ import annotations
does not have any sense (it enables some type annotations for lower versions of python)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just mentioned that, because couple days ago @golowanow added PR to still have possibility to run Twister with Python 3.8: #77077
With
match
keyword it is not possibleThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just ran into this on macOS:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right - I've used it to change
TwisterStatus
type hint intoSelf
- it seems I didn't upstream it. My bad.When it comes to Python<3.10 support - Zephyr does not claim to support it since 3.7.0 LTS (Python 3.10 is listed as minimum requirement), so I do not pay older versions special consideration.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the problem is confusing user experience to get SyntaxError just for
twister --help
now.#78671