diff options
author | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2020-10-24 12:07:49 +0200 |
---|---|---|
committer | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2020-10-24 12:07:49 +0200 |
commit | 9b358dba651141037fc044d3b9d6ac538b24f9be (patch) | |
tree | c1b7357badfacc1928b862cf561a3171238fa0d2 | |
parent | specverify: Add SpecVerify.verify() (diff) | |
download | rtems-central-9b358dba651141037fc044d3b9d6ac538b24f9be.tar.bz2 |
items: Add Item.cache
-rw-r--r-- | rtemsspec/items.py | 9 | ||||
-rw-r--r-- | 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 fdd37eb4..e9f1c0e2 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 bb9b085d..e84ce276 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]} |