[rtems-central commit] items: Add Item.cache

Sebastian Huber sebh at rtems.org
Sat Oct 24 10:27:38 UTC 2020


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

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Sat Oct 24 12:07:49 2020 +0200

items: Add Item.cache

---

 rtemsspec/items.py                 | 9 +++++++--
 rtemsspec/tests/test_items_item.py | 6 ++++++
 2 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/rtemsspec/items.py b/rtemsspec/items.py
index fdd37eb..e9f1c0e 100644
--- a/rtemsspec/items.py
+++ b/rtemsspec/items.py
@@ -142,7 +142,7 @@ class Item:
 
     # pylint: disable=too-many-public-methods
     def __init__(self, item_cache: "ItemCache", uid: str, data: Any):
-        self._item_cache = item_cache
+        self._cache = item_cache
         self._uid = uid
         self._data = data
         self._links_to_parents = []  # type: List[Link]
@@ -170,6 +170,11 @@ class Item:
     def __setitem__(self, key: str, value: Any) -> None:
         self._data[key] = value
 
+    @property
+    def cache(self) -> "ItemCache":
+        """ Returns the cache of the items. """
+        return self._cache
+
     def get(self, key: str, default: Any) -> Any:
         """
         Gets the attribute value if the attribute exists, otherwise the
@@ -235,7 +240,7 @@ class Item:
         Maps the absolute UID or the UID relative to this item to the
         corresponding item.
         """
-        return self._item_cache[self.to_abs_uid(abs_or_rel_uid)]
+        return self._cache[self.to_abs_uid(abs_or_rel_uid)]
 
     def links_to_parents(self) -> Iterator[Link]:
         """ Yields the links to the parents of this items. """
diff --git a/rtemsspec/tests/test_items_item.py b/rtemsspec/tests/test_items_item.py
index bb9b085..e84ce27 100644
--- a/rtemsspec/tests/test_items_item.py
+++ b/rtemsspec/tests/test_items_item.py
@@ -85,6 +85,12 @@ def test_data():
     assert item.data == {"x": "y"}
 
 
+def test_cache():
+    item_cache = EmptyItemCache()
+    item = Item(item_cache, "i", {})
+    assert item.cache == item_cache
+
+
 def test_get_key_path():
     data = {}
     data["a"] = {"b": "c", "d": [1, 2, 3]}



More information about the vc mailing list