diff mbox series

[libgpiod,4/5] bindings: python: provide the chip_path property in line_request

Message ID 20230719192057.172560-5-brgl@bgdev.pl
State New
Headers show
Series core: provide information about the parent chip in line requests | expand

Commit Message

Bartosz Golaszewski July 19, 2023, 7:20 p.m. UTC
From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>

Provide a wrapper around gpiod_line_request_get_chip_path() for Python
bindings and update the tests.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
---
 bindings/python/gpiod/chip.py               |  1 +
 bindings/python/gpiod/line_request.py       | 12 ++++++++++--
 bindings/python/tests/tests_line_request.py | 13 ++++++++-----
 3 files changed, 19 insertions(+), 7 deletions(-)
diff mbox series

Patch

diff --git a/bindings/python/gpiod/chip.py b/bindings/python/gpiod/chip.py
index da93370..0629db0 100644
--- a/bindings/python/gpiod/chip.py
+++ b/bindings/python/gpiod/chip.py
@@ -315,6 +315,7 @@  class Chip:
         req_internal = self._chip.request_lines(line_cfg, consumer, event_buffer_size)
         request = LineRequest(req_internal)
 
+        request._chip_path = self.path
         request._offsets = req_internal.offsets
         request._name_map = name_map
         request._offset_map = offset_map
diff --git a/bindings/python/gpiod/line_request.py b/bindings/python/gpiod/line_request.py
index 096bf18..aaae37c 100644
--- a/bindings/python/gpiod/line_request.py
+++ b/bindings/python/gpiod/line_request.py
@@ -212,10 +212,18 @@  class LineRequest:
         if not self._req:
             return "<LineRequest RELEASED>"
 
-        return "<LineRequest num_lines={} offsets={} fd={}>".format(
-            self.num_lines, self.offsets, self.fd
+        return '<LineRequest chip_path="{}" num_lines={} offsets={} fd={}>'.format(
+            self.chip_path, self.num_lines, self.offsets, self.fd
         )
 
+    @property
+    def chip_path(self) -> str:
+        """
+        Path of the chip this request was made on.
+        """
+        self._check_released()
+        return self._chip_path
+
     @property
     def num_lines(self) -> int:
         """
diff --git a/bindings/python/tests/tests_line_request.py b/bindings/python/tests/tests_line_request.py
index aa84b9a..4ab3ea5 100644
--- a/bindings/python/tests/tests_line_request.py
+++ b/bindings/python/tests/tests_line_request.py
@@ -529,11 +529,14 @@  class LineRequestStringRepresentation(TestCase):
         del self.sim
 
     def test_str(self):
-        with gpiod.request_lines(self.sim.dev_path, config={(2, 6, 4, 1): None}) as req:
-            self.assertEqual(
-                str(req),
-                "<LineRequest num_lines=4 offsets=[2, 6, 4, 1] fd={}>".format(req.fd),
-            )
+        with gpiod.Chip(self.sim.dev_path) as chip:
+            with chip.request_lines(config={(2, 6, 4, 1): None}) as req:
+                self.assertEqual(
+                    str(req),
+                    '<LineRequest chip_path="{}" num_lines=4 offsets=[2, 6, 4, 1] fd={}>'.format(
+                        chip.path, req.fd
+                    ),
+                )
 
     def test_str_released(self):
         req = gpiod.request_lines(self.sim.dev_path, config={(2, 6, 4, 1): None})