[rtems-central commit] specdoc/specverify: Support values of any type

Sebastian Huber sebh at rtems.org
Fri Nov 13 10:09:47 UTC 2020


Module:    rtems-central
Branch:    master
Commit:    ee2409fcbbc256ab4e1ba8d8d31b2a5385f3ffbc
Changeset: http://git.rtems.org/rtems-central/commit/?id=ee2409fcbbc256ab4e1ba8d8d31b2a5385f3ffbc

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Thu Nov 12 13:05:50 2020 +0100

specdoc/specverify: Support values of any type

---

 rtemsspec/specdoc.py                    |  1 +
 rtemsspec/specverify.py                 |  8 ++++++++
 rtemsspec/tests/spec-verify/d.yml       |  1 +
 rtemsspec/tests/spec-verify/spec2/d.yml |  3 +++
 rtemsspec/tests/test_specverify.py      | 10 ++++++++--
 5 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/rtemsspec/specdoc.py b/rtemsspec/specdoc.py
index 48e00f9..b2dab6e 100644
--- a/rtemsspec/specdoc.py
+++ b/rtemsspec/specdoc.py
@@ -35,6 +35,7 @@ from rtemsspec.specverify import NAME
 _DocumenterMap = Dict[str, "_Documenter"]
 
 _PRIMITIVE_TYPES = {
+    "any": "The attribute value may have any type.",
     "bool": "{} {} be a boolean.",
     "float": "{} {} be a floating-point number.",
     "int": "{} {} be an integer number.",
diff --git a/rtemsspec/specverify.py b/rtemsspec/specverify.py
index 060a39d..2f8f058 100755
--- a/rtemsspec/specverify.py
+++ b/rtemsspec/specverify.py
@@ -241,6 +241,13 @@ class _Verifier:
         """ Resolves the type refinements for this type. """
 
 
+class _AnyVerifier(_Verifier):
+    def verify(self, path: _Path, _value: Any) -> Set[str]:
+        """ Does not verify the value. """
+        self.verify_info(path)
+        return set()
+
+
 class _NameVerifier(_Verifier):
     def verify(self, path: _Path, value: Any) -> Set[str]:
         """ Verifies a name. """
@@ -493,6 +500,7 @@ class SpecVerifier:
     # pylint: disable=too-few-public-methods
     def __init__(self, item_cache: ItemCache, root_uid: str):
         verifier_map = {}  # type: _VerifierMap
+        _AnyVerifier("any", verifier_map)
         _NameVerifier("name", verifier_map)
         _UIDVerifier("uid", verifier_map)
         _Verifier("bool", verifier_map)
diff --git a/rtemsspec/tests/spec-verify/d.yml b/rtemsspec/tests/spec-verify/d.yml
index 68f65b9..2335ebc 100644
--- a/rtemsspec/tests/spec-verify/d.yml
+++ b/rtemsspec/tests/spec-verify/d.yml
@@ -1,4 +1,5 @@
 SPDX-License-Identifier: CC-BY-SA-4.0 OR BSD-2-Clause
+any: -1
 copyrights:
 - Copyright (C) 2020 embedded brains GmbH (http://www.embedded-brains.de
 d-type: blub
diff --git a/rtemsspec/tests/spec-verify/spec2/d.yml b/rtemsspec/tests/spec-verify/spec2/d.yml
index 2708996..49557ba 100644
--- a/rtemsspec/tests/spec-verify/spec2/d.yml
+++ b/rtemsspec/tests/spec-verify/spec2/d.yml
@@ -15,6 +15,9 @@ spec-info:
     attributes:
       d-type:
         spec-type: name
+      any:
+        description: null
+        spec-type: any
     mandatory-attributes:
     - d-type
 spec-type: d
diff --git a/rtemsspec/tests/test_specverify.py b/rtemsspec/tests/test_specverify.py
index a3cf571..c53e37a 100644
--- a/rtemsspec/tests/test_specverify.py
+++ b/rtemsspec/tests/test_specverify.py
@@ -79,7 +79,8 @@ def test_verify(caplog, tmpdir):
     item_cache = ItemCache(item_cache_config)
     caplog.set_level(logging.INFO)
     verifier = SpecVerifier(item_cache, "/spec/root")
-    assert get_and_clear_log(caplog) == """INFO type: any-dict
+    assert get_and_clear_log(caplog) == """INFO type: any
+INFO type: any-dict
 INFO type: bool
 INFO type: c
 INFO type: copyright
@@ -230,6 +231,7 @@ INFO /d:/enabled-by: verify using type 'enabled-by'
 INFO /d:/links: verify using type 'links'
 INFO /d:/type: verify using type 'name'
 INFO /d: verify using type 'd'
+INFO /d:/any: verify using type 'any'
 INFO /d:/d-type: verify using type 'name'
 INFO /d: verify using type 'd-a'
 INFO /d:/d-type: verify using type 'x'
@@ -1459,6 +1461,10 @@ INFO /spec2/d:/spec-info: verify using type 'spec-info'
 INFO /spec2/d:/spec-info/dict: verify using type 'spec-dict'
 ERROR /spec2/d:/spec-info/dict: missing mandatory keys for type 'spec-dict': ['description']
 INFO /spec2/d:/spec-info/dict/attributes: verify using type 'spec-attributes'
+INFO /spec2/d:/spec-info/dict/attributes/any: verify using type 'name'
+INFO /spec2/d:/spec-info/dict/attributes/any: verify using type 'spec-attribute-value'
+INFO /spec2/d:/spec-info/dict/attributes/any/description: verify using type 'optional-str'
+INFO /spec2/d:/spec-info/dict/attributes/any/spec-type: verify using type 'name'
 INFO /spec2/d:/spec-info/dict/attributes/d-type: verify using type 'name'
 INFO /spec2/d:/spec-info/dict/attributes/d-type: verify using type 'spec-attribute-value'
 ERROR /spec2/d:/spec-info/dict/attributes/d-type: missing mandatory keys for type 'spec-attribute-value': ['description']
@@ -1927,7 +1933,7 @@ INFO finished specification item verification"""
     assert info.critical == 0
     assert info.error == 91
     assert info.warning == 1
-    assert info.info == 1686
+    assert info.info == 1691
     assert info.debug == 0
     info = verifier.verify(item_cache["/spec2/x"])
     assert get_and_clear_log(



More information about the vc mailing list