-
Notifications
You must be signed in to change notification settings - Fork 29
feat(testcase): annotate testcase links with results #739
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
Merged
AlexanderLanin
merged 8 commits into
eclipse-score:main
from
etas-contrib:feat/testcase-result-annotations
Aug 26, 2026
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
a40328d
wip
AlexanderLanin 1e7626d
fix: address testcase annotation review feedback
AlexanderLanin be83018
feat: restore colored testcase result annotations
AlexanderLanin 92fae9b
Merge branch 'main' into feat/testcase-result-annotations
AlexanderLanin eda4e2c
docs: clarify testcase annotation rationale
AlexanderLanin 6fd9fbe
address review feedback
AlexanderLanin bc0c7db
Merge branch 'main' into feat/testcase-result-annotations
AlexanderLanin ef74a09
simplify
AlexanderLanin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
135 changes: 135 additions & 0 deletions
135
src/extensions/score_source_code_linker/testcase_annotations.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,135 @@ | ||
| # ******************************************************************************* | ||
| # Copyright (c) 2026 Contributors to the Eclipse Foundation | ||
| # | ||
| # See the NOTICE file(s) distributed with this work for additional | ||
| # information regarding copyright ownership. | ||
| # | ||
| # This program and the accompanying materials are made available under the | ||
| # terms of the Apache License Version 2.0 which is available at | ||
| # https://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # ******************************************************************************* | ||
| """Color execution results in rendered GitHub testcase links. | ||
|
|
||
| The ``testlink`` string-link configuration renders each link as | ||
| ``<testcase name> (<result>)``. This hook replaces the plain result suffix with | ||
| the corresponding colored HTML span after sphinx-needs has created the link. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from html import escape | ||
|
|
||
| from docutils import nodes | ||
|
|
||
| # Known result values get semantic classes so the stylesheet can provide | ||
| # readable colours for the current S-CORE light and dark themes. | ||
| RESULT_CLASSES = { | ||
| "passed": "score-testcase-result--passed", | ||
| "failed": "score-testcase-result--failed", | ||
| "skipped": "score-testcase-result--skipped", | ||
| "disabled": "score-testcase-result--disabled", | ||
| } | ||
| # The event handler is expected to be idempotent for a doctree. This marker | ||
| # prevents a second invocation from appending the same status again. | ||
| _ANNOTATED_ATTR = "score_source_code_linker_testcase_result_annotated" | ||
|
|
||
| # The styles are inserted into a document only when that document contains an | ||
| # annotation. Keeping them in one block avoids repeating inline style rules on | ||
| # every testcase link and lets the same classes handle theme changes. | ||
| _TESTCASE_STATUS_CSS = """ | ||
| <style> | ||
|
Contributor
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. for future PR maybe move this to overall css files |
||
| .score-testcase-result { | ||
| font-weight: bold; | ||
| } | ||
| .score-testcase-result--passed { | ||
| color: #146c2e; | ||
| } | ||
| .score-testcase-result--failed { | ||
| color: #b42318; | ||
| } | ||
| .score-testcase-result--skipped { | ||
| color: #8a5300; | ||
| } | ||
| .score-testcase-result--disabled { | ||
| color: #5f6368; | ||
| } | ||
| html[data-theme="dark"] .score-testcase-result--passed { | ||
| color: #7ee787; | ||
| } | ||
| html[data-theme="dark"] .score-testcase-result--failed { | ||
| color: #ff7b72; | ||
| } | ||
| html[data-theme="dark"] .score-testcase-result--skipped { | ||
| color: #d29922; | ||
| } | ||
| html[data-theme="dark"] .score-testcase-result--disabled { | ||
| color: #c4cad2; | ||
| } | ||
| @media (prefers-color-scheme: dark) { | ||
| html:not([data-theme="light"]) .score-testcase-result--passed { | ||
| color: #7ee787; | ||
| } | ||
| html:not([data-theme="light"]) .score-testcase-result--failed { | ||
| color: #ff7b72; | ||
| } | ||
| html:not([data-theme="light"]) .score-testcase-result--skipped { | ||
| color: #d29922; | ||
| } | ||
| html:not([data-theme="light"]) .score-testcase-result--disabled { | ||
| color: #c4cad2; | ||
| } | ||
| } | ||
| </style> | ||
| """ | ||
|
|
||
|
|
||
| def _result_node(result_text: str, result_class: str) -> nodes.raw: | ||
| escaped_result = escape(result_text, quote=True) | ||
| status_html = ( | ||
| f'<span class="score-testcase-result {result_class}"> ({escaped_result})</span>' | ||
| ) | ||
| return nodes.raw("", status_html, format="html") | ||
|
|
||
|
|
||
| def _color_existing_result_suffix(ref: nodes.reference) -> bool: | ||
| """Replace a recognized ``(result)`` suffix with a colored node.""" | ||
| if not ref.children or not isinstance(ref.children[-1], nodes.Text): | ||
| return False | ||
|
|
||
| last_text = ref.children[-1] | ||
| text = last_text.astext() | ||
| for result_text, result_class in RESULT_CLASSES.items(): | ||
| suffix = f" ({result_text})" | ||
| if text.endswith(suffix): | ||
| prefix = text[: -len(suffix)] | ||
| ref.replace(last_text, nodes.Text(prefix)) | ||
| ref.append(_result_node(result_text, result_class)) | ||
| return True | ||
| return False | ||
|
|
||
|
|
||
| def annotate_testcase_results(app, doctree, docname): | ||
| """Color rendered testcase result suffixes using the S-CORE theme palette. | ||
|
|
||
| The handler runs after sphinx-needs' own ``doctree-resolved`` handlers. | ||
| It therefore sees the external references generated for GitHub ``testlink`` | ||
| metadata, whose labels already contain the result. | ||
| """ | ||
| # CSS applies to the whole document, so one style block is enough even if | ||
| # the document contains many annotated references. | ||
| css_added = False | ||
|
|
||
| for ref in list(doctree.findall(nodes.reference)): | ||
| if ref.get(_ANNOTATED_ATTR): | ||
| # A repeated event invocation must not append another badge. | ||
| continue | ||
|
|
||
| if not _color_existing_result_suffix(ref): | ||
| continue | ||
|
|
||
| if not css_added: | ||
| doctree.insert(0, nodes.raw("", _TESTCASE_STATUS_CSS, format="html")) | ||
| css_added = True | ||
| ref[_ANNOTATED_ATTR] = True | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.