1
0
mirror of https://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git synced 2026-10-24 00:48:53 +03:00
Files
libgpiod/bindings/python/tests/tests_chip_info.py
Vincent Fazio 3bb5368ba2 bindings: python: tests: selectively use f-strings
Since their inclusion in Python 3.6, f-strings have become the preferred
way to format strings with variable values as they are generally more
readable as the value substitution is in place and doesn't have to be
parsed from the list or arguments to `.format()`.

Where it does not impact readability (when the line is <120 characters),
swap usage of `.format()` to an f-string.

For lines that are not converted, inform the linter to ignore attempts
to upgrade those instances to f-strings [0]

[0]: https://docs.astral.sh/ruff/rules/f-string/

Signed-off-by: Vincent Fazio <vfazio@xes-inc.com>
Link: https://lore.kernel.org/r/20241114145116.2123714-23-vfazio@xes-inc.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2024-11-19 15:23:58 +01:00

54 lines
1.6 KiB
Python

# SPDX-License-Identifier: GPL-2.0-or-later
# SPDX-FileCopyrightText: 2022 Bartosz Golaszewski <brgl@bgdev.pl>
from unittest import TestCase
import gpiod
from . import gpiosim
class ChipInfoProperties(TestCase):
def setUp(self) -> None:
self.sim = gpiosim.Chip(label="foobar", num_lines=16)
self.chip = gpiod.Chip(self.sim.dev_path)
self.info = self.chip.get_info()
def tearDown(self) -> None:
self.info = None # type: ignore[assignment]
self.chip.close()
self.chip = None # type: ignore[assignment]
self.sim = None # type: ignore[assignment]
def test_chip_info_name(self) -> None:
self.assertEqual(self.info.name, self.sim.name)
def test_chip_info_label(self) -> None:
self.assertEqual(self.info.label, "foobar")
def test_chip_info_num_lines(self) -> None:
self.assertEqual(self.info.num_lines, 16)
def test_chip_info_properties_are_immutable(self) -> None:
with self.assertRaises(AttributeError):
self.info.name = "foobar" # type: ignore[misc]
with self.assertRaises(AttributeError):
self.info.num_lines = 4 # type: ignore[misc]
with self.assertRaises(AttributeError):
self.info.label = "foobar" # type: ignore[misc]
class ChipInfoStringRepresentation(TestCase):
def test_chip_info_str(self) -> None:
sim = gpiosim.Chip(label="foobar", num_lines=16)
with gpiod.Chip(sim.dev_path) as chip:
info = chip.get_info()
self.assertEqual(
str(info),
f'<ChipInfo name="{sim.name}" label="foobar" num_lines=16>',
)