[rtems-central commit] items: Add Link order

Sebastian Huber sebh at rtems.org
Tue Nov 21 13:35:40 UTC 2023


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

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Tue Nov 21 11:13:15 2023 +0100

items: Add Link order

---

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

diff --git a/rtemsspec/items.py b/rtemsspec/items.py
index 4b0d2600..30af77f3 100644
--- a/rtemsspec/items.py
+++ b/rtemsspec/items.py
@@ -133,6 +133,12 @@ class Link:
     def __setitem__(self, key: str, value: Any) -> None:
         self._data[key] = value
 
+    def __lt__(self, other: Any) -> bool:
+        if not isinstance(other, Link):
+            return NotImplemented
+        # pylint: disable=protected-access
+        return self._item.uid < other._item.uid
+
     @property
     def item(self) -> "Item":
         """ The item referenced by this link. """
diff --git a/rtemsspec/tests/test_items_item.py b/rtemsspec/tests/test_items_item.py
index 1f107e56..8208bb9c 100644
--- a/rtemsspec/tests/test_items_item.py
+++ b/rtemsspec/tests/test_items_item.py
@@ -154,6 +154,9 @@ def test_children():
     assert len(children) == 0
     links = [link for link in parent.links_to_children()]
     assert len(links) == 1
+    assert not links[0] < links[0]
+    with pytest.raises(TypeError):
+        links[0] < 0
     assert links[0].item == child
     assert links[0]["a"] == "b"
     assert links[0].role == "c"



More information about the vc mailing list