[rtems-central commit] items: Return key path in ItemMapper.map()

Sebastian Huber sebh at rtems.org
Fri Sep 18 11:31:55 UTC 2020


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

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Wed Aug 12 08:04:50 2020 +0200

items: Return key path in ItemMapper.map()

---

 rtemsspec/items.py                      |  9 +++++----
 rtemsspec/tests/test_items_itemcache.py | 10 ++++++----
 rtemsspec/validation.py                 |  6 +++---
 3 files changed, 14 insertions(+), 11 deletions(-)

diff --git a/rtemsspec/items.py b/rtemsspec/items.py
index 09ba2a1..fa64f00 100644
--- a/rtemsspec/items.py
+++ b/rtemsspec/items.py
@@ -351,7 +351,7 @@ class ItemMapper(Mapping[str, object]):
         yield
         self.pop_prefix()
 
-    def map(self, identifier: str) -> Tuple[Item, Any]:
+    def map(self, identifier: str) -> Tuple[Item, str, Any]:
         """
         Maps an identifier to the corresponding item and attribute value.
         """
@@ -367,13 +367,14 @@ class ItemMapper(Mapping[str, object]):
         else:
             item = self._item.map(uid)
             prefix = ""
-        value = item.get_by_key_path(key_path, prefix, self.get_value)
+        key_path = normalize_key_path(key_path, prefix)
+        value = item.get_by_normalized_key_path(key_path, self.get_value)
         for func in pipes:
             value = getattr(self, func)(value)
-        return item, value
+        return item, key_path, value
 
     def __getitem__(self, identifier):
-        return self.map(identifier)[1]
+        return self.map(identifier)[2]
 
     def __iter__(self):
         raise StopIteration
diff --git a/rtemsspec/tests/test_items_itemcache.py b/rtemsspec/tests/test_items_itemcache.py
index 62aab04..2323760 100644
--- a/rtemsspec/tests/test_items_itemcache.py
+++ b/rtemsspec/tests/test_items_itemcache.py
@@ -102,8 +102,9 @@ def test_item_mapper(tmpdir):
     with mapper.prefix("v"):
         assert mapper[".:."] == "p"
         assert mapper[".:../x/y"] == "z"
-        item_2, value_2 = mapper.map(".:.")
-        assert item == item_2
+        item_2, key_path_2, value_2 = mapper.map(".:.")
+        assert item_2 == item
+        assert key_path_2 == "/v"
         assert value_2 == "p"
         assert mapper.substitute("$$${.:.}") == "$p"
     assert mapper.substitute_with_prefix("$$${.:.}", "v") == "$p"
@@ -118,8 +119,9 @@ def test_item_mapper(tmpdir):
     assert mapper["d/c:a/x-to-b|u|v"] == "vue"
     assert mapper["d/c:a/f[1]"] == 2
     assert mapper["d/c:a/../a/f[3]/g[0]|dup"] == 8
-    item_3, value_3 = mapper.map("/p:/v")
-    assert item == item_3
+    item_3, key_path_3, value_3 = mapper.map("/p:/v")
+    assert item_3 == item
+    assert key_path_3 == "/v"
     assert value_3 == "p"
     with pytest.raises(StopIteration):
         for something in mapper:
diff --git a/rtemsspec/validation.py b/rtemsspec/validation.py
index 4154588..5cfff89 100644
--- a/rtemsspec/validation.py
+++ b/rtemsspec/validation.py
@@ -60,16 +60,16 @@ class _Mapper(ItemMapper):
         """ Resets the test step counter. """
         self._step = 0
 
-    def map(self, identifier: str) -> Tuple[Item, Any]:
+    def map(self, identifier: str) -> Tuple[Item, str, Any]:
         if identifier == "step":
             step = self._step
             self._step = step + 1
-            return self._item, str(step)
+            return self._item, "step", str(step)
         match = _STEPS.search(identifier)
         if match:
             inc = int(match.group(1))
             self._step += inc
-            return self._item, f"Accounts for {inc} test plan steps"
+            return self._item, "step", f"Accounts for {inc} test plan steps"
         return super().map(identifier)
 
 



More information about the vc mailing list