mirror of
https://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git
synced 2026-10-24 00:48:53 +03:00
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>
60 lines
2.0 KiB
Python
60 lines
2.0 KiB
Python
# SPDX-License-Identifier: GPL-2.0-or-later
|
|
# SPDX-FileCopyrightText: 2022 Bartosz Golaszewski <brgl@bgdev.pl>
|
|
|
|
import os
|
|
from unittest import TestCase
|
|
|
|
import gpiod
|
|
|
|
from . import gpiosim
|
|
from .helpers import LinkGuard
|
|
|
|
|
|
class IsGPIOChip(TestCase):
|
|
def test_is_gpiochip_bad(self) -> None:
|
|
self.assertFalse(gpiod.is_gpiochip_device("/dev/null"))
|
|
self.assertFalse(gpiod.is_gpiochip_device("/dev/nonexistent"))
|
|
|
|
def test_is_gpiochip_invalid_argument(self) -> None:
|
|
with self.assertRaises(TypeError):
|
|
gpiod.is_gpiochip_device(4) # type: ignore[arg-type]
|
|
|
|
def test_is_gpiochip_superfluous_argument(self) -> None:
|
|
with self.assertRaises(TypeError):
|
|
gpiod.is_gpiochip_device("/dev/null", 4) # type: ignore[call-arg]
|
|
|
|
def test_is_gpiochip_missing_argument(self) -> None:
|
|
with self.assertRaises(TypeError):
|
|
gpiod.is_gpiochip_device() # type: ignore[call-arg]
|
|
|
|
def test_is_gpiochip_good(self) -> None:
|
|
sim = gpiosim.Chip()
|
|
self.assertTrue(gpiod.is_gpiochip_device(sim.dev_path))
|
|
|
|
def test_is_gpiochip_good_keyword_argument(self) -> None:
|
|
sim = gpiosim.Chip()
|
|
self.assertTrue(gpiod.is_gpiochip_device(path=sim.dev_path))
|
|
|
|
def test_is_gpiochip_link_good(self) -> None:
|
|
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 = f"/tmp/gpiod-py-test-link.{os.getpid()}"
|
|
|
|
with LinkGuard("/dev/null", link):
|
|
self.assertFalse(gpiod.is_gpiochip_device(link))
|
|
|
|
|
|
class VersionString(TestCase):
|
|
VERSION_PATTERN = "^\\d+\\.\\d+(\\.\\d+|\\-devel|\\-rc\\d+)?$"
|
|
|
|
def test_api_version_string(self) -> None:
|
|
self.assertRegex(gpiod.api_version, VersionString.VERSION_PATTERN)
|
|
|
|
def test_module_version(self) -> None:
|
|
self.assertRegex(gpiod.__version__, VersionString.VERSION_PATTERN)
|