Changeset 833470c in rtems-central


Ignore:
Timestamp:
May 6, 2020, 10:36:53 AM (6 months ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
master
Children:
1767cc8
Parents:
a5f3cc1
git-author:
Sebastian Huber <sebastian.huber@…> (05/06/20 10:36:53)
git-committer:
Sebastian Huber <sebastian.huber@…> (05/28/20 08:38:22)
Message:

items: Add Item.get()

Location:
rtemsqual
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • rtemsqual/items.py

    ra5f3cc1 r833470c  
    130130        return key in self._data
    131131
    132     def __getitem__(self, name: str) -> Any:
    133         return self._data[name]
     132    def __getitem__(self, key: str) -> Any:
     133        return self._data[key]
     134
     135    def get(self, key: str, default: Any) -> Any:
     136        """
     137        Gets the attribute value if the attribute exists, otherwise the
     138        specified default value is returned.
     139        """
     140        return self._data.get(key, default)
    134141
    135142    def get_by_key_path(self,
  • rtemsqual/tests/test_items_item.py

    ra5f3cc1 r833470c  
    8383
    8484
     85def test_get():
     86    data = {}
     87    data["x"] = "y"
     88    item = Item(EmptyCache(), "z", data)
     89    assert item.get("x", "z") == "y"
     90    assert item.get("z", "a") == "a"
     91
     92
    8593def test_children():
    8694    child = Item(EmptyCache(), "c", {})
Note: See TracChangeset for help on using the changeset viewer.