[rtems-central commit] rtemsspec: Add augment_with_test_links()
Sebastian Huber
sebh at rtems.org
Wed Jul 27 15:14:02 UTC 2022
Module: rtems-central
Branch: master
Commit: 9060c1d4d75669f48423823d06d7f2418a3ec04d
Changeset: http://git.rtems.org/rtems-central/commit/?id=9060c1d4d75669f48423823d06d7f2418a3ec04d
Author: Sebastian Huber <sebastian.huber at embedded-brains.de>
Date: Wed Jul 27 17:18:35 2022 +0200
rtemsspec: Add augment_with_test_links()
---
rtemsspec/rtems.py | 19 ++++++++++++++++++-
rtemsspec/tests/test_rtems.py | 21 ++++++++++++++++++++-
specview.py | 22 +++-------------------
3 files changed, 41 insertions(+), 21 deletions(-)
diff --git a/rtemsspec/rtems.py b/rtemsspec/rtems.py
index 910b3aa1..b2bcfd12 100644
--- a/rtemsspec/rtems.py
+++ b/rtemsspec/rtems.py
@@ -24,7 +24,7 @@
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
-from rtemsspec.items import Item
+from rtemsspec.items import Item, ItemCache, Link
_NOT_PRE_QUALIFIED = set([
"/acfg/constraint/option-not-pre-qualified",
@@ -38,3 +38,20 @@ def is_pre_qualified(item: Item) -> bool:
return not bool(
set(parent.uid for parent in item.parents("constraint")).intersection(
_NOT_PRE_QUALIFIED))
+
+
+def _add_link(item_cache: ItemCache, child: Item, link: Link) -> None:
+ parent = item_cache[child.to_abs_uid(link["uid"])]
+ parent.add_link_to_child(Link(child, link))
+
+
+def augment_with_test_links(item_cache: ItemCache) -> None:
+ """ Augments links of test case items with links from their actions. """
+ for item in item_cache.all.values():
+ if item.type == "test-case":
+ for actions in item["test-actions"]:
+ for checks in actions["checks"]:
+ for link in checks["links"]:
+ _add_link(item_cache, item, link)
+ for link in actions["links"]:
+ _add_link(item_cache, item, link)
diff --git a/rtemsspec/tests/test_rtems.py b/rtemsspec/tests/test_rtems.py
index ee16fc67..f412a543 100644
--- a/rtemsspec/tests/test_rtems.py
+++ b/rtemsspec/tests/test_rtems.py
@@ -27,7 +27,7 @@
import pytest
from rtemsspec.items import EmptyItemCache, Item
-from rtemsspec.rtems import is_pre_qualified
+from rtemsspec.rtems import augment_with_test_links, is_pre_qualified
def test_is_pre_qualified():
@@ -41,3 +41,22 @@ def test_is_pre_qualified():
"uid": uid
}]})
assert not is_pre_qualified(item)
+
+
+def test_augment_with_test_links():
+ item_cache = EmptyItemCache()
+ item = item_cache.add_volatile_item("/i", {"links": []})
+ link = {"role": "validation", "uid": "/i"}
+ test_case = item_cache.add_volatile_item(
+ "/t", {
+ "links": [],
+ "test-actions": [{
+ "checks": [{
+ "links": [link]
+ }],
+ "links": [link]
+ }]
+ })
+ test_case.data["_type"] = "test-case"
+ augment_with_test_links(item_cache)
+ assert item.child("validation") == test_case
diff --git a/specview.py b/specview.py
index c3217100..235b09b3 100755
--- a/specview.py
+++ b/specview.py
@@ -31,8 +31,8 @@ import sys
from typing import Any, Dict, List, Optional, Set, Tuple
from rtemsspec.items import EmptyItem, Item, ItemCache, ItemMapper, \
- ItemGetValueContext, Link
-from rtemsspec.rtems import is_pre_qualified
+ ItemGetValueContext
+from rtemsspec.rtems import augment_with_test_links, is_pre_qualified
from rtemsspec.sphinxcontent import SphinxContent
from rtemsspec.transitionmap import Transition, TransitionMap
from rtemsspec.util import load_config
@@ -287,22 +287,6 @@ def _gather(item: Item, spec: Set) -> None:
_gather(parent, spec)
-def _add_link(item_cache: ItemCache, child: Item, link: Link) -> None:
- parent = item_cache[child.to_abs_uid(link["uid"])]
- parent.add_link_to_child(Link(child, link))
-
-
-def _process_test_cases(item_cache: ItemCache) -> None:
- for item in item_cache.all.values():
- if item.type == "test-case":
- for actions in item["test-actions"]:
- for checks in actions["checks"]:
- for link in checks["links"]:
- _add_link(item_cache, item, link)
- for link in actions["links"]:
- _add_link(item_cache, item, link)
-
-
def _make_row(transition_map: TransitionMap, map_idx: int,
variant: Transition) -> Tuple[str, ...]:
return tuple(
@@ -436,7 +420,7 @@ def main() -> None:
enabled = args.enabled.split(",") if args.enabled else []
config = load_config("config.yml")
item_cache = ItemCache(config["spec"])
- _process_test_cases(item_cache)
+ augment_with_test_links(item_cache)
root = item_cache["/req/root"]
if args.filter == "none":
More information about the vc
mailing list