diff mbox series

[libgpiod,21/22] bindings: python: tests: use f-strings

Message ID 20240927-vfazio-mypy-v1-21-91a7c2e20884@xes-inc.com
State Superseded
Headers show
Series bindings: python: conform to mypy and ruff linter recommendations | expand

Commit Message

Vincent Fazio Sept. 27, 2024, 6:53 p.m. UTC
Signed-off-by: Vincent Fazio <vfazio@xes-inc.com>
---
 bindings/python/tests/__init__.py           |  4 +---
 bindings/python/tests/tests_chip.py         | 10 ++++------
 bindings/python/tests/tests_chip_info.py    |  2 +-
 bindings/python/tests/tests_line_request.py |  4 +---
 bindings/python/tests/tests_module.py       |  4 ++--
 5 files changed, 9 insertions(+), 15 deletions(-)

Comments

Bartosz Golaszewski Oct. 8, 2024, 1:35 p.m. UTC | #1
On Fri, Sep 27, 2024 at 8:57 PM Vincent Fazio <vfazio@xes-inc.com> wrote:
>
> Signed-off-by: Vincent Fazio <vfazio@xes-inc.com>
> ---
>  bindings/python/tests/__init__.py           |  4 +---
>  bindings/python/tests/tests_chip.py         | 10 ++++------
>  bindings/python/tests/tests_chip_info.py    |  2 +-
>  bindings/python/tests/tests_line_request.py |  4 +---
>  bindings/python/tests/tests_module.py       |  4 ++--
>  5 files changed, 9 insertions(+), 15 deletions(-)
>

Looks good.

Bart
diff mbox series

Patch

diff --git a/bindings/python/tests/__init__.py b/bindings/python/tests/__init__.py
index 2374e8155373efbd94d5c66dcfdffa7cc23be9f6..a0f22ae717271766b4175a775cc6ec19c9b24441 100644
--- a/bindings/python/tests/__init__.py
+++ b/bindings/python/tests/__init__.py
@@ -9,7 +9,5 @@  current_version = LooseVersion(os.uname().release.split("-")[0])
 
 if current_version < required_kernel_version:
     raise NotImplementedError(
-        "linux kernel version must be at least {} - got {}".format(
-            required_kernel_version, current_version
-        )
+        f"linux kernel version must be at least {required_kernel_version} - got {current_version}"
     )
diff --git a/bindings/python/tests/tests_chip.py b/bindings/python/tests/tests_chip.py
index b719f6ba402c962b3ba8029cef61ed28fd1a525a..3ea2be1d272d0ba5fca59c51f08962508505efb9 100644
--- a/bindings/python/tests/tests_chip.py
+++ b/bindings/python/tests/tests_chip.py
@@ -26,7 +26,7 @@  class ChipConstructor(TestCase):
             pass
 
     def test_open_chip_by_link(self) -> None:
-        link = "/tmp/gpiod-py-test-link.{}".format(os.getpid())
+        link = f"/tmp/gpiod-py-test-link.{os.getpid()}"
         sim = gpiosim.Chip()
 
         with LinkGuard(sim.dev_path, link):
@@ -96,7 +96,7 @@  class ChipProperties(TestCase):
 class ChipDevPathFromLink(TestCase):
     def test_dev_path_open_by_link(self) -> None:
         sim = gpiosim.Chip()
-        link = "/tmp/gpiod-py-test-link.{}".format(os.getpid())
+        link = f"/tmp/gpiod-py-test-link.{os.getpid()}"
 
         with LinkGuard(sim.dev_path, link):
             with gpiod.Chip(link) as chip:
@@ -206,7 +206,7 @@  class StringRepresentation(TestCase):
 
     def test_repr(self) -> None:
         assert self.sim
-        self.assertEqual(repr(self.chip), 'gpiod.Chip("{}")'.format(self.sim.dev_path))
+        self.assertEqual(repr(self.chip), f'gpiod.Chip("{self.sim.dev_path}")')
 
         cmp = eval(repr(self.chip))
         self.assertEqual(self.chip.path, cmp.path)
@@ -216,9 +216,7 @@  class StringRepresentation(TestCase):
         info = self.chip.get_info()
         self.assertEqual(
             str(self.chip),
-            '<Chip path="{}" fd={} info=<ChipInfo name="{}" label="foobar" num_lines=4>>'.format(
-                self.sim.dev_path, self.chip.fd, info.name
-            ),
+            f'<Chip path="{self.sim.dev_path}" fd={self.chip.fd} info=<ChipInfo name="{info.name}" label="foobar" num_lines=4>>',
         )
 
 
diff --git a/bindings/python/tests/tests_chip_info.py b/bindings/python/tests/tests_chip_info.py
index 463f07ab8edeec7dde8dacc4829b86dd3b1d6ebd..8d0a2f955edeb7fe8a285e9951f6b4d392f4490d 100644
--- a/bindings/python/tests/tests_chip_info.py
+++ b/bindings/python/tests/tests_chip_info.py
@@ -56,5 +56,5 @@  class ChipInfoStringRepresentation(TestCase):
 
             self.assertEqual(
                 str(info),
-                '<ChipInfo name="{}" label="foobar" num_lines=16>'.format(sim.name),
+                f'<ChipInfo name="{sim.name}" label="foobar" num_lines=16>',
             )
diff --git a/bindings/python/tests/tests_line_request.py b/bindings/python/tests/tests_line_request.py
index bae8815b98654145c26071c4fc40816469313192..afee644558b5e734b50a6d90dd6a0a867f466eb7 100644
--- a/bindings/python/tests/tests_line_request.py
+++ b/bindings/python/tests/tests_line_request.py
@@ -635,9 +635,7 @@  class LineRequestStringRepresentation(TestCase):
             with chip.request_lines(config={(2, 6, 4, 1): None}) as req:
                 self.assertEqual(
                     str(req),
-                    '<LineRequest chip="{}" num_lines=4 offsets=[2, 6, 4, 1] fd={}>'.format(
-                        self.sim.name, req.fd
-                    ),
+                    f'<LineRequest chip="{self.sim.name}" num_lines=4 offsets=[2, 6, 4, 1] fd={req.fd}>',
                 )
 
     def test_str_released(self) -> None:
diff --git a/bindings/python/tests/tests_module.py b/bindings/python/tests/tests_module.py
index efd49db59e6567b9bc5ee0096ccce3281ac466f3..7120c6346ba4666adb250d0880d5777dbb7666ea 100644
--- a/bindings/python/tests/tests_module.py
+++ b/bindings/python/tests/tests_module.py
@@ -36,14 +36,14 @@  class IsGPIOChip(TestCase):
         self.assertTrue(gpiod.is_gpiochip_device(path=sim.dev_path))
 
     def test_is_gpiochip_link_good(self) -> None:
-        link = "/tmp/gpiod-py-test-link.{}".format(os.getpid())
+        link = f"/tmp/gpiod-py-test-link.{os.getpid()}"
         sim = gpiosim.Chip()
 
         with LinkGuard(sim.dev_path, link):
             self.assertTrue(gpiod.is_gpiochip_device(link))
 
     def test_is_gpiochip_link_bad(self) -> None:
-        link = "/tmp/gpiod-py-test-link.{}".format(os.getpid())
+        link = f"/tmp/gpiod-py-test-link.{os.getpid()}"
 
         with LinkGuard("/dev/null", link):
             self.assertFalse(gpiod.is_gpiochip_device(link))