summaryrefslogtreecommitdiffstats
path: root/rtemsqual
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2020-06-26 20:01:46 +0200
committerSebastian Huber <sebastian.huber@embedded-brains.de>2020-07-03 10:22:46 +0200
commit0dada0449d51ef50c7d19d4130866d7a7360abcf (patch)
treeee36739478723d562ac7fa9905b1a69e7acb3708 /rtemsqual
parentitems: Add support for aggregated item type (diff)
downloadrtems-central-0dada0449d51ef50c7d19d4130866d7a7360abcf.tar.bz2
items: Add ItemGetValueContext
Use aggregated item type in get_value() methods.
Diffstat (limited to 'rtemsqual')
-rw-r--r--rtemsqual/glossary.py17
-rw-r--r--rtemsqual/interface.py16
-rw-r--r--rtemsqual/interfacedoc.py32
-rw-r--r--rtemsqual/items.py38
-rw-r--r--rtemsqual/specdoc.py2
-rw-r--r--rtemsqual/sphinxcontent.py17
-rw-r--r--rtemsqual/tests/spec-interface/command-line.yml2
-rw-r--r--rtemsqual/tests/spec-sphinx/y.yml4
-rw-r--r--rtemsqual/tests/spec/build-more.yml21
-rw-r--r--rtemsqual/tests/spec/build.yml24
-rw-r--r--rtemsqual/tests/spec/functional-more.yml21
-rw-r--r--rtemsqual/tests/spec/functional.yml24
-rw-r--r--rtemsqual/tests/spec/glossary-more.yml25
-rw-r--r--rtemsqual/tests/spec/glossary.yml24
-rw-r--r--rtemsqual/tests/spec/interface-more.yml85
-rw-r--r--rtemsqual/tests/spec/interface.yml24
-rw-r--r--rtemsqual/tests/spec/other.yml21
-rw-r--r--rtemsqual/tests/spec/requirement.yml24
-rw-r--r--rtemsqual/tests/spec/root.yml18
-rw-r--r--rtemsqual/tests/spec/spec.yml21
-rw-r--r--rtemsqual/tests/spec/test-case.yml21
-rw-r--r--rtemsqual/tests/spec/test-suite.yml21
-rw-r--r--rtemsqual/tests/test_content_sphinx.py8
-rw-r--r--rtemsqual/tests/test_glossary.py2
-rw-r--r--rtemsqual/tests/test_interface.py2
-rw-r--r--rtemsqual/tests/test_interfacedoc.py2
-rw-r--r--rtemsqual/tests/test_items_itemcache.py6
-rw-r--r--rtemsqual/tests/test_validation.py2
-rw-r--r--rtemsqual/tests/util.py13
-rw-r--r--rtemsqual/validation.py12
30 files changed, 464 insertions, 85 deletions
diff --git a/rtemsqual/glossary.py b/rtemsqual/glossary.py
index 35f9b56f..0524ef42 100644
--- a/rtemsqual/glossary.py
+++ b/rtemsqual/glossary.py
@@ -26,10 +26,10 @@
import glob
import re
-from typing import Any, Dict, NamedTuple, Optional
+from typing import Any, Dict, NamedTuple
from rtemsqual.sphinxcontent import SphinxContent, SphinxMapper
-from rtemsqual.items import Item, ItemCache, ItemMapper
+from rtemsqual.items import Item, ItemCache, ItemGetValueContext, ItemMapper
ItemMap = Dict[str, Item]
@@ -87,14 +87,13 @@ class _GlossaryMapper(ItemMapper):
super().__init__(item)
self._document_terms = document_terms
- def get_value(self, item: Item, _path: str, _value: Any, key: str,
- _index: Optional[int]) -> Any:
+ def get_value(self, ctx: ItemGetValueContext) -> Any:
""" Recursively adds glossary terms to the document terms. """
- if key == "term":
- if item.uid not in self._document_terms:
- self._document_terms[item.uid] = item
- _GlossaryMapper(item,
- self._document_terms).substitute(item["text"])
+ if ctx.type_path_key == "glossary/term:/term":
+ if ctx.item.uid not in self._document_terms:
+ self._document_terms[ctx.item.uid] = ctx.item
+ _GlossaryMapper(ctx.item, self._document_terms).substitute(
+ ctx.item["text"])
# The value of this substitute is unused.
return ""
diff --git a/rtemsqual/interface.py b/rtemsqual/interface.py
index 22e7aa94..90a0245b 100644
--- a/rtemsqual/interface.py
+++ b/rtemsqual/interface.py
@@ -26,11 +26,11 @@
from contextlib import contextmanager
import os
-from typing import Any, Callable, Dict, Iterator, List, Optional, Union
+from typing import Any, Callable, Dict, Iterator, List, Union
from rtemsqual.content import CContent, CInclude, enabled_by_to_exp, \
ExpressionMapper
-from rtemsqual.items import Item, ItemCache, ItemMapper
+from rtemsqual.items import Item, ItemCache, ItemGetValueContext, ItemMapper
ItemMap = Dict[str, Item]
Lines = Union[str, List[str]]
@@ -82,14 +82,14 @@ class _InterfaceMapper(ItemMapper):
header_file.add_potential_edge(node, item)
return value
- def get_value(self, item: Item, path: str, value: Any, key: str,
- _index: Optional[int]) -> Any:
- if path == "/" and key == "name" and item["type"] == "interface":
- interface_type = item["interface-type"]
+ def get_value(self, ctx: ItemGetValueContext) -> Any:
+ if ctx.path == "/" and ctx.key == "name" and ctx.item[
+ "type"] == "interface":
+ interface_type = ctx.item["interface-type"]
if interface_type == "forward-declaration":
- return _forward_declaration(item)
+ return _forward_declaration(ctx.item)
if not self._eval_interface:
- value = value[key]
+ value = ctx.value[ctx.key]
if interface_type == "function":
return f"{value}()"
if interface_type in ["enumerator", "typedef"]:
diff --git a/rtemsqual/interfacedoc.py b/rtemsqual/interfacedoc.py
index b7fb12dc..ffa681b4 100644
--- a/rtemsqual/interfacedoc.py
+++ b/rtemsqual/interfacedoc.py
@@ -27,11 +27,11 @@ This module provides functions for the generation of interface documentation.
# POSSIBILITY OF SUCH DAMAGE.
import os
-from typing import Any, Callable, Dict, List, Optional
+from typing import Any, Callable, Dict, List
from rtemsqual.content import CContent, enabled_by_to_exp, ExpressionMapper
from rtemsqual.sphinxcontent import get_label, get_reference, SphinxContent
-from rtemsqual.items import Item, ItemCache, ItemMapper
+from rtemsqual.items import Item, ItemCache, ItemGetValueContext, ItemMapper
ItemMap = Dict[str, Item]
AddDefinition = Callable[[CContent, ItemMapper, Item, Dict[str, Any]], None]
@@ -49,31 +49,21 @@ def _get_reference(name: str) -> str:
class _CodeMapper(ItemMapper):
- def get_value(self, item: Item, path: str, _value: Any, key: str,
- _index: Optional[int]) -> Any:
- # pylint: disable=duplicate-code
- if path == "/" and key == "name" and item["type"] == "interface":
- interface_type = item["interface-type"]
- if interface_type == "forward-declaration":
- return _forward_declaration(item)
+ def get_value(self, ctx: ItemGetValueContext) -> Any:
+ if ctx.type_path_key == "interface/forward-declaration:/name":
+ return _forward_declaration(ctx.item)
raise KeyError
class _Mapper(_CodeMapper):
- def get_value(self, item: Item, path: str, value: Any, key: str,
- index: Optional[int]) -> Any:
- # pylint: disable=too-many-arguments
+ def get_value(self, ctx: ItemGetValueContext) -> Any:
try:
- return super().get_value(item, path, value, key, index)
+ return super().get_value(ctx)
except KeyError:
- if path == "/" and key == "name" and item["type"] == "interface":
- value = value[key]
- interface_type = item["interface-type"]
- if interface_type == "function":
- return _get_reference(value)
- if interface_type == "appl-config-option":
- return f":ref:`{value}`"
- return value
+ if ctx.type_path_key == "interface/function:/name":
+ return _get_reference(ctx.value[ctx.key])
+ if ctx.type_path_key == "interface/appl-config-option:/name":
+ return f":ref:`{ctx.value[ctx.key]}`"
raise KeyError
diff --git a/rtemsqual/items.py b/rtemsqual/items.py
index d4bb9517..910c7924 100644
--- a/rtemsqual/items.py
+++ b/rtemsqual/items.py
@@ -33,8 +33,23 @@ from typing import Any, Callable, Dict, Iterator, List, NamedTuple, Mapping, \
Optional, Tuple
import yaml
+
+class ItemGetValueContext(NamedTuple):
+ """ Context used to get an item value. """
+ item: "Item"
+ path: str
+ value: Any
+ key: str
+ index: Any # should be int, but this triggers a mypy error
+
+ @property
+ def type_path_key(self) -> str:
+ """ Returns the item type followed the path to the key. """
+ return f"{self.item.type}:{self.path}{self.key}"
+
+
ItemMap = Dict[str, "Item"]
-ItemGetValue = Callable[["Item", str, Any, str, Optional[int]], Any]
+ItemGetValue = Callable[[ItemGetValueContext], Any]
def _is_enabled_op_and(enabled: List[str], enabled_by: Any) -> bool:
@@ -108,11 +123,10 @@ class Link:
return self._data["role"]
-def _get_value(_item: "Item", _path: str, value: Any, key: str,
- index: Optional[int]) -> str:
- value = value[key]
- if index is not None:
- value = value[index]
+def _get_value(ctx: ItemGetValueContext) -> Any:
+ value = ctx.value[ctx.key]
+ if ctx.index >= 0:
+ return value[ctx.index]
return value
@@ -154,13 +168,14 @@ class Item:
for key in key_path.strip("/").split("/"):
parts = key.split("[")
try:
- index = int(parts[1].split("]")[0]) # type: Optional[int]
+ index = int(parts[1].split("]")[0])
except IndexError:
- index = None
+ index = -1
+ ctx = ItemGetValueContext(self, path, value, parts[0], index)
try:
- value = get_value(self, path, value, parts[0], index)
+ value = get_value(ctx)
except KeyError:
- value = _get_value(self, path, value, parts[0], index)
+ value = _get_value(ctx)
path = os.path.join(path, key)
return value
@@ -339,8 +354,7 @@ class ItemMapper(Mapping[str, object]):
with self.prefix(prefix):
return ItemTemplate(text).substitute(self)
- def get_value(self, _item: Item, _path: str, _value: Any, _key: str,
- _index: Optional[int]) -> Any:
+ def get_value(self, ctx: ItemGetValueContext) -> Any:
""" Gets a value by key and optional index. """
# pylint: disable=no-self-use
raise KeyError
diff --git a/rtemsqual/specdoc.py b/rtemsqual/specdoc.py
index 72958a6e..c9ed8392 100644
--- a/rtemsqual/specdoc.py
+++ b/rtemsqual/specdoc.py
@@ -269,7 +269,7 @@ class _Documenter:
self._documenter_map = documenter_map
self.used_by = set() # type: Set[str]
self._mapper = SphinxMapper(item)
- self._mapper.add_get_reference("spec", "/spec-name",
+ self._mapper.add_get_reference("spec:/spec-name",
_get_ref_specification_type)
assert self._name not in documenter_map
documenter_map[self._name] = self
diff --git a/rtemsqual/sphinxcontent.py b/rtemsqual/sphinxcontent.py
index 15c7d3d4..4ec5ceec 100644
--- a/rtemsqual/sphinxcontent.py
+++ b/rtemsqual/sphinxcontent.py
@@ -25,13 +25,12 @@
# POSSIBILITY OF SUCH DAMAGE.
from contextlib import contextmanager
-import os
import re
from typing import Any, Dict, Callable, Iterable, Iterator, List, Optional, \
Union
from rtemsqual.content import Content, make_lines
-from rtemsqual.items import Item, ItemMapper
+from rtemsqual.items import Item, ItemGetValueContext, ItemMapper
GenericContent = Union[str, List[str], "Content"]
GenericContentIterable = Union[Iterable[str], Iterable[List[str]],
@@ -227,20 +226,18 @@ class SphinxMapper(ItemMapper):
def __init__(self, item: Item):
super().__init__(item)
self._get_ref = {
- "glossary:/term": _get_ref_term,
- "glossary:/plural": _get_ref_term_plural
+ "glossary/term:/term": _get_ref_term,
+ "glossary/term:/plural": _get_ref_term_plural
} # type: Dict[str, Callable[[Any, str], str]]
- def add_get_reference(self, type_name: str, path: str,
+ def add_get_reference(self, type_path_key: str,
get_ref: Callable[[Any, str], str]) -> None:
"""
Adds a function to get a reference to the specified path for items of
the specified type.
"""
- self._get_ref[f"{type_name}:{path}"] = get_ref
+ self._get_ref[type_path_key] = get_ref
- def get_value(self, item: Item, path: str, value: Any, key: str,
- _index: Optional[int]) -> Any:
+ def get_value(self, ctx: ItemGetValueContext) -> Any:
""" Gets a value by key and optional index. """
- return self._get_ref[f"{item['type']}:{os.path.join(path, key)}"](
- value, key)
+ return self._get_ref[ctx.type_path_key](ctx.value, ctx.key)
diff --git a/rtemsqual/tests/spec-interface/command-line.yml b/rtemsqual/tests/spec-interface/command-line.yml
index fede1644..5ecd875f 100644
--- a/rtemsqual/tests/spec-interface/command-line.yml
+++ b/rtemsqual/tests/spec-interface/command-line.yml
@@ -2,7 +2,7 @@ SPDX-License-Identifier: CC-BY-SA-4.0 OR BSD-2-Clause
copyrights:
- Copyright (C) 2020 embedded brains GmbH (http://www.embedded-brains.de)
enabled-by: true
-interface-type: command-line
+interface-type: container
links:
- role: interface-placement
uid: domain-command-line
diff --git a/rtemsqual/tests/spec-sphinx/y.yml b/rtemsqual/tests/spec-sphinx/y.yml
index 4c142141..79a22535 100644
--- a/rtemsqual/tests/spec-sphinx/y.yml
+++ b/rtemsqual/tests/spec-sphinx/y.yml
@@ -1,3 +1,3 @@
-name: bar
+name: foobar
links: []
-type: foo
+type: other
diff --git a/rtemsqual/tests/spec/build-more.yml b/rtemsqual/tests/spec/build-more.yml
new file mode 100644
index 00000000..fb35b357
--- /dev/null
+++ b/rtemsqual/tests/spec/build-more.yml
@@ -0,0 +1,21 @@
+SPDX-License-Identifier: CC-BY-SA-4.0 OR BSD-2-Clause
+copyrights:
+- Copyright (C) 2020 embedded brains GmbH (http://www.embedded-brains.de)
+enabled-by: true
+links:
+- role: spec-member
+ uid: root
+- role: spec-refinement
+ spec-key: build-type
+ spec-value: test-program
+ uid: build
+spec-description: null
+spec-example: null
+spec-info:
+ dict:
+ attributes: {}
+ description: null
+ mandatory-attributes: all
+spec-name: Build More
+spec-type: build-more
+type: spec
diff --git a/rtemsqual/tests/spec/build.yml b/rtemsqual/tests/spec/build.yml
new file mode 100644
index 00000000..8329c6d4
--- /dev/null
+++ b/rtemsqual/tests/spec/build.yml
@@ -0,0 +1,24 @@
+SPDX-License-Identifier: CC-BY-SA-4.0 OR BSD-2-Clause
+copyrights:
+- Copyright (C) 2020 embedded brains GmbH (http://www.embedded-brains.de)
+enabled-by: true
+links:
+- role: spec-member
+ uid: root
+- role: spec-refinement
+ spec-key: type
+ spec-value: build
+ uid: root
+spec-description: null
+spec-example: null
+spec-info:
+ dict:
+ attributes:
+ build-type:
+ description: null
+ spec-type: name
+ description: null
+ mandatory-attributes: all
+spec-name: Build
+spec-type: build
+type: spec
diff --git a/rtemsqual/tests/spec/functional-more.yml b/rtemsqual/tests/spec/functional-more.yml
new file mode 100644
index 00000000..dee60872
--- /dev/null
+++ b/rtemsqual/tests/spec/functional-more.yml
@@ -0,0 +1,21 @@
+SPDX-License-Identifier: CC-BY-SA-4.0 OR BSD-2-Clause
+copyrights:
+- Copyright (C) 2020 embedded brains GmbH (http://www.embedded-brains.de)
+enabled-by: true
+links:
+- role: spec-member
+ uid: root
+- role: spec-refinement
+ spec-key: functional-type
+ spec-value: action
+ uid: functional
+spec-description: null
+spec-example: null
+spec-info:
+ dict:
+ attributes: {}
+ description: null
+ mandatory-attributes: all
+spec-name: Functional More
+spec-type: functional-more
+type: spec
diff --git a/rtemsqual/tests/spec/functional.yml b/rtemsqual/tests/spec/functional.yml
new file mode 100644
index 00000000..9ae9cfec
--- /dev/null
+++ b/rtemsqual/tests/spec/functional.yml
@@ -0,0 +1,24 @@
+SPDX-License-Identifier: CC-BY-SA-4.0 OR BSD-2-Clause
+copyrights:
+- Copyright (C) 2020 embedded brains GmbH (http://www.embedded-brains.de)
+enabled-by: true
+links:
+- role: spec-member
+ uid: root
+- role: spec-refinement
+ spec-key: requirement-type
+ spec-value: functional
+ uid: requirement
+spec-description: null
+spec-example: null
+spec-info:
+ dict:
+ attributes:
+ functional-type:
+ description: null
+ spec-type: name
+ description: null
+ mandatory-attributes: all
+spec-name: Functional
+spec-type: functional
+type: spec
diff --git a/rtemsqual/tests/spec/glossary-more.yml b/rtemsqual/tests/spec/glossary-more.yml
new file mode 100644
index 00000000..bbcad8c3
--- /dev/null
+++ b/rtemsqual/tests/spec/glossary-more.yml
@@ -0,0 +1,25 @@
+SPDX-License-Identifier: CC-BY-SA-4.0 OR BSD-2-Clause
+copyrights:
+- Copyright (C) 2020 embedded brains GmbH (http://www.embedded-brains.de)
+enabled-by: true
+links:
+- role: spec-member
+ uid: root
+- role: spec-refinement
+ spec-key: glossary-type
+ spec-value: group
+ uid: glossary
+- role: spec-refinement
+ spec-key: glossary-type
+ spec-value: term
+ uid: glossary
+spec-description: null
+spec-example: null
+spec-info:
+ dict:
+ attributes: {}
+ description: null
+ mandatory-attributes: all
+spec-name: Glossary More
+spec-type: glossary-more
+type: spec
diff --git a/rtemsqual/tests/spec/glossary.yml b/rtemsqual/tests/spec/glossary.yml
new file mode 100644
index 00000000..6a34d364
--- /dev/null
+++ b/rtemsqual/tests/spec/glossary.yml
@@ -0,0 +1,24 @@
+SPDX-License-Identifier: CC-BY-SA-4.0 OR BSD-2-Clause
+copyrights:
+- Copyright (C) 2020 embedded brains GmbH (http://www.embedded-brains.de)
+enabled-by: true
+links:
+- role: spec-member
+ uid: root
+- role: spec-refinement
+ spec-key: type
+ spec-value: glossary
+ uid: root
+spec-description: null
+spec-example: null
+spec-info:
+ dict:
+ attributes:
+ glossary-type:
+ description: null
+ spec-type: name
+ description: null
+ mandatory-attributes: all
+spec-name: Glossary
+spec-type: glossary
+type: spec
diff --git a/rtemsqual/tests/spec/interface-more.yml b/rtemsqual/tests/spec/interface-more.yml
new file mode 100644
index 00000000..070f62f7
--- /dev/null
+++ b/rtemsqual/tests/spec/interface-more.yml
@@ -0,0 +1,85 @@
+SPDX-License-Identifier: CC-BY-SA-4.0 OR BSD-2-Clause
+copyrights:
+- Copyright (C) 2020 embedded brains GmbH (http://www.embedded-brains.de)
+enabled-by: true
+links:
+- role: spec-member
+ uid: root
+- role: spec-refinement
+ spec-key: interface-type
+ spec-value: appl-config-group
+ uid: interface
+- role: spec-refinement
+ spec-key: interface-type
+ spec-value: appl-config-option
+ uid: interface
+- role: spec-refinement
+ spec-key: interface-type
+ spec-value: struct
+ uid: interface
+- role: spec-refinement
+ spec-key: interface-type
+ spec-value: union
+ uid: interface
+- role: spec-refinement
+ spec-key: interface-type
+ spec-value: container
+ uid: interface
+- role: spec-refinement
+ spec-key: interface-type
+ spec-value: define
+ uid: interface
+- role: spec-refinement
+ spec-key: interface-type
+ spec-value: domain
+ uid: interface
+- role: spec-refinement
+ spec-key: interface-type
+ spec-value: enum
+ uid: interface
+- role: spec-refinement
+ spec-key: interface-type
+ spec-value: enumerator
+ uid: interface
+- role: spec-refinement
+ spec-key: interface-type
+ spec-value: forward-declaration
+ uid: interface
+- role: spec-refinement
+ spec-key: interface-type
+ spec-value: function
+ uid: interface
+- role: spec-refinement
+ spec-key: interface-type
+ spec-value: group
+ uid: interface
+- role: spec-refinement
+ spec-key: interface-type
+ spec-value: header-file
+ uid: interface
+- role: spec-refinement
+ spec-key: interface-type
+ spec-value: macro
+ uid: interface
+- role: spec-refinement
+ spec-key: interface-type
+ spec-value: typedef
+ uid: interface
+- role: spec-refinement
+ spec-key: interface-type
+ spec-value: unspecified
+ uid: interface
+- role: spec-refinement
+ spec-key: interface-type
+ spec-value: variable
+ uid: interface
+spec-description: null
+spec-example: null
+spec-info:
+ dict:
+ attributes: {}
+ description: null
+ mandatory-attributes: all
+spec-name: Interface More
+spec-type: interface-more
+type: spec
diff --git a/rtemsqual/tests/spec/interface.yml b/rtemsqual/tests/spec/interface.yml
new file mode 100644
index 00000000..99ba9ac5
--- /dev/null
+++ b/rtemsqual/tests/spec/interface.yml
@@ -0,0 +1,24 @@
+SPDX-License-Identifier: CC-BY-SA-4.0 OR BSD-2-Clause
+copyrights:
+- Copyright (C) 2020 embedded brains GmbH (http://www.embedded-brains.de)
+enabled-by: true
+links:
+- role: spec-member
+ uid: root
+- role: spec-refinement
+ spec-key: type
+ spec-value: interface
+ uid: root
+spec-description: null
+spec-example: null
+spec-info:
+ dict:
+ attributes:
+ build-type:
+ description: null
+ spec-type: name
+ description: null
+ mandatory-attributes: all
+spec-name: Interface
+spec-type: interface
+type: spec
diff --git a/rtemsqual/tests/spec/other.yml b/rtemsqual/tests/spec/other.yml
new file mode 100644
index 00000000..ae7b8770
--- /dev/null
+++ b/rtemsqual/tests/spec/other.yml
@@ -0,0 +1,21 @@
+SPDX-License-Identifier: CC-BY-SA-4.0 OR BSD-2-Clause
+copyrights:
+- Copyright (C) 2020 embedded brains GmbH (http://www.embedded-brains.de)
+enabled-by: true
+links:
+- role: spec-member
+ uid: root
+- role: spec-refinement
+ spec-key: type
+ spec-value: other
+ uid: root
+spec-description: null
+spec-example: null
+spec-info:
+ dict:
+ attributes: {}
+ description: null
+ mandatory-attributes: all
+spec-name: Other
+spec-type: other
+type: spec
diff --git a/rtemsqual/tests/spec/requirement.yml b/rtemsqual/tests/spec/requirement.yml
new file mode 100644
index 00000000..72efb21c
--- /dev/null
+++ b/rtemsqual/tests/spec/requirement.yml
@@ -0,0 +1,24 @@
+SPDX-License-Identifier: CC-BY-SA-4.0 OR BSD-2-Clause
+copyrights:
+- Copyright (C) 2020 embedded brains GmbH (http://www.embedded-brains.de)
+enabled-by: true
+links:
+- role: spec-member
+ uid: root
+- role: spec-refinement
+ spec-key: type
+ spec-value: requirement
+ uid: root
+spec-description: null
+spec-example: null
+spec-info:
+ dict:
+ attributes:
+ requirement-type:
+ description: null
+ spec-type: name
+ description: null
+ mandatory-attributes: all
+spec-name: Requirement
+spec-type: requirement
+type: spec
diff --git a/rtemsqual/tests/spec/root.yml b/rtemsqual/tests/spec/root.yml
new file mode 100644
index 00000000..4c3ea506
--- /dev/null
+++ b/rtemsqual/tests/spec/root.yml
@@ -0,0 +1,18 @@
+SPDX-License-Identifier: CC-BY-SA-4.0 OR BSD-2-Clause
+copyrights:
+- Copyright (C) 2020 embedded brains GmbH (http://www.embedded-brains.de)
+enabled-by: true
+links: []
+spec-description: null
+spec-example: null
+spec-info:
+ dict:
+ attributes:
+ type:
+ description: null
+ spec-type: name
+ description: null
+ mandatory-attributes: all
+spec-name: Root
+spec-type: root
+type: spec
diff --git a/rtemsqual/tests/spec/spec.yml b/rtemsqual/tests/spec/spec.yml
new file mode 100644
index 00000000..b4e42b2e
--- /dev/null
+++ b/rtemsqual/tests/spec/spec.yml
@@ -0,0 +1,21 @@
+SPDX-License-Identifier: CC-BY-SA-4.0 OR BSD-2-Clause
+copyrights:
+- Copyright (C) 2020 embedded brains GmbH (http://www.embedded-brains.de)
+enabled-by: true
+links:
+- role: spec-member
+ uid: root
+- role: spec-refinement
+ spec-key: type
+ spec-value: spec
+ uid: root
+spec-description: null
+spec-example: null
+spec-info:
+ dict:
+ attributes: {}
+ description: null
+ mandatory-attributes: all
+spec-name: Spec
+spec-type: spec
+type: spec
diff --git a/rtemsqual/tests/spec/test-case.yml b/rtemsqual/tests/spec/test-case.yml
new file mode 100644
index 00000000..9eeeb674
--- /dev/null
+++ b/rtemsqual/tests/spec/test-case.yml
@@ -0,0 +1,21 @@
+SPDX-License-Identifier: CC-BY-SA-4.0 OR BSD-2-Clause
+copyrights:
+- Copyright (C) 2020 embedded brains GmbH (http://www.embedded-brains.de)
+enabled-by: true
+links:
+- role: spec-member
+ uid: root
+- role: spec-refinement
+ spec-key: type
+ spec-value: test-case
+ uid: root
+spec-description: null
+spec-example: null
+spec-info:
+ dict:
+ attributes: {}
+ description: null
+ mandatory-attributes: all
+spec-name: Test Case
+spec-type: test-case
+type: spec
diff --git a/rtemsqual/tests/spec/test-suite.yml b/rtemsqual/tests/spec/test-suite.yml
new file mode 100644
index 00000000..8818c410
--- /dev/null
+++ b/rtemsqual/tests/spec/test-suite.yml
@@ -0,0 +1,21 @@
+SPDX-License-Identifier: CC-BY-SA-4.0 OR BSD-2-Clause
+copyrights:
+- Copyright (C) 2020 embedded brains GmbH (http://www.embedded-brains.de)
+enabled-by: true
+links:
+- role: spec-member
+ uid: root
+- role: spec-refinement
+ spec-key: type
+ spec-value: test-suite
+ uid: root
+spec-description: null
+spec-example: null
+spec-info:
+ dict:
+ attributes: {}
+ description: null
+ mandatory-attributes: all
+spec-name: Test Suite
+spec-type: test-suite
+type: spec
diff --git a/rtemsqual/tests/test_content_sphinx.py b/rtemsqual/tests/test_content_sphinx.py
index 5d24a818..f6c7f057 100644
--- a/rtemsqual/tests/test_content_sphinx.py
+++ b/rtemsqual/tests/test_content_sphinx.py
@@ -261,12 +261,14 @@ def test_license_and_copyrights():
def test_substitute(tmpdir):
- config = create_item_cache_config_and_copy_spec(tmpdir, "spec-sphinx")
+ config = create_item_cache_config_and_copy_spec(tmpdir,
+ "spec-sphinx",
+ with_spec_types=True)
item_cache = ItemCache(config)
mapper = SphinxMapper(item_cache["/x"])
with pytest.raises(KeyError):
mapper.substitute("${x:/y}")
assert mapper.substitute("${x:/term}") == ":term:`y`"
assert mapper.substitute("${x:/plural}") == ":term:`ys <y>`"
- mapper.add_get_reference("foo", "/name", lambda x, y: x[y])
- assert mapper.substitute("${y:/name}") == "bar"
+ mapper.add_get_reference("other:/name", lambda x, y: x[y])
+ assert mapper.substitute("${y:/name}") == "foobar"
diff --git a/rtemsqual/tests/test_glossary.py b/rtemsqual/tests/test_glossary.py
index f975b3ca..65113540 100644
--- a/rtemsqual/tests/test_glossary.py
+++ b/rtemsqual/tests/test_glossary.py
@@ -33,7 +33,7 @@ from rtemsqual.tests.util import create_item_cache_config_and_copy_spec
def test_glossary(tmpdir):
item_cache_config = create_item_cache_config_and_copy_spec(
- tmpdir, "spec-glossary")
+ tmpdir, "spec-glossary", with_spec_types=True)
item_cache = ItemCache(item_cache_config)
glossary_config = {}
diff --git a/rtemsqual/tests/test_interface.py b/rtemsqual/tests/test_interface.py
index f6b110d8..8415ba75 100644
--- a/rtemsqual/tests/test_interface.py
+++ b/rtemsqual/tests/test_interface.py
@@ -44,7 +44,7 @@ def test_interface(tmpdir):
interface_config["item-level-interfaces"] = ["/command-line"]
item_cache_config = create_item_cache_config_and_copy_spec(
- tmpdir, "spec-interface")
+ tmpdir, "spec-interface", with_spec_types=True)
generate(interface_config, ItemCache(item_cache_config))
with open(os.path.join(base_directory, "include", "h.h"), "r") as src:
diff --git a/rtemsqual/tests/test_interfacedoc.py b/rtemsqual/tests/test_interfacedoc.py
index 7f02ff99..f68e9587 100644
--- a/rtemsqual/tests/test_interfacedoc.py
+++ b/rtemsqual/tests/test_interfacedoc.py
@@ -48,7 +48,7 @@ def test_interfacedoc(tmpdir):
doc_config_2["directives-target"] = directives_2_rst
item_cache_config = create_item_cache_config_and_copy_spec(
- tmpdir, "spec-interface")
+ tmpdir, "spec-interface", with_spec_types=True)
generate([doc_config, doc_config_2], ItemCache(item_cache_config))
with open(introduction_rst, "r") as src:
diff --git a/rtemsqual/tests/test_items_itemcache.py b/rtemsqual/tests/test_items_itemcache.py
index 8274dfb9..a38e225b 100644
--- a/rtemsqual/tests/test_items_itemcache.py
+++ b/rtemsqual/tests/test_items_itemcache.py
@@ -75,9 +75,9 @@ class Mapper(ItemMapper):
def dup(self, value):
return value + value
- def get_value(self, item, path, value, key, index):
- if key == "x-to-b":
- return value["b"]
+ def get_value(self, ctx):
+ if ctx.key == "x-to-b":
+ return ctx.value["b"]
raise KeyError
diff --git a/rtemsqual/tests/test_validation.py b/rtemsqual/tests/test_validation.py
index 62234100..209e8268 100644
--- a/rtemsqual/tests/test_validation.py
+++ b/rtemsqual/tests/test_validation.py
@@ -40,7 +40,7 @@ def test_validation(tmpdir):
generate(validation_config, EmptyItemCache())
item_cache_config = create_item_cache_config_and_copy_spec(
- tmpdir, "spec-validation")
+ tmpdir, "spec-validation", with_spec_types=True)
generate(validation_config, ItemCache(item_cache_config))
with open(os.path.join(base_directory, "ts.c"), "r") as src:
diff --git a/rtemsqual/tests/util.py b/rtemsqual/tests/util.py
index 37cc5e9c..d07df74c 100644
--- a/rtemsqual/tests/util.py
+++ b/rtemsqual/tests/util.py
@@ -29,8 +29,10 @@ import shutil
from typing import Dict
-def create_item_cache_config_and_copy_spec(tmp_dir: str,
- spec_dir: str) -> Dict[str, str]:
+def create_item_cache_config_and_copy_spec(
+ tmp_dir: str,
+ spec_dir: str,
+ with_spec_types: bool = False) -> Dict[str, str]:
"""
Creates an item cache configuration and copies a specification
directory to the temporary tests directory.
@@ -42,5 +44,10 @@ def create_item_cache_config_and_copy_spec(tmp_dir: str,
spec_dst = os.path.join(tmp_dir, "spec")
shutil.copytree(spec_src, spec_dst)
config["paths"] = [os.path.normpath(spec_dst)]
- config["spec-type-root-uid"] = None
+ if with_spec_types:
+ spec = os.path.join(os.path.dirname(__file__), "spec")
+ shutil.copytree(spec, os.path.join(spec_dst, "spec"))
+ config["spec-type-root-uid"] = "/spec/root"
+ else:
+ config["spec-type-root-uid"] = None
return config
diff --git a/rtemsqual/validation.py b/rtemsqual/validation.py
index 3ffd2c56..1f4bb276 100644
--- a/rtemsqual/validation.py
+++ b/rtemsqual/validation.py
@@ -30,19 +30,15 @@ from typing import Any, Dict, List, NamedTuple, Optional, Tuple
from rtemsqual.content import CContent, CInclude, enabled_by_to_exp, \
ExpressionMapper
-from rtemsqual.items import Item, ItemCache, ItemMapper
+from rtemsqual.items import Item, ItemCache, ItemGetValueContext, ItemMapper
ItemMap = Dict[str, Item]
class _CodeMapper(ItemMapper):
- def get_value(self, item: Item, path: str, _value: Any, key: str,
- _index: Optional[int]) -> Any:
- if path == "/" and key == "test-run" and item[
- "type"] == "requirement" and item[
- "requirement-type"] == "functional" and item[
- "functional-type"] == "action":
- return f"{item['test-name'].replace(' ', '')}_Run"
+ def get_value(self, ctx: ItemGetValueContext) -> Any:
+ if ctx.type_path_key == "requirement/functional/action:/test-run":
+ return f"{ctx.item['test-name'].replace(' ', '')}_Run"
raise KeyError