[rtems-central commit] specverify: Add SpecVerify.verify()

Sebastian Huber sebh at rtems.org
Fri Oct 23 10:55:13 UTC 2020


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

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Fri Oct 23 12:51:34 2020 +0200

specverify: Add SpecVerify.verify()

---

 rtemsspec/specverify.py            | 10 +++++++
 rtemsspec/tests/test_specverify.py | 59 ++++++++++++++++++++++++++++++++++----
 2 files changed, 63 insertions(+), 6 deletions(-)

diff --git a/rtemsspec/specverify.py b/rtemsspec/specverify.py
index cec03c6..e3b299a 100644
--- a/rtemsspec/specverify.py
+++ b/rtemsspec/specverify.py
@@ -525,6 +525,16 @@ class SpecVerifier:
                 logging.info("finished specification item verification")
         return log_filter.get_verify_info()
 
+    def verify(self, item: Item) -> VerifyStatus:
+        """ Verifies the item. """
+        with _add_filter() as log_filter:
+            if self._root_verifier is None:
+                logging.error("root type item does not exist in item cache")
+            else:
+                self._root_verifier.verify(_Path(item, f"{item.uid}:"),
+                                           item.data)
+        return log_filter.get_verify_info()
+
 
 def verify(config: dict, item_cache: ItemCache) -> VerifyStatus:
     """
diff --git a/rtemsspec/tests/test_specverify.py b/rtemsspec/tests/test_specverify.py
index 9b70aaa..a3cf571 100644
--- a/rtemsspec/tests/test_specverify.py
+++ b/rtemsspec/tests/test_specverify.py
@@ -27,7 +27,7 @@
 import logging
 
 from rtemsspec.items import ItemCache
-from rtemsspec.specverify import verify
+from rtemsspec.specverify import SpecVerifier, verify
 from rtemsspec.tests.util import create_item_cache_config_and_copy_spec, \
     get_and_clear_log
 
@@ -54,18 +54,31 @@ def test_no_root_item(caplog, tmpdir):
     item_cache = ItemCache(item_cache_config)
     config = {"root-type": "/nix"}
     caplog.set_level(logging.INFO)
-    verify(config, item_cache)
+    info = verify(config, item_cache)
+    assert get_and_clear_log(
+        caplog) == """ERROR root type item does not exist in item cache"""
+    assert info.critical == 0
+    assert info.error == 1
+    assert info.warning == 0
+    assert info.info == 0
+    assert info.debug == 0
+    verifier = SpecVerifier(item_cache, "/nix")
+    info = verifier.verify("/blub")
     assert get_and_clear_log(
         caplog) == """ERROR root type item does not exist in item cache"""
+    assert info.critical == 0
+    assert info.error == 1
+    assert info.warning == 0
+    assert info.info == 0
+    assert info.debug == 0
 
 
 def test_verify(caplog, tmpdir):
     item_cache_config = create_item_cache_config_and_copy_spec(
         tmpdir, "spec-verify")
     item_cache = ItemCache(item_cache_config)
-    config = {"root-type": "/spec/root"}
     caplog.set_level(logging.INFO)
-    verify(config, item_cache)
+    verifier = SpecVerifier(item_cache, "/spec/root")
     assert get_and_clear_log(caplog) == """INFO type: any-dict
 INFO type: bool
 INFO type: c
@@ -130,8 +143,10 @@ INFO type: spec-str
 INFO type: str
 INFO type: str-contains
 INFO type: uid
-INFO type: x
-INFO start specification item verification
+INFO type: x"""
+    info = verifier.verify_all(item_cache)
+    assert get_and_clear_log(
+        caplog) == """INFO start specification item verification
 INFO /c1: verify using type 'root'
 INFO /c1:/SPDX-License-Identifier: verify using type 'spdx-license-identifier'
 INFO /c1:/copyrights: verify using type 'copyrights'
@@ -1909,3 +1924,35 @@ INFO /spec2/x:/spec-info/str/assert: verify using type 'spec-assert-str'
 INFO /spec2/x:/spec-info/str/assert/eq: verify using type 'str'
 INFO /spec2/x:/spec-type: verify using type 'name'
 INFO finished specification item verification"""
+    assert info.critical == 0
+    assert info.error == 91
+    assert info.warning == 1
+    assert info.info == 1686
+    assert info.debug == 0
+    info = verifier.verify(item_cache["/spec2/x"])
+    assert get_and_clear_log(
+        caplog) == """INFO /spec2/x: verify using type 'root'
+INFO /spec2/x:/SPDX-License-Identifier: verify using type 'spdx-license-identifier'
+INFO /spec2/x:/copyrights: verify using type 'copyrights'
+INFO /spec2/x:/copyrights[0]: verify using type 'copyright'
+INFO /spec2/x:/enabled-by: verify using type 'enabled-by'
+INFO /spec2/x:/links: verify using type 'links'
+INFO /spec2/x:/links[0]: verify using type 'link'
+INFO /spec2/x:/links[0]/role: verify using type 'name'
+INFO /spec2/x:/links[0]/uid: verify using type 'uid'
+INFO /spec2/x:/links[0]: verify using type 'spec-member'
+INFO /spec2/x:/type: verify using type 'name'
+INFO /spec2/x: verify using type 'spec'
+ERROR /spec2/x: missing mandatory keys for type 'spec': ['spec-description', 'spec-name']
+INFO /spec2/x:/spec-example: verify using type 'optional-str'
+INFO /spec2/x:/spec-info: verify using type 'spec-info'
+INFO /spec2/x:/spec-info/str: verify using type 'spec-str'
+ERROR /spec2/x:/spec-info/str: missing mandatory keys for type 'spec-str': ['description']
+INFO /spec2/x:/spec-info/str/assert: verify using type 'spec-assert-str'
+INFO /spec2/x:/spec-info/str/assert/eq: verify using type 'str'
+INFO /spec2/x:/spec-type: verify using type 'name'"""
+    assert info.critical == 0
+    assert info.error == 2
+    assert info.warning == 0
+    assert info.info == 18
+    assert info.debug == 0



More information about the vc mailing list