From patchwork Fri Sep 27 18:53:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Fazio X-Patchwork-Id: 831082 Received: from mail.xes-mad.com (mail.xes-mad.com [162.248.234.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EF3E014AD25 for ; Fri, 27 Sep 2024 19:05:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=162.248.234.2 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727463907; cv=none; b=FhroWrLOo5joasFLvFXaA4ldTTOGNbRzMhKSEDvgJMbjGxosqzQMNYQMErrNkE7+KNp2gI7l0BZXjouUavURDQQAD7WZ2G/GsQEpk3OU3HU2Gq5OQmbrQzULH4lS5NSUoPpcH2fm5TKlklx7GXH3BMDVxAhzkxlWwJCPE2oJVZo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727463907; c=relaxed/simple; bh=IVRrzf2822jXGkzbisnDzJLeRRdoWwlHT9/l+efyS+w=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=amlG3+9PaOV6DjWCu3XRsTosfGBSCEyR0x2qE7cF0rR++wvvh9ye22nLlSwukt6Z5wz79qVFXdtmWxlZgV7o9c7aQ2yfxx5lWIYs1IbqzIp91Fsv2YTV72xeB+Y+gSDvb+e5AuUof4V7/J2r+P4tHdGJSFGIpla9NiWlRSO5Ank= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=xes-inc.com; spf=pass smtp.mailfrom=xes-inc.com; dkim=pass (1024-bit key) header.d=xes-inc.com header.i=@xes-inc.com header.b=NfCBKj/Y; arc=none smtp.client-ip=162.248.234.2 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=xes-inc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=xes-inc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=xes-inc.com header.i=@xes-inc.com header.b="NfCBKj/Y" Received: from vfazio4.xes-mad.com (vfazio4.xes-mad.com [10.52.19.201]) by mail.xes-mad.com (Postfix) with ESMTP id C9BC92035F; Fri, 27 Sep 2024 13:55:15 -0500 (CDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=xes-inc.com; s=mail; t=1727463315; bh=IVRrzf2822jXGkzbisnDzJLeRRdoWwlHT9/l+efyS+w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NfCBKj/YFrOj7lggtkcAXJLwAIaWPUuzv2dASCMqrhM+v/q03jzsPVqs7zEUg60Ve 58LlJcO49sBzBzPNWv4XToq+sWNKo73eo/9lbEqHrbOy9si2DY6x5Fk+9oFP+TWE7/ FPDa5Etzocj7xfNoPqNKMqJFcm1TpcFOehTtZZ2c= From: Vincent Fazio To: linux-gpio@vger.kernel.org Cc: vfazio@gmail.com, Vincent Fazio Subject: [libgpiod][PATCH 01/22] bindings: python: clean up imports and exports Date: Fri, 27 Sep 2024 13:53:37 -0500 Message-Id: <20240927-vfazio-mypy-v1-1-91a7c2e20884@xes-inc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240927-vfazio-mypy-v1-0-91a7c2e20884@xes-inc.com> References: <20240927-vfazio-mypy-v1-0-91a7c2e20884@xes-inc.com> Precedence: bulk X-Mailing-List: linux-gpio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Remove unused imports and sort the remainder following isort rules. Update submodules to use lists for `__all__` for ease of re-exporting public classes from within gpiod. Also, fix instances where `line` wasn't imported via a relative import. The library now consistently uses relative imports for submodules. Signed-off-by: Vincent Fazio --- bindings/python/gpiod/__init__.py | 66 +++++++++++++++++++++++++++++----- bindings/python/gpiod/chip.py | 15 ++++---- bindings/python/gpiod/chip_info.py | 2 +- bindings/python/gpiod/edge_event.py | 5 +-- bindings/python/gpiod/info_event.py | 7 ++-- bindings/python/gpiod/internal.py | 2 +- bindings/python/gpiod/line.py | 3 +- bindings/python/gpiod/line_info.py | 6 ++-- bindings/python/gpiod/line_request.py | 9 ++--- bindings/python/gpiod/line_settings.py | 7 ++-- 10 files changed, 87 insertions(+), 35 deletions(-) diff --git a/bindings/python/gpiod/__init__.py b/bindings/python/gpiod/__init__.py index 9cbb8dfb7b7b8aff4b2f6429fd831d582058c1b6..4d916f7f1a4eabd8ad1b2844262c20ed01a0798c 100644 --- a/bindings/python/gpiod/__init__.py +++ b/bindings/python/gpiod/__init__.py @@ -7,19 +7,67 @@ Python bindings for libgpiod. This module wraps the native C API of libgpiod in a set of python classes. """ -from . import _ext -from . import line -from .chip import Chip -from .chip_info import ChipInfo -from .edge_event import EdgeEvent -from .exception import ChipClosedError, RequestReleasedError -from .info_event import InfoEvent -from .line_request import LineRequest -from .line_settings import LineSettings +from . import ( + _ext, + chip, + chip_info, + edge_event, + exception, + info_event, + line, + line_info, + line_request, + line_settings, + version, +) +from .chip import * +from .chip_info import * +from .edge_event import * +from .exception import * +from .info_event import * +from .line import * +from .line_info import * +from .line_request import * +from .line_settings import * from .version import __version__ api_version = _ext.api_version +# public submodules +__all__ = [ + "chip", + "chip_info", + "edge_event", + "exception", + "info_event", + "line", + "line_info", + "line_request", + "line_settings", + "version", +] + +# re-export public submodule exports +__all__ += ( + chip.__all__ + + chip_info.__all__ + + edge_event.__all__ + + exception.__all__ + + info_event.__all__ + + line.__all__ + + line_info.__all__ + + line_request.__all__ + + line_settings.__all__ +) + +# module methods/attributes +__all__ += [ + "__version__", + "api_version", + "is_gpiochip_device", + "request_lines", +] + def is_gpiochip_device(path: str) -> bool: """ diff --git a/bindings/python/gpiod/chip.py b/bindings/python/gpiod/chip.py index 0a5ac6daac5e44499896958f3453845bf269af2e..257a31eba8d19634fd14e3b1d33a1345a0363946 100644 --- a/bindings/python/gpiod/chip.py +++ b/bindings/python/gpiod/chip.py @@ -1,6 +1,11 @@ # SPDX-License-Identifier: LGPL-2.1-or-later # SPDX-FileCopyrightText: 2022 Bartosz Golaszewski +from collections import Counter +from datetime import timedelta +from errno import ENOENT +from typing import Optional, Union + from . import _ext from .chip_info import ChipInfo from .exception import ChipClosedError @@ -8,16 +13,10 @@ from .info_event import InfoEvent from .internal import poll_fd from .line import Value from .line_info import LineInfo -from .line_settings import LineSettings, _line_settings_to_ext from .line_request import LineRequest -from collections import Counter -from collections.abc import Iterable -from datetime import timedelta -from errno import ENOENT -from select import select -from typing import Union, Optional +from .line_settings import LineSettings, _line_settings_to_ext -__all__ = "Chip" +__all__ = ["Chip"] class Chip: diff --git a/bindings/python/gpiod/chip_info.py b/bindings/python/gpiod/chip_info.py index 92b5e6f23c7117eaaa3e73ed27305116de7b0af2..884b910681abbc2069673669539d068a93f6aa72 100644 --- a/bindings/python/gpiod/chip_info.py +++ b/bindings/python/gpiod/chip_info.py @@ -4,7 +4,7 @@ from dataclasses import dataclass -__all__ = "ChipInfo" +__all__ = ["ChipInfo"] @dataclass(frozen=True, repr=False) diff --git a/bindings/python/gpiod/edge_event.py b/bindings/python/gpiod/edge_event.py index bf258c1472abc7b0faa40ed6533c68cefcd85b6b..a8b2378f9e3a9bdfabd8dde60d5c30fc73766f4c 100644 --- a/bindings/python/gpiod/edge_event.py +++ b/bindings/python/gpiod/edge_event.py @@ -1,11 +1,12 @@ # SPDX-License-Identifier: LGPL-2.1-or-later # SPDX-FileCopyrightText: 2022 Bartosz Golaszewski -from . import _ext from dataclasses import dataclass from enum import Enum -__all__ = "EdgeEvent" +from . import _ext + +__all__ = ["EdgeEvent"] @dataclass(frozen=True, init=False, repr=False) diff --git a/bindings/python/gpiod/info_event.py b/bindings/python/gpiod/info_event.py index 481eae6c376bc6cb418e03be84511b0de811ff91..7b544aa6436b34613a71ee06d9b675a63ad16989 100644 --- a/bindings/python/gpiod/info_event.py +++ b/bindings/python/gpiod/info_event.py @@ -1,12 +1,13 @@ # SPDX-License-Identifier: LGPL-2.1-or-later # SPDX-FileCopyrightText: 2022 Bartosz Golaszewski -from . import _ext -from .line_info import LineInfo from dataclasses import dataclass from enum import Enum -__all__ = "InfoEvent" +from . import _ext +from .line_info import LineInfo + +__all__ = ["InfoEvent"] @dataclass(frozen=True, init=False, repr=False) diff --git a/bindings/python/gpiod/internal.py b/bindings/python/gpiod/internal.py index 2dddb65027ab6a3f8b590a65050203d3189fb8c8..d1e95e4ade3146f596643d52207b367e332e6f7e 100644 --- a/bindings/python/gpiod/internal.py +++ b/bindings/python/gpiod/internal.py @@ -5,7 +5,7 @@ from datetime import timedelta from select import select from typing import Optional, Union -__all__ = [] +__all__ = ["poll_fd"] def poll_fd(fd: int, timeout: Optional[Union[timedelta, float]] = None) -> bool: diff --git a/bindings/python/gpiod/line.py b/bindings/python/gpiod/line.py index d088fb4631cc9f2bf102b6fe9a6ed5dad1eb4420..828385cbd84a95f207e808fe77022caad4056916 100644 --- a/bindings/python/gpiod/line.py +++ b/bindings/python/gpiod/line.py @@ -2,9 +2,10 @@ # SPDX-FileCopyrightText: 2022 Bartosz Golaszewski -from . import _ext from enum import Enum +from . import _ext + __all__ = ["Value", "Direction", "Bias", "Drive", "Edge", "Clock"] diff --git a/bindings/python/gpiod/line_info.py b/bindings/python/gpiod/line_info.py index c196a6aedeb48223ff5aec27b415c3ac690a84b1..46e16533802e9c8ff57a697e5b51b8b028d0c061 100644 --- a/bindings/python/gpiod/line_info.py +++ b/bindings/python/gpiod/line_info.py @@ -1,12 +1,12 @@ # SPDX-License-Identifier: LGPL-2.1-or-later # SPDX-FileCopyrightText: 2022 Bartosz Golaszewski -from . import _ext from dataclasses import dataclass from datetime import timedelta -from gpiod.line import Direction, Bias, Drive, Edge, Clock -__all__ = "LineInfo" +from .line import Bias, Clock, Direction, Drive, Edge + +__all__ = ["LineInfo"] @dataclass(frozen=True, init=False, repr=False) diff --git a/bindings/python/gpiod/line_request.py b/bindings/python/gpiod/line_request.py index 51e600a2ee5854f11f12d41ef561ec7bcdeb5908..e48830450dcb5b7fa6c7983a0fe074cd9bd32ab7 100644 --- a/bindings/python/gpiod/line_request.py +++ b/bindings/python/gpiod/line_request.py @@ -1,17 +1,18 @@ # SPDX-License-Identifier: LGPL-2.1-or-later # SPDX-FileCopyrightText: 2022 Bartosz Golaszewski +from collections.abc import Iterable +from datetime import timedelta +from typing import Optional, Union + from . import _ext from .edge_event import EdgeEvent from .exception import RequestReleasedError from .internal import poll_fd from .line import Value from .line_settings import LineSettings, _line_settings_to_ext -from collections.abc import Iterable -from datetime import timedelta -from typing import Optional, Union -__all__ = "LineRequest" +__all__ = ["LineRequest"] class LineRequest: diff --git a/bindings/python/gpiod/line_settings.py b/bindings/python/gpiod/line_settings.py index 5e3219438c2812c449d4da84a97ebc420f2b2352..f2811b288f4e832802217e9249a71a4db0eb1a2d 100644 --- a/bindings/python/gpiod/line_settings.py +++ b/bindings/python/gpiod/line_settings.py @@ -1,12 +1,13 @@ # SPDX-License-Identifier: LGPL-2.1-or-later # SPDX-FileCopyrightText: 2022 Bartosz Golaszewski -from . import _ext from dataclasses import dataclass from datetime import timedelta -from gpiod.line import Direction, Bias, Drive, Edge, Clock, Value -__all__ = "LineSettings" +from . import _ext +from .line import Bias, Clock, Direction, Drive, Edge, Value + +__all__ = ["LineSettings"] @dataclass(repr=False) From patchwork Fri Sep 27 18:53:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Fazio X-Patchwork-Id: 831081 Received: from mail.xes-mad.com (mail.xes-mad.com [162.248.234.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 16E9B1C1ABE for ; Fri, 27 Sep 2024 19:05:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=162.248.234.2 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727463907; cv=none; b=Gxl2vb4ZB76cia721kupJYgQV82WEUMCZpoUTTpba54njcv9libFmMOvZzIUHwuBTLusUpZ0ctM6efK0Iy3Qq1ukfwotMXRrruXicmq5K3xYjSzuWcZH1Qva6S1a2icL0okm7rcNKkiJyOGOUhc4RogiXpYfu2/zdKU251VwUko= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727463907; c=relaxed/simple; bh=FfZnDXVBsvrJ6TH9MDumMusb+f/puIGNBfj/R8tk5YA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=kIYBLLXF/aKrnFquxhsTn56YB/YKJi+FAz8z0SG/c1luOp7PBWJTK6dxDVwa0E4tC1X1I5wPOHbmF39sTGW7CsGLGPyruRwXdYr4+VIJX38H5dOp53Fd9wEOu8ZsOowCLNe/L0GHVukvtdosEyVqYkCndkpxYD7TbrgXcmb7NbU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=xes-inc.com; spf=pass smtp.mailfrom=xes-inc.com; dkim=pass (1024-bit key) header.d=xes-inc.com header.i=@xes-inc.com header.b=qrP7WfZc; arc=none smtp.client-ip=162.248.234.2 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=xes-inc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=xes-inc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=xes-inc.com header.i=@xes-inc.com header.b="qrP7WfZc" Received: from vfazio4.xes-mad.com (vfazio4.xes-mad.com [10.52.19.201]) by mail.xes-mad.com (Postfix) with ESMTP id E0999205B1; Fri, 27 Sep 2024 13:55:15 -0500 (CDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=xes-inc.com; s=mail; t=1727463315; bh=FfZnDXVBsvrJ6TH9MDumMusb+f/puIGNBfj/R8tk5YA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qrP7WfZcmSqEfX6QhDtVqY4/nRrQhqIaUsAOb5SPJKKUxe4StXBdEL2V2dkPUH4g5 24ex7NeyN8/Hn9c8vDiFsJRRNk/miv2xeNaoV0GpoaTddW2Z0CJzyu/nMj/O2ZsLyl qN5voZMHpwChm/Z4+kVDde77kLdEgK2zlc0qUmc0= From: Vincent Fazio To: linux-gpio@vger.kernel.org Cc: vfazio@gmail.com, Vincent Fazio Subject: [libgpiod][PATCH 02/22] bindings: python: make internal a private submodule Date: Fri, 27 Sep 2024 13:53:38 -0500 Message-Id: <20240927-vfazio-mypy-v1-2-91a7c2e20884@xes-inc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240927-vfazio-mypy-v1-0-91a7c2e20884@xes-inc.com> References: <20240927-vfazio-mypy-v1-0-91a7c2e20884@xes-inc.com> Precedence: bulk X-Mailing-List: linux-gpio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The internal submodule shouldn't be exposed as part of the public interface, so mark it private following PEP 8 convention [0]. Also, add a type annotation to `sec` for its possible types. [0]: https://peps.python.org/pep-0008/#public-and-internal-interfaces Signed-off-by: Vincent Fazio --- bindings/python/gpiod/{internal.py => _internal.py} | 1 + bindings/python/gpiod/chip.py | 2 +- bindings/python/gpiod/line_request.py | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/bindings/python/gpiod/internal.py b/bindings/python/gpiod/_internal.py similarity index 94% rename from bindings/python/gpiod/internal.py rename to bindings/python/gpiod/_internal.py index d1e95e4ade3146f596643d52207b367e332e6f7e..c9b5d2850389d5314a12bf6d151774a96469a085 100644 --- a/bindings/python/gpiod/internal.py +++ b/bindings/python/gpiod/_internal.py @@ -9,6 +9,7 @@ __all__ = ["poll_fd"] def poll_fd(fd: int, timeout: Optional[Union[timedelta, float]] = None) -> bool: + sec: Union[float, None] if isinstance(timeout, timedelta): sec = timeout.total_seconds() else: diff --git a/bindings/python/gpiod/chip.py b/bindings/python/gpiod/chip.py index 257a31eba8d19634fd14e3b1d33a1345a0363946..1a1bba4d6dd9e840a60394f1b74903f6ad15a0f4 100644 --- a/bindings/python/gpiod/chip.py +++ b/bindings/python/gpiod/chip.py @@ -7,10 +7,10 @@ from errno import ENOENT from typing import Optional, Union from . import _ext +from ._internal import poll_fd from .chip_info import ChipInfo from .exception import ChipClosedError from .info_event import InfoEvent -from .internal import poll_fd from .line import Value from .line_info import LineInfo from .line_request import LineRequest diff --git a/bindings/python/gpiod/line_request.py b/bindings/python/gpiod/line_request.py index e48830450dcb5b7fa6c7983a0fe074cd9bd32ab7..154174872e488fa478b27f5e83d65e6040aca367 100644 --- a/bindings/python/gpiod/line_request.py +++ b/bindings/python/gpiod/line_request.py @@ -6,9 +6,9 @@ from datetime import timedelta from typing import Optional, Union from . import _ext +from ._internal import poll_fd from .edge_event import EdgeEvent from .exception import RequestReleasedError -from .internal import poll_fd from .line import Value from .line_settings import LineSettings, _line_settings_to_ext From patchwork Fri Sep 27 18:53:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Fazio X-Patchwork-Id: 831091 Received: from mail.xes-mad.com (mail.xes-mad.com [162.248.234.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8F6271C2319 for ; Fri, 27 Sep 2024 18:55:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=162.248.234.2 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727463325; cv=none; b=cpI0tnZJ8H0+oqhMxpfYMoKlnOwMqzCDn33rhV+VH+NI6FbZOSmCkd1qNP4JSXvYpF+ldsJbaRQ4i6gJNXlmzQWeD5MB9ldy7/gn05N9UGfKAJI8MIoXJylWU6KkoUtcP0f/EbIcbfwbQfPAnONqB0HvIYkooJdlWfd9bXvfk14= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727463325; c=relaxed/simple; bh=O3ZjR7ttwV5/2sbRx1YUGWJch7qmeaRNCPEKg5o8Rhc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=leJegWAwJaCPJgbqToynaZSnj7YPiIP7ieGWTS11xQRXANoKuhtc9Bh5VexpxEjoDNMmVIxQWzSfMmb98GxfJWXCmj1SU2F9kA1CFAOZnI3ezAiTJqqBuQYHpaoKmSBvVtFrU71Vf/WlW+Ym+LKKxf5PsTK8u/8tSG4nrXT+Gxc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=xes-inc.com; spf=pass smtp.mailfrom=xes-inc.com; dkim=pass (1024-bit key) header.d=xes-inc.com header.i=@xes-inc.com header.b=Psp0+aJI; arc=none smtp.client-ip=162.248.234.2 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=xes-inc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=xes-inc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=xes-inc.com header.i=@xes-inc.com header.b="Psp0+aJI" Received: from vfazio4.xes-mad.com (vfazio4.xes-mad.com [10.52.19.201]) by mail.xes-mad.com (Postfix) with ESMTP id 4A38920BC7; Fri, 27 Sep 2024 13:55:16 -0500 (CDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=xes-inc.com; s=mail; t=1727463316; bh=O3ZjR7ttwV5/2sbRx1YUGWJch7qmeaRNCPEKg5o8Rhc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Psp0+aJIFE60MLC7WThoH0QaVgtdIGJ8fQHCJUWsS5Gosi66Rl6ppR7mg+yebcObX Lcx98PcZup0wargLMlSFJ4VolWB1QdjBrbnI/6EtT70dfT0XHZa3eA/APojF2HVM// BTtOCknVeCgrJ3UGo+tmBZl8IP+aLtrutFTsDvNI= From: Vincent Fazio To: linux-gpio@vger.kernel.org Cc: vfazio@gmail.com, Vincent Fazio Subject: [libgpiod][PATCH 06/22] bindings: python: annotate internal members of Chip Date: Fri, 27 Sep 2024 13:53:42 -0500 Message-Id: <20240927-vfazio-mypy-v1-6-91a7c2e20884@xes-inc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240927-vfazio-mypy-v1-0-91a7c2e20884@xes-inc.com> References: <20240927-vfazio-mypy-v1-0-91a7c2e20884@xes-inc.com> Precedence: bulk X-Mailing-List: linux-gpio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Signed-off-by: Vincent Fazio --- bindings/python/gpiod/chip.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bindings/python/gpiod/chip.py b/bindings/python/gpiod/chip.py index 75cc337e74bc965a30962b39a1584b13b4c4b067..4aa5677f94caf8c5d863aa6d75915a5b650de137 100644 --- a/bindings/python/gpiod/chip.py +++ b/bindings/python/gpiod/chip.py @@ -57,8 +57,8 @@ class Chip: path: Path to the GPIO character device file. """ - self._chip = _ext.Chip(path) - self._info = None + self._chip: Union[_ext.Chip, None] = _ext.Chip(path) + self._info: Union[ChipInfo, None] = None def __bool__(self) -> bool: """ From patchwork Fri Sep 27 18:53:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Fazio X-Patchwork-Id: 831089 Received: from mail.xes-mad.com (mail.xes-mad.com [162.248.234.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 632BF1C231D for ; Fri, 27 Sep 2024 18:55:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=162.248.234.2 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727463326; cv=none; b=f08lXMCn+MqNptQz79TuIwKPvIYRkgGW/2mpp5jrSrnqJoEzG3nZOud1tDhE+q9EEUDEouhr25NwbomeW9a9L9v+AI+4/LYfyTqXg8xvqmFim4XwSqoPps+fdxbGDSgtCzOBoXpIhR3XGCO6oFMbq7Rd6UpSqDcF1hBt7XhFIxs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727463326; c=relaxed/simple; bh=J3W1hAtg9Dc7a/iGdygy+aiySByFUWr4AHS855iWF6g=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=UzsE1n2cO42eqJEvZKmL2U7j1vFe5Urpy8IH4R8SismbYc0ikj7BnqvjmjPJamilJraxT84AgbJWbhGmgcw9eEvqxKS1/vGRVmGTRwEmgLHKkW+0qtN4kmunlbcotcN1uANyVV2q4RkiDM/lj78WDcwZlkTAsETrsoDG/KWVya0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=xes-inc.com; spf=pass smtp.mailfrom=xes-inc.com; dkim=pass (1024-bit key) header.d=xes-inc.com header.i=@xes-inc.com header.b=UVH03CDM; arc=none smtp.client-ip=162.248.234.2 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=xes-inc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=xes-inc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=xes-inc.com header.i=@xes-inc.com header.b="UVH03CDM" Received: from vfazio4.xes-mad.com (vfazio4.xes-mad.com [10.52.19.201]) by mail.xes-mad.com (Postfix) with ESMTP id 8DA5A20F65; Fri, 27 Sep 2024 13:55:16 -0500 (CDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=xes-inc.com; s=mail; t=1727463316; bh=J3W1hAtg9Dc7a/iGdygy+aiySByFUWr4AHS855iWF6g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UVH03CDMMNDVUMUn0r79AWsAMx69TauQJPpFugGowENLJX9L62TovrOrxpkgj1K+F jPg8/EMl2dDJZaym8hOEFbOHdoOrYveBcQIhfIUDtP9hzXlQTrjJXIyf1OrqBIZ7wy lSMm76cdboIKtBqj2ZjgS+TdLaC5rKiNx0JIqNA8= From: Vincent Fazio To: linux-gpio@vger.kernel.org Cc: vfazio@gmail.com, Vincent Fazio Subject: [libgpiod][PATCH 09/22] bindings: python: fix LineRequest union-attr type errors Date: Fri, 27 Sep 2024 13:53:45 -0500 Message-Id: <20240927-vfazio-mypy-v1-9-91a7c2e20884@xes-inc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240927-vfazio-mypy-v1-0-91a7c2e20884@xes-inc.com> References: <20240927-vfazio-mypy-v1-0-91a7c2e20884@xes-inc.com> Precedence: bulk X-Mailing-List: linux-gpio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Since `LineRequest._req` can be `None`, it's necessary to inform type checkers of the state of the object to silence the union-attr errors. Type checkers may not be able to infer that an object is not `None` from an earlier call (such as `_check_released`). Instead of littering the code with "# type: ignore" comments, use casts to inform type checkers that objects are not `None`. Using `assert` is another option, however this duplicates the logic in `_check_released` so is redundant at best and, at worst, is not a safe replacement as `assert` can be elided in optimized Python environments and these checks need to be runtime enforced. Also, convert singular ints or strs to a tuple instead of a list to keep with the inferred variable type of `lines`. Signed-off-by: Vincent Fazio --- bindings/python/gpiod/line_request.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/bindings/python/gpiod/line_request.py b/bindings/python/gpiod/line_request.py index 77d199ac64e9d3cc68d4a8b38dd0f571a24ab231..6c57f612a4167061945e798e93f069689723b583 100644 --- a/bindings/python/gpiod/line_request.py +++ b/bindings/python/gpiod/line_request.py @@ -6,7 +6,7 @@ from __future__ import annotations from collections.abc import Iterable from datetime import timedelta from types import TracebackType -from typing import Optional, Union +from typing import Optional, Union, cast from . import _ext from ._internal import poll_fd @@ -74,6 +74,7 @@ class LineRequest: not be used after a call to this method. """ self._check_released() + self._req = cast(_ext.Request, self._req) self._req.release() self._req = None @@ -114,6 +115,7 @@ class LineRequest: List of logical line values. """ self._check_released() + self._req = cast(_ext.Request, self._req) lines = lines or self._lines @@ -148,6 +150,7 @@ class LineRequest: Dictionary mapping line offsets or names to desired values. """ self._check_released() + self._req = cast(_ext.Request, self._req) mapped = { self._name_map[line] if self._check_line_name(line) else line: values[line] @@ -173,13 +176,14 @@ class LineRequest: Any settings for non-requested lines are ignored. """ self._check_released() + self._req = cast(_ext.Request, self._req) line_cfg = _ext.LineConfig() line_settings = {} for lines, settings in config.items(): if isinstance(lines, int) or isinstance(lines, str): - lines = [lines] + lines = (lines,) for line in lines: offset = self._name_map[line] if self._check_line_name(line) else line @@ -222,6 +226,7 @@ class LineRequest: List of read EdgeEvent objects. """ self._check_released() + self._req = cast(_ext.Request, self._req) return self._req.read_edge_events(max_events) @@ -275,4 +280,5 @@ class LineRequest: File descriptor associated with this request. """ self._check_released() + self._req = cast(_ext.Request, self._req) return self._req.fd From patchwork Fri Sep 27 18:53:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Fazio X-Patchwork-Id: 831090 Received: from mail.xes-mad.com (mail.xes-mad.com [162.248.234.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 631FD1C231C for ; Fri, 27 Sep 2024 18:55:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=162.248.234.2 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727463326; cv=none; b=K+/HVN/4WVUd7meRvffwuEQTGnwcpzMZiuJvFRk/5dHAoP4Lq0/x4njSk/4WX+iBK36w9C6Rw6C5u2sSQiNHcF2+fGmeeTU0GbDuW4Wiy7w5vemyncG6xWJ8W8yeNI4/7Gdg0oiAuxuQiaFa7zCyqH0Vo1o6FGzxthf9oYqU00o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727463326; c=relaxed/simple; bh=S1Dl+GO+xUhDktgHMVn5tY8vnX3u5nozztWw4LPzdaU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=aTtbqYK9JNtbcYb58+wRA5EiNjmxTuLroIcifPUTUOE3OFO8TzUpbFUwpx2LSC0EXdnhv9x6e7EfBvun3fKbnd/p1xqMaQI0EN+IlpZbk7T/gtfHsBykUPaeG1Ej+pyztDVzjfHx/GpJGjib0vmQX/NXQBDTbRvBsrcU4J7lVWs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=xes-inc.com; spf=pass smtp.mailfrom=xes-inc.com; dkim=pass (1024-bit key) header.d=xes-inc.com header.i=@xes-inc.com header.b=PiOBCKXn; arc=none smtp.client-ip=162.248.234.2 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=xes-inc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=xes-inc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=xes-inc.com header.i=@xes-inc.com header.b="PiOBCKXn" Received: from vfazio4.xes-mad.com (vfazio4.xes-mad.com [10.52.19.201]) by mail.xes-mad.com (Postfix) with ESMTP id A421321031; Fri, 27 Sep 2024 13:55:16 -0500 (CDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=xes-inc.com; s=mail; t=1727463316; bh=S1Dl+GO+xUhDktgHMVn5tY8vnX3u5nozztWw4LPzdaU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PiOBCKXnJnxXfj5P+Pp8Q8fJzcsnEiMIS72kmpYV2XN7ou3FKTpfMWJT5My6aOmZl rHWshd7gyYJqfHBaoqolj5bI37eKFREwwUqTVH8Qr58Eae94whti8Ox8Te5sTKTy47 cHFevsl+7ruO2jzNCUEHkWE0S/M0Tcby+AaMMV9U= From: Vincent Fazio To: linux-gpio@vger.kernel.org Cc: vfazio@gmail.com, Vincent Fazio Subject: [libgpiod][PATCH 10/22] bindings: python: convert lines to offsets in LineRequest Date: Fri, 27 Sep 2024 13:53:46 -0500 Message-Id: <20240927-vfazio-mypy-v1-10-91a7c2e20884@xes-inc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240927-vfazio-mypy-v1-0-91a7c2e20884@xes-inc.com> References: <20240927-vfazio-mypy-v1-0-91a7c2e20884@xes-inc.com> Precedence: bulk X-Mailing-List: linux-gpio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Remove `_check_line_name` in favor of a new function, `_line_to_offset`, that converts a line reference to an offset. This new function helps narrow types and simplifies the iteration logic that is used to build objects to interface with `_ext.Request`. Signed-off-by: Vincent Fazio --- bindings/python/gpiod/line_request.py | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/bindings/python/gpiod/line_request.py b/bindings/python/gpiod/line_request.py index 6c57f612a4167061945e798e93f069689723b583..a1ca64cfd82c32be5de3fc53f6c981026911bb9c 100644 --- a/bindings/python/gpiod/line_request.py +++ b/bindings/python/gpiod/line_request.py @@ -91,14 +91,15 @@ class LineRequest: """ return self.get_values([line])[0] - def _check_line_name(self, line: Union[int, str]) -> bool: - if isinstance(line, str): - if line not in self._name_map: - raise ValueError("unknown line name: {}".format(line)) - - return True - - return False + def _line_to_offset(self, line: Union[int, str]) -> int: + if isinstance(line, int): + return line + else: + _line: Union[int, None] + if (_line := self._name_map.get(line)) is None: + raise ValueError(f"unknown line name: {line}") + else: + return _line def get_values( self, lines: Optional[Iterable[Union[int, str]]] = None @@ -119,10 +120,7 @@ class LineRequest: lines = lines or self._lines - offsets = [ - self._name_map[line] if self._check_line_name(line) else line - for line in lines - ] + offsets = [self._line_to_offset(line) for line in lines] buf = [None] * len(lines) @@ -152,10 +150,7 @@ class LineRequest: self._check_released() self._req = cast(_ext.Request, self._req) - mapped = { - self._name_map[line] if self._check_line_name(line) else line: values[line] - for line in values - } + mapped = {self._line_to_offset(line): value for line, value in values.items()} self._req.set_values(mapped) @@ -186,7 +181,7 @@ class LineRequest: lines = (lines,) for line in lines: - offset = self._name_map[line] if self._check_line_name(line) else line + offset = self._line_to_offset(line) line_settings[offset] = settings for offset in self.offsets: From patchwork Fri Sep 27 18:53:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Fazio X-Patchwork-Id: 831087 Received: from mail.xes-mad.com (mail.xes-mad.com [162.248.234.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 62C531C2310 for ; Fri, 27 Sep 2024 18:55:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=162.248.234.2 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727463327; cv=none; b=RUcfO3D982BfaZ5CokY3lhuSuDWLcUZo/1luHvreiEYPhSIql4JJMiW5nU8g3YXGOk8pY6wdvwY3DQPtiG2gI9MOPw3k2/pyF9IIbNVeUYnNIMe0uokihUxE7JbH+MhH+xOOCihLMYkh+3LGWis2r/FWaNOsd0keT0HZeazgUD0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727463327; c=relaxed/simple; bh=veS+vSx+9jxGxIbmA2rImTAhiE2YTCqZ7MstOFZfE1Q=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=oIamO2JNx9soPhd4sqxVXahhcLunjoLjvC+ZCGN+n8TLZIkyX2LYU6V2ti9MDERyL2teGhGLWs5OvXWktiX5flSrlYu4BZllyAT95Ax1VcyI6flX3rx3fw8uEgw7HjyCj3+yxH3s9utB7xdyx96PX8Sp29S9nr/1z1aztofIs74= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=xes-inc.com; spf=pass smtp.mailfrom=xes-inc.com; dkim=pass (1024-bit key) header.d=xes-inc.com header.i=@xes-inc.com header.b=mYfr9I9u; arc=none smtp.client-ip=162.248.234.2 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=xes-inc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=xes-inc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=xes-inc.com header.i=@xes-inc.com header.b="mYfr9I9u" Received: from vfazio4.xes-mad.com (vfazio4.xes-mad.com [10.52.19.201]) by mail.xes-mad.com (Postfix) with ESMTP id B94B520FDF; Fri, 27 Sep 2024 13:55:16 -0500 (CDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=xes-inc.com; s=mail; t=1727463316; bh=veS+vSx+9jxGxIbmA2rImTAhiE2YTCqZ7MstOFZfE1Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mYfr9I9uVeYERaqjhh1L9XHGeazPWmr8AokTSIfal8uiaQ0szSTmz5La0K7HIdIz1 gJI/Jo0svoWtgPRZHh+u4USNWCEvuc2j1JDmGGIcID5RZt9GMzUczaPVhSD4Tfcucc FjMgOxIlyRPoiwP+P7/UfrgHzfh5HV+0DwOAQhAs= From: Vincent Fazio To: linux-gpio@vger.kernel.org Cc: vfazio@gmail.com, Vincent Fazio Subject: [libgpiod][PATCH 11/22] bindings: python: cast return value of LineRequest.get_values Date: Fri, 27 Sep 2024 13:53:47 -0500 Message-Id: <20240927-vfazio-mypy-v1-11-91a7c2e20884@xes-inc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240927-vfazio-mypy-v1-0-91a7c2e20884@xes-inc.com> References: <20240927-vfazio-mypy-v1-0-91a7c2e20884@xes-inc.com> Precedence: bulk X-Mailing-List: linux-gpio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The `values` argument of `_ext.Request.get_values` uses a preallocated `list[None]` as a buffer that is populated with `Value`s by the external module that are then returned from the function. Use `cast` to inform the type checker it's a `list[Value]` despite how it's allocated. Also, as `lines` is typed as an `Iterable`, there is no guarantee it has a `__len__` method. Instead, use the size of the `offsets` array to allocate the buffer. Signed-off-by: Vincent Fazio --- bindings/python/gpiod/line_request.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bindings/python/gpiod/line_request.py b/bindings/python/gpiod/line_request.py index a1ca64cfd82c32be5de3fc53f6c981026911bb9c..917020b9ec7046dd8e10158f70efb555fc87eade 100644 --- a/bindings/python/gpiod/line_request.py +++ b/bindings/python/gpiod/line_request.py @@ -122,7 +122,7 @@ class LineRequest: offsets = [self._line_to_offset(line) for line in lines] - buf = [None] * len(lines) + buf = cast(list[Value], [None] * len(offsets)) self._req.get_values(offsets, buf) return buf From patchwork Fri Sep 27 18:53:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Fazio X-Patchwork-Id: 831088 Received: from mail.xes-mad.com (mail.xes-mad.com [162.248.234.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 635631C231F for ; Fri, 27 Sep 2024 18:55:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=162.248.234.2 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727463326; cv=none; b=jD0N3A22xGwiSgGh+2vHPERXCbLm4j6yuTHkmx0BJiHzX4p5sk5dqKQUmZZLVQFOIyJgjMG80wbjOhcq6j7jVFVeBEN46Tu0uvn1a8jfKxM5FaouNaQKtwBofCUob38yNRRt7VBnqkUqQWguMPDdOUbsoLPRY7ylSLYW3g3FqMU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727463326; c=relaxed/simple; bh=Y+KPrfKo1o4gx2Bz92oyLWusiIsQp5VKNt2PBjv6AnU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=ns71wnhcFY4ZkRzgz7ZgpZTZ1BlR6El/L5il8tMbEO4gcOs8mJk7etXaxtvUXcZAR6SSoxiPQ7G+16JqeWfccYFHgVjF5vFP8rggT51swuHXzTBFGih3SOdQBLpy55oAWekkbWtwqkVl04lFPX8Lme6eJui6cQLRyqGFZ/Bqpns= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=xes-inc.com; spf=pass smtp.mailfrom=xes-inc.com; dkim=pass (1024-bit key) header.d=xes-inc.com header.i=@xes-inc.com header.b=VriC60Zc; arc=none smtp.client-ip=162.248.234.2 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=xes-inc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=xes-inc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=xes-inc.com header.i=@xes-inc.com header.b="VriC60Zc" Received: from vfazio4.xes-mad.com (vfazio4.xes-mad.com [10.52.19.201]) by mail.xes-mad.com (Postfix) with ESMTP id E4344211EA; Fri, 27 Sep 2024 13:55:16 -0500 (CDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=xes-inc.com; s=mail; t=1727463316; bh=Y+KPrfKo1o4gx2Bz92oyLWusiIsQp5VKNt2PBjv6AnU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VriC60ZcHo6l0L4r5nmt4/qldvqzwAdvOPFK86sCBMfsJm1DUNJsm7r5j485p+pWp 6e8z7e6Ap8oMAZnBBrO6xEq2Q/HBQNwuT9UjPRH7ZDuCU8BYkoQuoAW/XwQaGgfs3x Ao7U+KzA4EEDqv9Dk3PkVgSgJCjVlOHVsUvdyNv4= From: Vincent Fazio To: linux-gpio@vger.kernel.org Cc: vfazio@gmail.com, Vincent Fazio Subject: [libgpiod][PATCH 13/22] bindings: python: selectively use f-strings Date: Fri, 27 Sep 2024 13:53:49 -0500 Message-Id: <20240927-vfazio-mypy-v1-13-91a7c2e20884@xes-inc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240927-vfazio-mypy-v1-0-91a7c2e20884@xes-inc.com> References: <20240927-vfazio-mypy-v1-0-91a7c2e20884@xes-inc.com> Precedence: bulk X-Mailing-List: linux-gpio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Dataclasses are not migrated to f-strings so readability isn't impacted. Signed-off-by: Vincent Fazio --- bindings/python/gpiod/chip.py | 8 +++----- bindings/python/gpiod/chip_info.py | 2 +- bindings/python/gpiod/edge_event.py | 2 +- bindings/python/gpiod/info_event.py | 2 +- bindings/python/gpiod/line_info.py | 2 +- bindings/python/gpiod/line_request.py | 2 +- bindings/python/gpiod/line_settings.py | 4 ++-- 7 files changed, 10 insertions(+), 12 deletions(-) diff --git a/bindings/python/gpiod/chip.py b/bindings/python/gpiod/chip.py index 27785d63806619ff70e7c75f7dd102894d3a4ec1..e2a82203501160cf63d86a7c8c3e2d92469e2fb9 100644 --- a/bindings/python/gpiod/chip.py +++ b/bindings/python/gpiod/chip.py @@ -281,9 +281,7 @@ class Chip: ).items(): if count != 1: raise ValueError( - "line must be configured exactly once - offset {} repeats".format( - offset - ) + f"line must be configured exactly once - offset {offset} repeats" ) # If we have global output values - map line names to offsets @@ -350,7 +348,7 @@ class Chip: if not self._chip: return "" - return 'gpiod.Chip("{}")'.format(self.path) + return f'gpiod.Chip("{self.path}")' def __str__(self) -> str: """ @@ -359,7 +357,7 @@ class Chip: if not self._chip: return "" - return ''.format( + return ''.format( # noqa: UP032 self.path, self.fd, self.get_info() ) diff --git a/bindings/python/gpiod/chip_info.py b/bindings/python/gpiod/chip_info.py index eb585d6d7efa26492163dc0a731ba263d0232099..27c28131ad4f883f3712e4201a0c325274f5fefc 100644 --- a/bindings/python/gpiod/chip_info.py +++ b/bindings/python/gpiod/chip_info.py @@ -18,6 +18,6 @@ class ChipInfo: num_lines: int def __str__(self) -> str: - return ''.format( + return ''.format( # noqa: UP032 self.name, self.label, self.num_lines ) diff --git a/bindings/python/gpiod/edge_event.py b/bindings/python/gpiod/edge_event.py index 0d401d896a79dc5204e7ea86f202e37acbd24758..7f5cd4d345785ceb549e2888629898818a4ab293 100644 --- a/bindings/python/gpiod/edge_event.py +++ b/bindings/python/gpiod/edge_event.py @@ -40,7 +40,7 @@ class EdgeEvent: object.__setattr__(self, "line_seqno", line_seqno) def __str__(self) -> str: - return "".format( + return "".format( # noqa: UP032 self.event_type, self.timestamp_ns, self.line_offset, diff --git a/bindings/python/gpiod/info_event.py b/bindings/python/gpiod/info_event.py index d9e9564e21338cd8d1e28c567fa2ed2ac29ceb00..ed531f2c3ab36e3c146c87bfdbabd3f95ab8b643 100644 --- a/bindings/python/gpiod/info_event.py +++ b/bindings/python/gpiod/info_event.py @@ -31,6 +31,6 @@ class InfoEvent: object.__setattr__(self, "line_info", line_info) def __str__(self) -> str: - return "".format( + return "".format( # noqa: UP032 self.event_type, self.timestamp_ns, self.line_info ) diff --git a/bindings/python/gpiod/line_info.py b/bindings/python/gpiod/line_info.py index 5ea9568fd5c963c77f53c56ef748ac1e80872ed9..1aca142387992d2d836fb2b5672f0b45249691af 100644 --- a/bindings/python/gpiod/line_info.py +++ b/bindings/python/gpiod/line_info.py @@ -59,7 +59,7 @@ class LineInfo: ) def __str__(self) -> str: - return ''.format( + return ''.format( # noqa: UP032 self.offset, self.name, self.used, diff --git a/bindings/python/gpiod/line_request.py b/bindings/python/gpiod/line_request.py index a9b5105e5cc5bc5f857300ba3e0eb7528ed6ae80..dcb711095a39002be650aaaf6f158807c37f27e1 100644 --- a/bindings/python/gpiod/line_request.py +++ b/bindings/python/gpiod/line_request.py @@ -232,7 +232,7 @@ class LineRequest: if not self._req: return "" - return ''.format( + return ''.format( # noqa: UP032 self.chip_name, self.num_lines, self.offsets, self.fd ) diff --git a/bindings/python/gpiod/line_settings.py b/bindings/python/gpiod/line_settings.py index 6c6518dbc958423393790a39d69e94802eda8547..2aca71c9c5cd02d1add663f5d430dcf0153706b9 100644 --- a/bindings/python/gpiod/line_settings.py +++ b/bindings/python/gpiod/line_settings.py @@ -28,7 +28,7 @@ class LineSettings: # __repr__ generated by @dataclass uses repr for enum members resulting in # an unusable representation as those are of the form: def __repr__(self) -> str: - return "gpiod.LineSettings(direction=gpiod.line.{}, edge_detection=gpiod.line.{}, bias=gpiod.line.{}, drive=gpiod.line.{}, active_low={}, debounce_period={}, event_clock=gpiod.line.{}, output_value=gpiod.line.{})".format( + return "gpiod.LineSettings(direction=gpiod.line.{}, edge_detection=gpiod.line.{}, bias=gpiod.line.{}, drive=gpiod.line.{}, active_low={}, debounce_period={}, event_clock=gpiod.line.{}, output_value=gpiod.line.{})".format( # noqa: UP032 str(self.direction), str(self.edge_detection), str(self.bias), @@ -40,7 +40,7 @@ class LineSettings: ) def __str__(self) -> str: - return "".format( + return "".format( # noqa: UP032 self.direction, self.edge_detection, self.bias, From patchwork Fri Sep 27 18:53:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Fazio X-Patchwork-Id: 831086 Received: from mail.xes-mad.com (mail.xes-mad.com [162.248.234.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 624881C233F for ; Fri, 27 Sep 2024 18:55:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=162.248.234.2 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727463329; cv=none; b=uTADHHhktH+JXis5Q1RzZjWybYQoCIg8+8SywnWfLo2rYSHjQxAiGVqoF6h+vMMajB5CS79kfM4kBFC2epHMkwRkneZDd8+IVuzS3ipwXOZdnCM5xIxtdNQvcIPGka8PxdpwAVy0vCbmW+s4MvhwgIyEA7HcDs8pDS+pdOFQoX0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727463329; c=relaxed/simple; bh=g3Y99R0h2yatq0LeTDa8NE58aE8IF1GFOfiF5D6xGBM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=MbIis5sAfrc7wBZPKQ16g0kcAjL82CqsUfoNk5DenR0H3Sa2xXAFn+og0zHJ+TZeN3yqs/picPqMTkgZc4eRxFd9PrtnXxNWqDNAGuqNfKSTWGLVaxIUw3UuYqy+X0dukCwXoTuUHWXZ7cgdG6CV1JCIN57qhapkkBllcB6vJ5I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=xes-inc.com; spf=pass smtp.mailfrom=xes-inc.com; dkim=pass (1024-bit key) header.d=xes-inc.com header.i=@xes-inc.com header.b=CEQrtyMk; arc=none smtp.client-ip=162.248.234.2 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=xes-inc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=xes-inc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=xes-inc.com header.i=@xes-inc.com header.b="CEQrtyMk" Received: from vfazio4.xes-mad.com (vfazio4.xes-mad.com [10.52.19.201]) by mail.xes-mad.com (Postfix) with ESMTP id 34D4D2183A; Fri, 27 Sep 2024 13:55:17 -0500 (CDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=xes-inc.com; s=mail; t=1727463317; bh=g3Y99R0h2yatq0LeTDa8NE58aE8IF1GFOfiF5D6xGBM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CEQrtyMkEg8QJ9AlrLPtPE69xq9vPWWbk93LiY0Rgl2mMsO7VRlbQ2VyfrlOjZeOG H+Hz3L78jnFdc4a5LdiODc+khS3FgS2qyuvm1NoGWulVVKPojRH3EZ3M86ZHeXSp6N PvFnyLQ3tZgBzqrW6tuxK/bosHVaFhTbfRRYarbQ= From: Vincent Fazio To: linux-gpio@vger.kernel.org Cc: vfazio@gmail.com, Vincent Fazio Subject: [libgpiod][PATCH 16/22] bindings: python: tests: make EventType private to prevent export Date: Fri, 27 Sep 2024 13:53:52 -0500 Message-Id: <20240927-vfazio-mypy-v1-16-91a7c2e20884@xes-inc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240927-vfazio-mypy-v1-0-91a7c2e20884@xes-inc.com> References: <20240927-vfazio-mypy-v1-0-91a7c2e20884@xes-inc.com> Precedence: bulk X-Mailing-List: linux-gpio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Signed-off-by: Vincent Fazio --- bindings/python/tests/tests_edge_event.py | 14 +++++++------- bindings/python/tests/tests_info_event.py | 10 +++++----- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/bindings/python/tests/tests_edge_event.py b/bindings/python/tests/tests_edge_event.py index 7e7fada38cf2a983172aaa9c8400fbfe0d3b7a7d..c24d344fdbd6a1b9eda9497afab8a61c5ecb8f09 100644 --- a/bindings/python/tests/tests_edge_event.py +++ b/bindings/python/tests/tests_edge_event.py @@ -12,7 +12,7 @@ from gpiod.line import Direction, Edge from . import gpiosim -EventType = gpiod.EdgeEvent.Type +_EventType = gpiod.EdgeEvent.Type Pull = gpiosim.Chip.Pull @@ -87,7 +87,7 @@ class WaitingForEdgeEvents(TestCase): events = req.read_edge_events() self.assertEqual(len(events), 1) event = events[0] - self.assertEqual(event.event_type, EventType.RISING_EDGE) + self.assertEqual(event.event_type, _EventType.RISING_EDGE) self.assertEqual(event.line_offset, 2) ts_rising = event.timestamp_ns @@ -95,7 +95,7 @@ class WaitingForEdgeEvents(TestCase): events = req.read_edge_events() self.assertEqual(len(events), 1) event = events[0] - self.assertEqual(event.event_type, EventType.FALLING_EDGE) + self.assertEqual(event.event_type, _EventType.FALLING_EDGE) self.assertEqual(event.line_offset, 2) ts_falling = event.timestamp_ns @@ -114,7 +114,7 @@ class WaitingForEdgeEvents(TestCase): events = req.read_edge_events() self.assertEqual(len(events), 1) event = events[0] - self.assertEqual(event.event_type, EventType.RISING_EDGE) + self.assertEqual(event.event_type, _EventType.RISING_EDGE) self.assertEqual(event.line_offset, 6) self.assertFalse(req.wait_edge_events(timedelta(microseconds=10000))) @@ -132,7 +132,7 @@ class WaitingForEdgeEvents(TestCase): events = req.read_edge_events() self.assertEqual(len(events), 1) event = events[0] - self.assertEqual(event.event_type, EventType.FALLING_EDGE) + self.assertEqual(event.event_type, _EventType.FALLING_EDGE) self.assertEqual(event.line_offset, 6) self.assertFalse(req.wait_edge_events(timedelta(microseconds=10000))) @@ -150,7 +150,7 @@ class WaitingForEdgeEvents(TestCase): events = req.read_edge_events() self.assertEqual(len(events), 1) event = events[0] - self.assertEqual(event.event_type, EventType.RISING_EDGE) + self.assertEqual(event.event_type, _EventType.RISING_EDGE) self.assertEqual(event.line_offset, 2) self.assertEqual(event.global_seqno, 1) self.assertEqual(event.line_seqno, 1) @@ -159,7 +159,7 @@ class WaitingForEdgeEvents(TestCase): events = req.read_edge_events() self.assertEqual(len(events), 1) event = events[0] - self.assertEqual(event.event_type, EventType.RISING_EDGE) + self.assertEqual(event.event_type, _EventType.RISING_EDGE) self.assertEqual(event.line_offset, 4) self.assertEqual(event.global_seqno, 2) self.assertEqual(event.line_seqno, 1) diff --git a/bindings/python/tests/tests_info_event.py b/bindings/python/tests/tests_info_event.py index bbdbc0fa6e69c59a32d67d00f5e785105c90e840..1976f4be8b9a63942275875ada00472402524350 100644 --- a/bindings/python/tests/tests_info_event.py +++ b/bindings/python/tests/tests_info_event.py @@ -14,7 +14,7 @@ from gpiod.line import Direction from . import gpiosim -EventType = gpiod.InfoEvent.Type +_EventType = gpiod.InfoEvent.Type class InfoEventDataclassBehavior(TestCase): @@ -101,7 +101,7 @@ class WatchingInfoEventWorks(TestCase): self.assertTrue(self.chip.wait_info_event(datetime.timedelta(seconds=1))) event = self.chip.read_info_event() - self.assertEqual(event.event_type, EventType.LINE_REQUESTED) + self.assertEqual(event.event_type, _EventType.LINE_REQUESTED) self.assertEqual(event.line_info.offset, 7) self.assertEqual(event.line_info.direction, Direction.INPUT) ts_req = event.timestamp_ns @@ -109,14 +109,14 @@ class WatchingInfoEventWorks(TestCase): # Check that we can use a float directly instead of datetime.timedelta. self.assertTrue(self.chip.wait_info_event(1.0)) event = self.chip.read_info_event() - self.assertEqual(event.event_type, EventType.LINE_CONFIG_CHANGED) + self.assertEqual(event.event_type, _EventType.LINE_CONFIG_CHANGED) self.assertEqual(event.line_info.offset, 7) self.assertEqual(event.line_info.direction, Direction.OUTPUT) ts_rec = event.timestamp_ns self.assertTrue(self.chip.wait_info_event(datetime.timedelta(seconds=1))) event = self.chip.read_info_event() - self.assertEqual(event.event_type, EventType.LINE_RELEASED) + self.assertEqual(event.event_type, _EventType.LINE_RELEASED) self.assertEqual(event.line_info.offset, 7) self.assertEqual(event.line_info.direction, Direction.OUTPUT) ts_rel = event.timestamp_ns @@ -146,7 +146,7 @@ class UnwatchingLineInfo(TestCase): with self.chip.request_lines(config={0: None}) as request: self.assertTrue(self.chip.wait_info_event(datetime.timedelta(seconds=1))) event = self.chip.read_info_event() - self.assertEqual(event.event_type, EventType.LINE_REQUESTED) + self.assertEqual(event.event_type, _EventType.LINE_REQUESTED) self.chip.unwatch_line_info(0) self.assertFalse( From patchwork Fri Sep 27 18:53:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Fazio X-Patchwork-Id: 831083 Received: from mail.xes-mad.com (mail.xes-mad.com [162.248.234.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 06D8B1C2334 for ; Fri, 27 Sep 2024 18:55:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=162.248.234.2 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727463330; cv=none; b=G+g/NyEShE7xB/PF/RcVIcqV2/ykZFZFhnTYZXHHVSnH2hX++1vcYdPVmuyeAaDPIYj3ZpUovYZdoozskjF3EDVoEEsi0vN5OCPdEVs50KGv9ff1jO7FQZGEB/FOmL7ReMixgpfAcih+U3UK90UL0aGIVtr1BQ0WPGGySn3bCH4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727463330; c=relaxed/simple; bh=aSszVcfUJj6n4Uv8AOTiUu0H4P7wId2QipliR/huIUI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=mmeSIFXLvnm9oavx1iNiNnRXXRh92yA3ZjnG8P3NeWQObxPeT7hSFVFzks70OnYH0u89yKXbWPn8ywSEZJVvW7glEOtoL7DjBI7ghU7gpAqmdruV3Th9vkwjBOWoMuND0EJaFyPqYTDecDKkE5+DSX0sqxsQxguFjbync0b6Y48= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=xes-inc.com; spf=pass smtp.mailfrom=xes-inc.com; dkim=pass (1024-bit key) header.d=xes-inc.com header.i=@xes-inc.com header.b=hB7xWJKA; arc=none smtp.client-ip=162.248.234.2 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=xes-inc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=xes-inc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=xes-inc.com header.i=@xes-inc.com header.b="hB7xWJKA" Received: from vfazio4.xes-mad.com (vfazio4.xes-mad.com [10.52.19.201]) by mail.xes-mad.com (Postfix) with ESMTP id 60E2621CCE; Fri, 27 Sep 2024 13:55:17 -0500 (CDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=xes-inc.com; s=mail; t=1727463317; bh=aSszVcfUJj6n4Uv8AOTiUu0H4P7wId2QipliR/huIUI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hB7xWJKAZTGft4Nbbia42y7U8QlSyrHMiNech+0um4hbLwwLfmIqOZwqcONrRKX+g 6/jhIjz0QvktTQE9Ny7rmrHYh+7h5XD8o+vLSNTaEvAMHjaf9A2N2jKOi0oPq5COhU ILr2yw9b98xua06fM7ZxmvzLx1HuVAAL/SSNmxP0= From: Vincent Fazio To: linux-gpio@vger.kernel.org Cc: vfazio@gmail.com, Vincent Fazio Subject: [libgpiod][PATCH 18/22] bindings: python: tests: add missing type annotations Date: Fri, 27 Sep 2024 13:53:54 -0500 Message-Id: <20240927-vfazio-mypy-v1-18-91a7c2e20884@xes-inc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240927-vfazio-mypy-v1-0-91a7c2e20884@xes-inc.com> References: <20240927-vfazio-mypy-v1-0-91a7c2e20884@xes-inc.com> Precedence: bulk X-Mailing-List: linux-gpio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Signed-off-by: Vincent Fazio --- bindings/python/tests/helpers.py | 6 +- bindings/python/tests/tests_chip.py | 68 +++++----- bindings/python/tests/tests_chip_info.py | 14 +- bindings/python/tests/tests_edge_event.py | 32 ++--- bindings/python/tests/tests_info_event.py | 38 +++--- bindings/python/tests/tests_line.py | 2 +- bindings/python/tests/tests_line_info.py | 22 ++-- bindings/python/tests/tests_line_request.py | 184 +++++++++++++-------------- bindings/python/tests/tests_line_settings.py | 12 +- bindings/python/tests/tests_module.py | 20 +-- 10 files changed, 200 insertions(+), 198 deletions(-) diff --git a/bindings/python/tests/helpers.py b/bindings/python/tests/helpers.py index f9a15e8e33f62ad63923bddedc206022eabe96b4..d327da2816594655cec5a76e024e31ff978d5d93 100644 --- a/bindings/python/tests/helpers.py +++ b/bindings/python/tests/helpers.py @@ -5,12 +5,12 @@ import os class LinkGuard: - def __init__(self, src, dst): + def __init__(self, src: str, dst: str) -> None: self.src = src self.dst = dst - def __enter__(self): + def __enter__(self) -> None: os.symlink(self.src, self.dst) - def __exit__(self, type, val, tb): + def __exit__(self, type, val, tb) -> None: # type: ignore[no-untyped-def] os.unlink(self.dst) diff --git a/bindings/python/tests/tests_chip.py b/bindings/python/tests/tests_chip.py index 9110bebf3596557fbacb3c7620e931982f9dc957..9c8f87579469e684ed3b6a5dbcef35e0856127ba 100644 --- a/bindings/python/tests/tests_chip.py +++ b/bindings/python/tests/tests_chip.py @@ -12,19 +12,19 @@ from .helpers import LinkGuard class ChipConstructor(TestCase): - def test_open_existing_chip(self): + def test_open_existing_chip(self) -> None: sim = gpiosim.Chip() with gpiod.Chip(sim.dev_path): pass - def test_open_existing_chip_with_keyword(self): + def test_open_existing_chip_with_keyword(self) -> None: sim = gpiosim.Chip() with gpiod.Chip(path=sim.dev_path): pass - def test_open_chip_by_link(self): + def test_open_chip_by_link(self) -> None: link = "/tmp/gpiod-py-test-link.{}".format(os.getpid()) sim = gpiosim.Chip() @@ -32,35 +32,35 @@ class ChipConstructor(TestCase): with gpiod.Chip(link): pass - def test_open_nonexistent_chip(self): + def test_open_nonexistent_chip(self) -> None: with self.assertRaises(OSError) as ex: gpiod.Chip("/dev/nonexistent") self.assertEqual(ex.exception.errno, errno.ENOENT) - def test_open_not_a_character_device(self): + def test_open_not_a_character_device(self) -> None: with self.assertRaises(OSError) as ex: gpiod.Chip("/tmp") self.assertEqual(ex.exception.errno, errno.ENOTTY) - def test_open_not_a_gpio_device(self): + def test_open_not_a_gpio_device(self) -> None: with self.assertRaises(OSError) as ex: gpiod.Chip("/dev/null") self.assertEqual(ex.exception.errno, errno.ENODEV) - def test_missing_path(self): + def test_missing_path(self) -> None: with self.assertRaises(TypeError): gpiod.Chip() - def test_invalid_type_for_path(self): + def test_invalid_type_for_path(self) -> None: with self.assertRaises(TypeError): gpiod.Chip(4) class ChipBooleanConversion(TestCase): - def test_chip_bool(self): + def test_chip_bool(self) -> None: sim = gpiosim.Chip() chip = gpiod.Chip(sim.dev_path) self.assertTrue(chip) @@ -69,21 +69,21 @@ class ChipBooleanConversion(TestCase): class ChipProperties(TestCase): - def setUp(self): + def setUp(self) -> None: self.sim = gpiosim.Chip() self.chip = gpiod.Chip(self.sim.dev_path) - def tearDown(self): + def tearDown(self) -> None: self.chip.close() self.sim = None - def test_get_chip_path(self): + def test_get_chip_path(self) -> None: self.assertEqual(self.sim.dev_path, self.chip.path) - def test_get_fd(self): + def test_get_fd(self) -> None: self.assertGreaterEqual(self.chip.fd, 0) - def test_properties_are_immutable(self): + def test_properties_are_immutable(self) -> None: with self.assertRaises(AttributeError): self.chip.path = "foobar" @@ -92,7 +92,7 @@ class ChipProperties(TestCase): class ChipDevPathFromLink(TestCase): - def test_dev_path_open_by_link(self): + def test_dev_path_open_by_link(self) -> None: sim = gpiosim.Chip() link = "/tmp/gpiod-py-test-link.{}".format(os.getpid()) @@ -102,7 +102,7 @@ class ChipDevPathFromLink(TestCase): class ChipMapLine(TestCase): - def test_lookup_by_name_good(self): + def test_lookup_by_name_good(self) -> None: sim = gpiosim.Chip( num_lines=8, line_names={1: "foo", 2: "bar", 4: "baz", 5: "xyz"} ) @@ -110,7 +110,7 @@ class ChipMapLine(TestCase): with gpiod.Chip(sim.dev_path) as chip: self.assertEqual(chip.line_offset_from_id("baz"), 4) - def test_lookup_by_name_good_keyword_argument(self): + def test_lookup_by_name_good_keyword_argument(self) -> None: sim = gpiosim.Chip( num_lines=8, line_names={1: "foo", 2: "bar", 4: "baz", 5: "xyz"} ) @@ -118,7 +118,7 @@ class ChipMapLine(TestCase): with gpiod.Chip(sim.dev_path) as chip: self.assertEqual(chip.line_offset_from_id(id="baz"), 4) - def test_lookup_bad_name(self): + def test_lookup_bad_name(self) -> None: sim = gpiosim.Chip( num_lines=8, line_names={1: "foo", 2: "bar", 4: "baz", 5: "xyz"} ) @@ -127,21 +127,21 @@ class ChipMapLine(TestCase): with self.assertRaises(FileNotFoundError): chip.line_offset_from_id("nonexistent") - def test_lookup_bad_offset(self): + def test_lookup_bad_offset(self) -> None: sim = gpiosim.Chip() with gpiod.Chip(sim.dev_path) as chip: with self.assertRaises(ValueError): chip.line_offset_from_id(4) - def test_lookup_bad_offset_as_string(self): + def test_lookup_bad_offset_as_string(self) -> None: sim = gpiosim.Chip() with gpiod.Chip(sim.dev_path) as chip: with self.assertRaises(ValueError): chip.line_offset_from_id("4") - def test_duplicate_names(self): + def test_duplicate_names(self) -> None: sim = gpiosim.Chip( num_lines=8, line_names={1: "foo", 2: "bar", 4: "baz", 5: "bar"} ) @@ -149,14 +149,14 @@ class ChipMapLine(TestCase): with gpiod.Chip(sim.dev_path) as chip: self.assertEqual(chip.line_offset_from_id("bar"), 2) - def test_integer_offsets(self): + def test_integer_offsets(self) -> None: sim = gpiosim.Chip(num_lines=8, line_names={1: "foo", 2: "bar", 6: "baz"}) with gpiod.Chip(sim.dev_path) as chip: self.assertEqual(chip.line_offset_from_id(4), 4) self.assertEqual(chip.line_offset_from_id(1), 1) - def test_offsets_as_string(self): + def test_offsets_as_string(self) -> None: sim = gpiosim.Chip(num_lines=8, line_names={1: "foo", 2: "bar", 7: "6"}) with gpiod.Chip(sim.dev_path) as chip: @@ -165,7 +165,7 @@ class ChipMapLine(TestCase): class ClosedChipCannotBeUsed(TestCase): - def test_close_chip_and_try_to_use_it(self): + def test_close_chip_and_try_to_use_it(self) -> None: sim = gpiosim.Chip(label="foobar") chip = gpiod.Chip(sim.dev_path) @@ -174,7 +174,7 @@ class ClosedChipCannotBeUsed(TestCase): with self.assertRaises(gpiod.ChipClosedError): chip.path - def test_close_chip_and_try_controlled_execution(self): + def test_close_chip_and_try_controlled_execution(self) -> None: sim = gpiosim.Chip() chip = gpiod.Chip(sim.dev_path) @@ -184,7 +184,7 @@ class ClosedChipCannotBeUsed(TestCase): with chip: chip.fd - def test_close_chip_twice(self): + def test_close_chip_twice(self) -> None: sim = gpiosim.Chip(label="foobar") chip = gpiod.Chip(sim.dev_path) chip.close() @@ -194,21 +194,21 @@ class ClosedChipCannotBeUsed(TestCase): class StringRepresentation(TestCase): - def setUp(self): + def setUp(self) -> None: self.sim = gpiosim.Chip(num_lines=4, label="foobar") self.chip = gpiod.Chip(self.sim.dev_path) - def tearDown(self): + def tearDown(self) -> None: self.chip.close() self.sim = None - def test_repr(self): + def test_repr(self) -> None: self.assertEqual(repr(self.chip), 'gpiod.Chip("{}")'.format(self.sim.dev_path)) cmp = eval(repr(self.chip)) self.assertEqual(self.chip.path, cmp.path) - def test_str(self): + def test_str(self) -> None: info = self.chip.get_info() self.assertEqual( str(self.chip), @@ -219,17 +219,17 @@ class StringRepresentation(TestCase): class StringRepresentationClosed(TestCase): - def setUp(self): + def setUp(self) -> None: self.sim = gpiosim.Chip(num_lines=4, label="foobar") self.chip = gpiod.Chip(self.sim.dev_path) - def tearDown(self): + def tearDown(self) -> None: self.sim = None - def test_repr_closed(self): + def test_repr_closed(self) -> None: self.chip.close() self.assertEqual(repr(self.chip), "") - def test_str_closed(self): + def test_str_closed(self) -> None: self.chip.close() self.assertEqual(str(self.chip), "") diff --git a/bindings/python/tests/tests_chip_info.py b/bindings/python/tests/tests_chip_info.py index 9474f38be3d33e60529e0e24fb4f10cb99ce9d5c..acb0da9d1f302186a2a6bca3e2f5a46abd3ebc51 100644 --- a/bindings/python/tests/tests_chip_info.py +++ b/bindings/python/tests/tests_chip_info.py @@ -9,27 +9,27 @@ from . import gpiosim class ChipInfoProperties(TestCase): - def setUp(self): + 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): + def tearDown(self) -> None: self.info = None self.chip.close() self.chip = None self.sim = None - def test_chip_info_name(self): + def test_chip_info_name(self) -> None: self.assertEqual(self.info.name, self.sim.name) - def test_chip_info_label(self): + def test_chip_info_label(self) -> None: self.assertEqual(self.info.label, "foobar") - def test_chip_info_num_lines(self): + def test_chip_info_num_lines(self) -> None: self.assertEqual(self.info.num_lines, 16) - def test_chip_info_properties_are_immutable(self): + def test_chip_info_properties_are_immutable(self) -> None: with self.assertRaises(AttributeError): self.info.name = "foobar" @@ -41,7 +41,7 @@ class ChipInfoProperties(TestCase): class ChipInfoStringRepresentation(TestCase): - def test_chip_info_str(self): + def test_chip_info_str(self) -> None: sim = gpiosim.Chip(label="foobar", num_lines=16) with gpiod.Chip(sim.dev_path) as chip: diff --git a/bindings/python/tests/tests_edge_event.py b/bindings/python/tests/tests_edge_event.py index c24d344fdbd6a1b9eda9497afab8a61c5ecb8f09..f80d6a52680c48405b935fca8e47e2a2817a2fac 100644 --- a/bindings/python/tests/tests_edge_event.py +++ b/bindings/python/tests/tests_edge_event.py @@ -17,7 +17,7 @@ Pull = gpiosim.Chip.Pull class EdgeEventWaitTimeout(TestCase): - def test_event_wait_timeout(self): + def test_event_wait_timeout(self) -> None: sim = gpiosim.Chip() with gpiod.request_lines( @@ -26,7 +26,7 @@ class EdgeEventWaitTimeout(TestCase): ) as req: self.assertEqual(req.wait_edge_events(timedelta(microseconds=10000)), False) - def test_event_wait_timeout_float(self): + def test_event_wait_timeout_float(self) -> None: sim = gpiosim.Chip() with gpiod.request_lines( @@ -37,7 +37,7 @@ class EdgeEventWaitTimeout(TestCase): class EdgeEventInvalidConfig(TestCase): - def test_output_mode_and_edge_detection(self): + def test_output_mode_and_edge_detection(self) -> None: sim = gpiosim.Chip() with self.assertRaises(ValueError): @@ -52,29 +52,31 @@ class EdgeEventInvalidConfig(TestCase): class WaitingForEdgeEvents(TestCase): - def setUp(self): + def setUp(self) -> None: self.sim = gpiosim.Chip(num_lines=8) self.thread = None - def tearDown(self): + def tearDown(self) -> None: if self.thread: self.thread.join() del self.thread self.sim = None - def trigger_falling_and_rising_edge(self, offset): + def trigger_falling_and_rising_edge(self, offset: int) -> None: time.sleep(0.05) self.sim.set_pull(offset, Pull.UP) time.sleep(0.05) self.sim.set_pull(offset, Pull.DOWN) - def trigger_rising_edge_events_on_two_offsets(self, offset0, offset1): + def trigger_rising_edge_events_on_two_offsets( + self, offset0: int, offset1: int + ) -> None: time.sleep(0.05) self.sim.set_pull(offset0, Pull.UP) time.sleep(0.05) self.sim.set_pull(offset1, Pull.UP) - def test_both_edge_events(self): + def test_both_edge_events(self) -> None: with gpiod.request_lines( self.sim.dev_path, {2: gpiod.LineSettings(edge_detection=Edge.BOTH)} ) as req: @@ -101,7 +103,7 @@ class WaitingForEdgeEvents(TestCase): self.assertGreater(ts_falling, ts_rising) - def test_rising_edge_event(self): + def test_rising_edge_event(self) -> None: with gpiod.request_lines( self.sim.dev_path, {6: gpiod.LineSettings(edge_detection=Edge.RISING)} ) as req: @@ -119,7 +121,7 @@ class WaitingForEdgeEvents(TestCase): self.assertFalse(req.wait_edge_events(timedelta(microseconds=10000))) - def test_falling_edge_event(self): + def test_falling_edge_event(self) -> None: with gpiod.request_lines( self.sim.dev_path, {6: gpiod.LineSettings(edge_detection=Edge.FALLING)} ) as req: @@ -137,7 +139,7 @@ class WaitingForEdgeEvents(TestCase): self.assertFalse(req.wait_edge_events(timedelta(microseconds=10000))) - def test_sequence_numbers(self): + def test_sequence_numbers(self) -> None: with gpiod.request_lines( self.sim.dev_path, {(2, 4): gpiod.LineSettings(edge_detection=Edge.BOTH)} ) as req: @@ -166,7 +168,7 @@ class WaitingForEdgeEvents(TestCase): class ReadingMultipleEdgeEvents(TestCase): - def setUp(self): + def setUp(self) -> None: self.sim = gpiosim.Chip(num_lines=8) self.request = gpiod.request_lines( self.sim.dev_path, {1: gpiod.LineSettings(edge_detection=Edge.BOTH)} @@ -180,12 +182,12 @@ class ReadingMultipleEdgeEvents(TestCase): self.sim.set_pull(1, Pull.UP) time.sleep(0.05) - def tearDown(self): + def tearDown(self) -> None: self.request.release() del self.request del self.sim - def test_read_multiple_events(self): + def test_read_multiple_events(self) -> None: self.assertTrue(self.request.wait_edge_events(timedelta(seconds=1))) events = self.request.read_edge_events() self.assertEqual(len(events), 3) @@ -199,7 +201,7 @@ class ReadingMultipleEdgeEvents(TestCase): class EdgeEventStringRepresentation(TestCase): - def test_edge_event_str(self): + def test_edge_event_str(self) -> None: sim = gpiosim.Chip() with gpiod.request_lines( diff --git a/bindings/python/tests/tests_info_event.py b/bindings/python/tests/tests_info_event.py index 1976f4be8b9a63942275875ada00472402524350..7e12b8e33f1a425423a1b2f30dd5af9a331906e9 100644 --- a/bindings/python/tests/tests_info_event.py +++ b/bindings/python/tests/tests_info_event.py @@ -18,7 +18,7 @@ _EventType = gpiod.InfoEvent.Type class InfoEventDataclassBehavior(TestCase): - def test_info_event_props_are_frozen(self): + def test_info_event_props_are_frozen(self) -> None: sim = gpiosim.Chip() with gpiod.Chip(sim.dev_path) as chip: @@ -37,7 +37,7 @@ class InfoEventDataclassBehavior(TestCase): event.line_info = 4 -def request_reconfigure_release_line(chip_path, offset): +def request_reconfigure_release_line(chip_path: str, offset: int) -> None: time.sleep(0.1) with gpiod.request_lines(chip_path, config={offset: None}) as request: time.sleep(0.1) @@ -48,12 +48,12 @@ def request_reconfigure_release_line(chip_path, offset): class WatchingInfoEventWorks(TestCase): - def setUp(self): + def setUp(self) -> None: self.sim = gpiosim.Chip(num_lines=8, line_names={4: "foobar"}) self.chip = gpiod.Chip(self.sim.dev_path) self.thread = None - def tearDown(self): + def tearDown(self) -> None: if self.thread: self.thread.join() self.thread = None @@ -62,35 +62,35 @@ class WatchingInfoEventWorks(TestCase): self.chip = None self.sim = None - def test_watch_line_info_returns_line_info(self): + def test_watch_line_info_returns_line_info(self) -> None: info = self.chip.watch_line_info(7) self.assertEqual(info.offset, 7) - def test_watch_line_info_keyword_argument(self): + def test_watch_line_info_keyword_argument(self) -> None: info = self.chip.watch_line_info(line=7) - def test_watch_line_info_offset_out_of_range(self): + def test_watch_line_info_offset_out_of_range(self) -> None: with self.assertRaises(ValueError): self.chip.watch_line_info(8) - def test_watch_line_info_no_arguments(self): + def test_watch_line_info_no_arguments(self) -> None: with self.assertRaises(TypeError): self.chip.watch_line_info() - def test_watch_line_info_by_line_name(self): + def test_watch_line_info_by_line_name(self) -> None: self.chip.watch_line_info("foobar") - def test_watch_line_info_invalid_argument_type(self): + def test_watch_line_info_invalid_argument_type(self) -> None: with self.assertRaises(TypeError): self.chip.watch_line_info(None) - def test_wait_for_event_timeout(self): + def test_wait_for_event_timeout(self) -> None: info = self.chip.watch_line_info(7) self.assertFalse( self.chip.wait_info_event(datetime.timedelta(microseconds=10000)) ) - def test_request_reconfigure_release_events(self): + def test_request_reconfigure_release_events(self) -> None: info = self.chip.watch_line_info(7) self.assertEqual(info.direction, Direction.INPUT) @@ -132,16 +132,16 @@ class WatchingInfoEventWorks(TestCase): class UnwatchingLineInfo(TestCase): - def setUp(self): + def setUp(self) -> None: self.sim = gpiosim.Chip(num_lines=8, line_names={4: "foobar"}) self.chip = gpiod.Chip(self.sim.dev_path) - def tearDown(self): + def tearDown(self) -> None: self.chip.close() self.chip = None self.sim = None - def test_unwatch_line_info(self): + def test_unwatch_line_info(self) -> None: self.chip.watch_line_info(0) with self.chip.request_lines(config={0: None}) as request: self.assertTrue(self.chip.wait_info_event(datetime.timedelta(seconds=1))) @@ -153,17 +153,17 @@ class UnwatchingLineInfo(TestCase): self.chip.wait_info_event(datetime.timedelta(microseconds=10000)) ) - def test_unwatch_not_watched_line(self): + def test_unwatch_not_watched_line(self) -> None: with self.assertRaises(OSError) as ex: self.chip.unwatch_line_info(2) self.assertEqual(ex.exception.errno, errno.EBUSY) - def test_unwatch_line_info_no_argument(self): + def test_unwatch_line_info_no_argument(self) -> None: with self.assertRaises(TypeError): self.chip.unwatch_line_info() - def test_unwatch_line_info_by_line_name(self): + def test_unwatch_line_info_by_line_name(self) -> None: self.chip.watch_line_info(4) with self.chip.request_lines(config={4: None}) as request: self.assertIsNotNone(self.chip.read_info_event()) @@ -175,7 +175,7 @@ class UnwatchingLineInfo(TestCase): class InfoEventStringRepresentation(TestCase): - def test_info_event_str(self): + def test_info_event_str(self) -> None: sim = gpiosim.Chip() with gpiod.Chip(sim.dev_path) as chip: diff --git a/bindings/python/tests/tests_line.py b/bindings/python/tests/tests_line.py index 218256711b2b248f692f07b9ae99e462f03c6965..c96f6de87fe811663b6040f27fee354fd203dcbc 100644 --- a/bindings/python/tests/tests_line.py +++ b/bindings/python/tests/tests_line.py @@ -7,6 +7,6 @@ from gpiod.line import Value class LineValue(TestCase): - def test_cast_bool(self): + def test_cast_bool(self) -> None: self.assertTrue(bool(Value.ACTIVE)) self.assertFalse(bool(Value.INACTIVE)) diff --git a/bindings/python/tests/tests_line_info.py b/bindings/python/tests/tests_line_info.py index 79281a82932a32bdb8c89f2aac7b15eb28eafd9d..9828349810eed0e3fa755f8557ec314d3e86ed7a 100644 --- a/bindings/python/tests/tests_line_info.py +++ b/bindings/python/tests/tests_line_info.py @@ -12,7 +12,7 @@ HogDir = gpiosim.Chip.Direction class GetLineInfo(TestCase): - def setUp(self): + def setUp(self) -> None: self.sim = gpiosim.Chip( num_lines=4, line_names={0: "foobar"}, @@ -20,37 +20,37 @@ class GetLineInfo(TestCase): self.chip = gpiod.Chip(self.sim.dev_path) - def tearDown(self): + def tearDown(self) -> None: self.chip.close() self.chip = None self.sim = None - def test_get_line_info_by_offset(self): + def test_get_line_info_by_offset(self) -> None: self.chip.get_line_info(0) - def test_get_line_info_by_offset_keyword(self): + def test_get_line_info_by_offset_keyword(self) -> None: self.chip.get_line_info(line=0) - def test_get_line_info_by_name(self): + def test_get_line_info_by_name(self) -> None: self.chip.get_line_info("foobar") - def test_get_line_info_by_name_keyword(self): + def test_get_line_info_by_name_keyword(self) -> None: self.chip.get_line_info(line="foobar") - def test_get_line_info_by_offset_string(self): + def test_get_line_info_by_offset_string(self) -> None: self.chip.get_line_info("2") - def test_offset_out_of_range(self): + def test_offset_out_of_range(self) -> None: with self.assertRaises(ValueError) as ex: self.chip.get_line_info(4) - def test_no_offset(self): + def test_no_offset(self) -> None: with self.assertRaises(TypeError): self.chip.get_line_info() class LinePropertiesCanBeRead(TestCase): - def test_basic_properties(self): + def test_basic_properties(self) -> None: sim = gpiosim.Chip( num_lines=8, line_names={1: "foo", 2: "bar", 4: "baz", 5: "xyz"}, @@ -87,7 +87,7 @@ class LinePropertiesCanBeRead(TestCase): class LineInfoStringRepresentation(TestCase): - def test_line_info_str(self): + def test_line_info_str(self) -> None: sim = gpiosim.Chip( line_names={0: "foo"}, hogs={0: ("hogger", HogDir.OUTPUT_HIGH)} ) diff --git a/bindings/python/tests/tests_line_request.py b/bindings/python/tests/tests_line_request.py index c3e86c56be63f7e449c07e7833cb7080ee42b0ac..76edb1d273f103c1b2f72974f5364728f121b05b 100644 --- a/bindings/python/tests/tests_line_request.py +++ b/bindings/python/tests/tests_line_request.py @@ -13,78 +13,78 @@ SimVal = gpiosim.Chip.Value class ChipLineRequestsBehaveCorrectlyWithInvalidArguments(TestCase): - def setUp(self): + def setUp(self) -> None: self.sim = gpiosim.Chip(num_lines=8) self.chip = gpiod.Chip(self.sim.dev_path) - def tearDown(self): + def tearDown(self) -> None: self.chip.close() del self.chip del self.sim - def test_passing_invalid_types_as_configs(self): + def test_passing_invalid_types_as_configs(self) -> None: with self.assertRaises(AttributeError): self.chip.request_lines("foobar") with self.assertRaises(AttributeError): self.chip.request_lines(None, "foobar") - def test_offset_out_of_range(self): + def test_offset_out_of_range(self) -> None: with self.assertRaises(ValueError): self.chip.request_lines(config={(1, 0, 4, 8): None}) - def test_line_name_not_found(self): + def test_line_name_not_found(self) -> None: with self.assertRaises(FileNotFoundError): self.chip.request_lines(config={"foo": None}) - def test_request_no_arguments(self): + def test_request_no_arguments(self) -> None: with self.assertRaises(TypeError): self.chip.request_lines() class ModuleLineRequestsBehaveCorrectlyWithInvalidArguments(TestCase): - def setUp(self): + def setUp(self) -> None: self.sim = gpiosim.Chip(num_lines=8) - def tearDown(self): + def tearDown(self) -> None: del self.sim - def test_passing_invalid_types_as_configs(self): + def test_passing_invalid_types_as_configs(self) -> None: with self.assertRaises(AttributeError): gpiod.request_lines(self.sim.dev_path, "foobar") with self.assertRaises(AttributeError): gpiod.request_lines(self.sim.dev_path, None, "foobar") - def test_offset_out_of_range(self): + def test_offset_out_of_range(self) -> None: with self.assertRaises(ValueError): gpiod.request_lines(self.sim.dev_path, config={(1, 0, 4, 8): None}) - def test_line_name_not_found(self): + def test_line_name_not_found(self) -> None: with self.assertRaises(FileNotFoundError): gpiod.request_lines(self.sim.dev_path, config={"foo": None}) - def test_request_no_arguments(self): + def test_request_no_arguments(self) -> None: with self.assertRaises(TypeError): gpiod.request_lines() class ChipLineRequestWorks(TestCase): - def setUp(self): + def setUp(self) -> None: self.sim = gpiosim.Chip(num_lines=8, line_names={5: "foo", 7: "bar"}) self.chip = gpiod.Chip(self.sim.dev_path) - def tearDown(self): + def tearDown(self) -> None: self.chip.close() del self.chip del self.sim - def test_request_with_positional_arguments(self): + def test_request_with_positional_arguments(self) -> None: with self.chip.request_lines({(0, 5, 3, 1): None}, "foobar", 32) as req: self.assertEqual(req.offsets, [0, 5, 3, 1]) self.assertEqual(self.chip.get_line_info(0).consumer, "foobar") - def test_request_with_keyword_arguments(self): + def test_request_with_keyword_arguments(self) -> None: with self.chip.request_lines( config={(0, 5, 6): None}, consumer="foobar", @@ -93,31 +93,31 @@ class ChipLineRequestWorks(TestCase): self.assertEqual(req.offsets, [0, 5, 6]) self.assertEqual(self.chip.get_line_info(0).consumer, "foobar") - def test_request_single_offset_as_int(self): + def test_request_single_offset_as_int(self) -> None: with self.chip.request_lines(config={4: None}) as req: self.assertEqual(req.offsets, [4]) - def test_request_single_offset_as_tuple(self): + def test_request_single_offset_as_tuple(self) -> None: with self.chip.request_lines(config={(4): None}) as req: self.assertEqual(req.offsets, [4]) - def test_request_by_name(self): + def test_request_by_name(self) -> None: with self.chip.request_lines(config={(1, 2, "foo", "bar"): None}) as req: self.assertEqual(req.offsets, [1, 2, 5, 7]) - def test_request_single_line_by_name(self): + def test_request_single_line_by_name(self) -> None: with self.chip.request_lines(config={"foo": None}) as req: self.assertEqual(req.offsets, [5]) class ModuleLineRequestWorks(TestCase): - def setUp(self): + def setUp(self) -> None: self.sim = gpiosim.Chip(num_lines=8, line_names={5: "foo", 7: "bar"}) - def tearDown(self): + def tearDown(self) -> None: del self.sim - def test_request_with_positional_arguments(self): + def test_request_with_positional_arguments(self) -> None: with gpiod.request_lines( self.sim.dev_path, {(0, 5, 3, 1): None}, "foobar", 32 ) as req: @@ -125,7 +125,7 @@ class ModuleLineRequestWorks(TestCase): with gpiod.Chip(self.sim.dev_path) as chip: self.assertEqual(chip.get_line_info(5).consumer, "foobar") - def test_request_with_keyword_arguments(self): + def test_request_with_keyword_arguments(self) -> None: with gpiod.request_lines( path=self.sim.dev_path, config={(0, 5, 6): None}, @@ -136,15 +136,15 @@ class ModuleLineRequestWorks(TestCase): with gpiod.Chip(self.sim.dev_path) as chip: self.assertEqual(chip.get_line_info(5).consumer, "foobar") - def test_request_single_offset_as_int(self): + def test_request_single_offset_as_int(self) -> None: with gpiod.request_lines(path=self.sim.dev_path, config={4: None}) as req: self.assertEqual(req.offsets, [4]) - def test_request_single_offset_as_tuple(self): + def test_request_single_offset_as_tuple(self) -> None: with gpiod.request_lines(path=self.sim.dev_path, config={(4): None}) as req: self.assertEqual(req.offsets, [4]) - def test_request_by_name(self): + def test_request_by_name(self) -> None: with gpiod.request_lines( self.sim.dev_path, {(1, 2, "foo", "bar"): None} ) as req: @@ -152,29 +152,29 @@ class ModuleLineRequestWorks(TestCase): class LineRequestGettingValues(TestCase): - def setUp(self): + def setUp(self) -> None: self.sim = gpiosim.Chip(num_lines=8) self.req = gpiod.request_lines( self.sim.dev_path, {(0, 1, 2, 3): gpiod.LineSettings(direction=Direction.INPUT)}, ) - def tearDown(self): + def tearDown(self) -> None: self.req.release() del self.req del self.sim - def test_get_single_value(self): + def test_get_single_value(self) -> None: self.sim.set_pull(1, Pull.UP) self.assertEqual(self.req.get_values([1]), [Value.ACTIVE]) - def test_get_single_value_helper(self): + def test_get_single_value_helper(self) -> None: self.sim.set_pull(1, Pull.UP) self.assertEqual(self.req.get_value(1), Value.ACTIVE) - def test_get_values_for_subset_of_lines(self): + def test_get_values_for_subset_of_lines(self) -> None: self.sim.set_pull(0, Pull.UP) self.sim.set_pull(1, Pull.DOWN) self.sim.set_pull(3, Pull.UP) @@ -183,7 +183,7 @@ class LineRequestGettingValues(TestCase): self.req.get_values([0, 1, 3]), [Value.ACTIVE, Value.INACTIVE, Value.ACTIVE] ) - def test_get_all_values(self): + def test_get_all_values(self) -> None: self.sim.set_pull(0, Pull.DOWN) self.sim.set_pull(1, Pull.UP) self.sim.set_pull(2, Pull.UP) @@ -194,29 +194,29 @@ class LineRequestGettingValues(TestCase): [Value.INACTIVE, Value.ACTIVE, Value.ACTIVE, Value.ACTIVE], ) - def test_get_values_invalid_offset(self): + def test_get_values_invalid_offset(self) -> None: with self.assertRaises(ValueError): self.req.get_values([9]) - def test_get_values_invalid_argument_type(self): + def test_get_values_invalid_argument_type(self) -> None: with self.assertRaises(TypeError): self.req.get_values(True) class LineRequestGettingValuesByName(TestCase): - def setUp(self): + def setUp(self) -> None: self.sim = gpiosim.Chip(num_lines=4, line_names={2: "foo", 3: "bar", 1: "baz"}) self.req = gpiod.request_lines( self.sim.dev_path, {(0, "baz", "bar", "foo"): gpiod.LineSettings(direction=Direction.INPUT)}, ) - def tearDown(self): + def tearDown(self) -> None: self.req.release() del self.req del self.sim - def test_get_values_by_name(self): + def test_get_values_by_name(self) -> None: self.sim.set_pull(1, Pull.UP) self.sim.set_pull(2, Pull.DOWN) self.sim.set_pull(3, Pull.UP) @@ -226,58 +226,58 @@ class LineRequestGettingValuesByName(TestCase): [Value.INACTIVE, Value.ACTIVE, Value.ACTIVE], ) - def test_get_values_by_bad_name(self): + def test_get_values_by_bad_name(self) -> None: with self.assertRaises(ValueError): self.req.get_values(["xyz"]) class LineRequestSettingValues(TestCase): - def setUp(self): + def setUp(self) -> None: self.sim = gpiosim.Chip(num_lines=8) self.req = gpiod.request_lines( self.sim.dev_path, {(0, 1, 2, 3): gpiod.LineSettings(direction=Direction.OUTPUT)}, ) - def tearDown(self): + def tearDown(self) -> None: self.req.release() del self.req del self.sim - def test_set_single_value(self): + def test_set_single_value(self) -> None: self.req.set_values({1: Value.ACTIVE}) self.assertEqual(self.sim.get_value(1), SimVal.ACTIVE) - def test_set_single_value_helper(self): + def test_set_single_value_helper(self) -> None: self.req.set_value(1, Value.ACTIVE) self.assertEqual(self.sim.get_value(1), SimVal.ACTIVE) - def test_set_values_for_subset_of_lines(self): + def test_set_values_for_subset_of_lines(self) -> None: self.req.set_values({0: Value.ACTIVE, 1: Value.INACTIVE, 3: Value.ACTIVE}) self.assertEqual(self.sim.get_value(0), SimVal.ACTIVE) self.assertEqual(self.sim.get_value(1), SimVal.INACTIVE) self.assertEqual(self.sim.get_value(3), SimVal.ACTIVE) - def test_set_values_invalid_offset(self): + def test_set_values_invalid_offset(self) -> None: with self.assertRaises(ValueError): self.req.set_values({9: Value.ACTIVE}) class LineRequestSettingValuesByName(TestCase): - def setUp(self): + def setUp(self) -> None: self.sim = gpiosim.Chip(num_lines=4, line_names={2: "foo", 3: "bar", 1: "baz"}) self.req = gpiod.request_lines( self.sim.dev_path, {(0, "baz", "bar", "foo"): gpiod.LineSettings(direction=Direction.OUTPUT)}, ) - def tearDown(self): + def tearDown(self) -> None: self.req.release() del self.req del self.sim - def test_set_values_by_name(self): + def test_set_values_by_name(self) -> None: self.req.set_values( {"foo": Value.INACTIVE, "bar": Value.ACTIVE, 1: Value.ACTIVE} ) @@ -286,13 +286,13 @@ class LineRequestSettingValuesByName(TestCase): self.assertEqual(self.sim.get_value(1), SimVal.ACTIVE) self.assertEqual(self.sim.get_value(3), SimVal.ACTIVE) - def test_set_values_by_bad_name(self): + def test_set_values_by_bad_name(self) -> None: with self.assertRaises(ValueError): self.req.set_values({"xyz": Value.ACTIVE}) class LineRequestComplexConfig(TestCase): - def test_complex_config(self): + def test_complex_config(self) -> None: sim = gpiosim.Chip(num_lines=8) with gpiod.Chip(sim.dev_path) as chip: @@ -314,7 +314,7 @@ class LineRequestComplexConfig(TestCase): class LineRequestMixedConfigByName(TestCase): - def setUp(self): + def setUp(self) -> None: self.sim = gpiosim.Chip( num_lines=4, line_names={2: "foo", 3: "bar", 1: "baz", 0: "xyz"} ) @@ -326,18 +326,18 @@ class LineRequestMixedConfigByName(TestCase): }, ) - def tearDown(self): + def tearDown(self) -> None: self.req.release() del self.req del self.sim - def test_set_values_by_name(self): + def test_set_values_by_name(self) -> None: self.req.set_values({"bar": Value.ACTIVE, "baz": Value.INACTIVE}) self.assertEqual(self.sim.get_value(1), SimVal.INACTIVE) self.assertEqual(self.sim.get_value(3), SimVal.ACTIVE) - def test_get_values_by_name(self): + def test_get_values_by_name(self) -> None: self.sim.set_pull(0, Pull.UP) self.sim.set_pull(2, Pull.DOWN) @@ -348,40 +348,40 @@ class LineRequestMixedConfigByName(TestCase): class RepeatingLinesInRequestConfig(TestCase): - def setUp(self): + def setUp(self) -> None: self.sim = gpiosim.Chip(num_lines=4, line_names={0: "foo", 2: "bar"}) self.chip = gpiod.Chip(self.sim.dev_path) - def tearDown(self): + def tearDown(self) -> None: self.chip.close() del self.chip del self.sim - def test_offsets_repeating_within_the_same_tuple(self): + def test_offsets_repeating_within_the_same_tuple(self) -> None: with self.assertRaises(ValueError): self.chip.request_lines({(0, 1, 2, 1): None}) - def test_offsets_repeating_in_different_tuples(self): + def test_offsets_repeating_in_different_tuples(self) -> None: with self.assertRaises(ValueError): self.chip.request_lines({(0, 1, 2): None, (3, 4, 0): None}) - def test_offset_and_name_conflict_in_the_same_tuple(self): + def test_offset_and_name_conflict_in_the_same_tuple(self) -> None: with self.assertRaises(ValueError): self.chip.request_lines({(2, "bar"): None}) - def test_offset_and_name_conflict_in_different_tuples(self): + def test_offset_and_name_conflict_in_different_tuples(self) -> None: with self.assertRaises(ValueError): self.chip.request_lines({(0, 1, 2): None, (4, 5, "bar"): None}) class LineRequestPropertiesWork(TestCase): - def setUp(self): + def setUp(self) -> None: self.sim = gpiosim.Chip(num_lines=16, line_names={0: "foo", 2: "bar", 5: "baz"}) - def tearDown(self): + def tearDown(self) -> None: del self.sim - def test_property_fd(self): + def test_property_fd(self) -> None: with gpiod.request_lines( self.sim.dev_path, config={ @@ -392,19 +392,19 @@ class LineRequestPropertiesWork(TestCase): ) as req: self.assertGreaterEqual(req.fd, 0) - def test_property_num_lines(self): + def test_property_num_lines(self) -> None: with gpiod.request_lines( self.sim.dev_path, config={(0, 2, 3, 5, 6, 8, 12): None} ) as req: self.assertEqual(req.num_lines, 7) - def test_property_offsets(self): + def test_property_offsets(self) -> None: with gpiod.request_lines( self.sim.dev_path, config={(1, 6, 12, 4): None} ) as req: self.assertEqual(req.offsets, [1, 6, 12, 4]) - def test_property_lines(self): + def test_property_lines(self) -> None: with gpiod.request_lines( self.sim.dev_path, config={("foo", 1, "bar", 4, "baz"): None} ) as req: @@ -412,43 +412,43 @@ class LineRequestPropertiesWork(TestCase): class LineRequestConsumerString(TestCase): - def setUp(self): + def setUp(self) -> None: self.sim = gpiosim.Chip(num_lines=4) self.chip = gpiod.Chip(self.sim.dev_path) - def tearDown(self): + def tearDown(self) -> None: self.chip.close() del self.chip del self.sim - def test_custom_consumer(self): + def test_custom_consumer(self) -> None: with self.chip.request_lines( consumer="foobar", config={(2, 3): None} ) as request: info = self.chip.get_line_info(2) self.assertEqual(info.consumer, "foobar") - def test_empty_consumer(self): + def test_empty_consumer(self) -> None: with self.chip.request_lines(consumer="", config={(2, 3): None}) as request: info = self.chip.get_line_info(2) self.assertEqual(info.consumer, "?") - def test_default_consumer(self): + def test_default_consumer(self) -> None: with self.chip.request_lines(config={(2, 3): None}) as request: info = self.chip.get_line_info(2) self.assertEqual(info.consumer, "?") class LineRequestSetOutputValues(TestCase): - def setUp(self): + def setUp(self) -> None: self.sim = gpiosim.Chip( num_lines=4, line_names={0: "foo", 1: "bar", 2: "baz", 3: "xyz"} ) - def tearDown(self): + def tearDown(self) -> None: del self.sim - def test_request_with_globally_set_output_values(self): + def test_request_with_globally_set_output_values(self) -> None: with gpiod.request_lines( self.sim.dev_path, config={(0, 1, 2, 3): gpiod.LineSettings(direction=Direction.OUTPUT)}, @@ -464,7 +464,7 @@ class LineRequestSetOutputValues(TestCase): self.assertEqual(self.sim.get_value(2), SimVal.ACTIVE) self.assertEqual(self.sim.get_value(3), SimVal.INACTIVE) - def test_request_with_globally_set_output_values_with_mapping(self): + def test_request_with_globally_set_output_values_with_mapping(self) -> None: with gpiod.request_lines( self.sim.dev_path, config={(0, 1, 2, 3): gpiod.LineSettings(direction=Direction.OUTPUT)}, @@ -475,7 +475,7 @@ class LineRequestSetOutputValues(TestCase): self.assertEqual(self.sim.get_value(2), SimVal.ACTIVE) self.assertEqual(self.sim.get_value(3), SimVal.INACTIVE) - def test_request_with_globally_set_output_values_bad_mapping(self): + def test_request_with_globally_set_output_values_bad_mapping(self) -> None: with self.assertRaises(FileNotFoundError): with gpiod.request_lines( self.sim.dev_path, @@ -484,7 +484,7 @@ class LineRequestSetOutputValues(TestCase): ) as request: pass - def test_request_with_globally_set_output_values_bad_offset(self): + def test_request_with_globally_set_output_values_bad_offset(self) -> None: with self.assertRaises(ValueError): with gpiod.request_lines( self.sim.dev_path, @@ -495,7 +495,7 @@ class LineRequestSetOutputValues(TestCase): class ReconfigureRequestedLines(TestCase): - def setUp(self): + def setUp(self) -> None: self.sim = gpiosim.Chip(num_lines=8, line_names={3: "foo", 4: "bar", 6: "baz"}) self.chip = gpiod.Chip(self.sim.dev_path) self.req = self.chip.request_lines( @@ -506,14 +506,14 @@ class ReconfigureRequestedLines(TestCase): } ) - def tearDown(self): + def tearDown(self) -> None: self.chip.close() del self.chip self.req.release() del self.req del self.sim - def test_reconfigure_by_offsets(self): + def test_reconfigure_by_offsets(self) -> None: info = self.chip.get_line_info(2) self.assertEqual(info.direction, Direction.OUTPUT) self.req.reconfigure_lines( @@ -522,7 +522,7 @@ class ReconfigureRequestedLines(TestCase): info = self.chip.get_line_info(2) self.assertEqual(info.direction, Direction.INPUT) - def test_reconfigure_by_names(self): + def test_reconfigure_by_names(self) -> None: info = self.chip.get_line_info(2) self.assertEqual(info.direction, Direction.OUTPUT) self.req.reconfigure_lines( @@ -531,7 +531,7 @@ class ReconfigureRequestedLines(TestCase): info = self.chip.get_line_info(2) self.assertEqual(info.direction, Direction.INPUT) - def test_reconfigure_by_misordered_offsets(self): + def test_reconfigure_by_misordered_offsets(self) -> None: info = self.chip.get_line_info(2) self.assertEqual(info.direction, Direction.OUTPUT) self.req.reconfigure_lines( @@ -540,7 +540,7 @@ class ReconfigureRequestedLines(TestCase): info = self.chip.get_line_info(2) self.assertEqual(info.direction, Direction.INPUT) - def test_reconfigure_by_misordered_names(self): + def test_reconfigure_by_misordered_names(self) -> None: info = self.chip.get_line_info(2) self.assertEqual(info.direction, Direction.OUTPUT) self.req.reconfigure_lines( @@ -549,7 +549,7 @@ class ReconfigureRequestedLines(TestCase): info = self.chip.get_line_info(2) self.assertEqual(info.direction, Direction.INPUT) - def test_reconfigure_with_default(self): + def test_reconfigure_with_default(self) -> None: info = self.chip.get_line_info(2) self.assertEqual(info.direction, Direction.OUTPUT) self.assertTrue(info.active_low) @@ -568,7 +568,7 @@ class ReconfigureRequestedLines(TestCase): self.assertTrue(info.active_low) self.assertEqual(info.drive, Drive.OPEN_DRAIN) - def test_reconfigure_missing_offsets(self): + def test_reconfigure_missing_offsets(self) -> None: info = self.chip.get_line_info(2) self.assertEqual(info.direction, Direction.OUTPUT) self.assertTrue(info.active_low) @@ -583,7 +583,7 @@ class ReconfigureRequestedLines(TestCase): self.assertTrue(info.active_low) self.assertEqual(info.drive, Drive.OPEN_DRAIN) - def test_reconfigure_extra_offsets(self): + def test_reconfigure_extra_offsets(self) -> None: info = self.chip.get_line_info(2) self.assertEqual(info.direction, Direction.OUTPUT) self.req.reconfigure_lines( @@ -594,7 +594,7 @@ class ReconfigureRequestedLines(TestCase): class ReleasedLineRequestCannotBeUsed(TestCase): - def test_using_released_line_request(self): + def test_using_released_line_request(self) -> None: sim = gpiosim.Chip() with gpiod.Chip(sim.dev_path) as chip: @@ -606,7 +606,7 @@ class ReleasedLineRequestCannotBeUsed(TestCase): class LineRequestSurvivesParentChip(TestCase): - def test_line_request_survives_parent_chip(self): + def test_line_request_survives_parent_chip(self) -> None: sim = gpiosim.Chip() chip = gpiod.Chip(sim.dev_path) @@ -624,13 +624,13 @@ class LineRequestSurvivesParentChip(TestCase): class LineRequestStringRepresentation(TestCase): - def setUp(self): + def setUp(self) -> None: self.sim = gpiosim.Chip(num_lines=8) - def tearDown(self): + def tearDown(self) -> None: del self.sim - def test_str(self): + def test_str(self) -> None: with gpiod.Chip(self.sim.dev_path) as chip: with chip.request_lines(config={(2, 6, 4, 1): None}) as req: self.assertEqual( @@ -640,7 +640,7 @@ class LineRequestStringRepresentation(TestCase): ), ) - def test_str_released(self): + def test_str_released(self) -> None: req = gpiod.request_lines(self.sim.dev_path, config={(2, 6, 4, 1): None}) req.release() self.assertEqual(str(req), "") diff --git a/bindings/python/tests/tests_line_settings.py b/bindings/python/tests/tests_line_settings.py index 832ac8a2377ddb25f5a5ab5c1732d1a9d5c5dff1..66e01dfea3339391b2146cf3ed2c26c8fc1cc34e 100644 --- a/bindings/python/tests/tests_line_settings.py +++ b/bindings/python/tests/tests_line_settings.py @@ -9,7 +9,7 @@ from gpiod.line import Bias, Clock, Direction, Drive, Edge, Value class LineSettingsConstructor(TestCase): - def test_default_values(self): + def test_default_values(self) -> None: settings = gpiod.LineSettings() self.assertEqual(settings.direction, Direction.AS_IS) @@ -21,7 +21,7 @@ class LineSettingsConstructor(TestCase): self.assertEqual(settings.event_clock, Clock.MONOTONIC) self.assertEqual(settings.output_value, Value.INACTIVE) - def test_keyword_arguments(self): + def test_keyword_arguments(self) -> None: settings = gpiod.LineSettings( direction=Direction.INPUT, edge_detection=Edge.BOTH, @@ -40,7 +40,7 @@ class LineSettingsConstructor(TestCase): class LineSettingsAttributes(TestCase): - def test_line_settings_attributes_are_mutable(self): + def test_line_settings_attributes_are_mutable(self) -> None: settings = gpiod.LineSettings() settings.direction = Direction.INPUT @@ -60,12 +60,12 @@ class LineSettingsAttributes(TestCase): class LineSettingsStringRepresentation(TestCase): - def setUp(self): + def setUp(self) -> None: self.settings = gpiod.LineSettings( direction=Direction.OUTPUT, drive=Drive.OPEN_SOURCE, active_low=True ) - def test_repr(self): + def test_repr(self) -> None: self.assertEqual( repr(self.settings), "gpiod.LineSettings(direction=gpiod.line.Direction.OUTPUT, edge_detection=gpiod.line.Edge.NONE, bias=gpiod.line.Bias.AS_IS, drive=gpiod.line.Drive.OPEN_SOURCE, active_low=True, debounce_period=datetime.timedelta(0), event_clock=gpiod.line.Clock.MONOTONIC, output_value=gpiod.line.Value.INACTIVE)", @@ -74,7 +74,7 @@ class LineSettingsStringRepresentation(TestCase): cmp = eval(repr(self.settings)) self.assertEqual(self.settings, cmp) - def test_str(self): + def test_str(self) -> None: self.assertEqual( str(self.settings), "", diff --git a/bindings/python/tests/tests_module.py b/bindings/python/tests/tests_module.py index f46729feda86962d17907bc8b6b4e710fec3087e..2718624c7e0dd41259c7006e37d48f52cc279b1d 100644 --- a/bindings/python/tests/tests_module.py +++ b/bindings/python/tests/tests_module.py @@ -11,38 +11,38 @@ from .helpers import LinkGuard class IsGPIOChip(TestCase): - def test_is_gpiochip_bad(self): + 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): + def test_is_gpiochip_invalid_argument(self) -> None: with self.assertRaises(TypeError): gpiod.is_gpiochip_device(4) - def test_is_gpiochip_superfluous_argument(self): + def test_is_gpiochip_superfluous_argument(self) -> None: with self.assertRaises(TypeError): gpiod.is_gpiochip_device("/dev/null", 4) - def test_is_gpiochip_missing_argument(self): + def test_is_gpiochip_missing_argument(self) -> None: with self.assertRaises(TypeError): gpiod.is_gpiochip_device() - def test_is_gpiochip_good(self): + 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): + 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): + def test_is_gpiochip_link_good(self) -> None: link = "/tmp/gpiod-py-test-link.{}".format(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): + def test_is_gpiochip_link_bad(self) -> None: link = "/tmp/gpiod-py-test-link.{}".format(os.getpid()) with LinkGuard("/dev/null", link): @@ -52,8 +52,8 @@ class IsGPIOChip(TestCase): class VersionString(TestCase): VERSION_PATTERN = "^\\d+\\.\\d+(\\.\\d+|\\-devel|\\-rc\\d+)?$" - def test_api_version_string(self): + def test_api_version_string(self) -> None: self.assertRegex(gpiod.api_version, VersionString.VERSION_PATTERN) - def test_module_version(self): + def test_module_version(self) -> None: self.assertRegex(gpiod.__version__, VersionString.VERSION_PATTERN) From patchwork Fri Sep 27 18:53:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Fazio X-Patchwork-Id: 831085 Received: from mail.xes-mad.com (mail.xes-mad.com [162.248.234.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E20451C2323 for ; Fri, 27 Sep 2024 18:55:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=162.248.234.2 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727463329; cv=none; b=NViDG9ukaOuP7Uin8udf65N/lOMAnoSBrusOQUQ9yR3B4hkhyNOyCpqX+Y5cJaUGGfUKRUqJTdp1X8NNMXJHcBDaOvYCUnCGTSTuk1zdxZ4lgGxEovFXepbJvFxBVu3q77F+USr0G7xDFvHuvCHvV6SaH/VoFe20Ihs0Y/Tsbq8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727463329; c=relaxed/simple; bh=/x8Rs9BWHy1aC8uDHr6soOcZ3jOw21eTjTe5cSbL4As=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=EL5syT2e/bHjtp2jm1rgvU/kXF+hibbyhM8nIglU6CfJqO1j9ogb6qJ7S7UJLlgJrzMjlvMcRMRpHzGmCGkuAWvmVw2wsgccvrd4mNv+wK0LT3Kj7w2bMYvWNlr68fXjWYe/XPEq1JDlA76rYPbBAKyvSSBnsgjJ4TSFhi4njI4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=xes-inc.com; spf=pass smtp.mailfrom=xes-inc.com; dkim=pass (1024-bit key) header.d=xes-inc.com header.i=@xes-inc.com header.b=MaXa9902; arc=none smtp.client-ip=162.248.234.2 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=xes-inc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=xes-inc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=xes-inc.com header.i=@xes-inc.com header.b="MaXa9902" Received: from vfazio4.xes-mad.com (vfazio4.xes-mad.com [10.52.19.201]) by mail.xes-mad.com (Postfix) with ESMTP id 7CBA222AD9; Fri, 27 Sep 2024 13:55:17 -0500 (CDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=xes-inc.com; s=mail; t=1727463317; bh=/x8Rs9BWHy1aC8uDHr6soOcZ3jOw21eTjTe5cSbL4As=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MaXa9902bEsqYkYCaylhZyjI1wBgVshHSQ3sWBpIfIo3nqyK4cln7tmAcSvSIe+zw FLqKof2+8n+LgYBgJ6lt33uwZ3u+NkTe+/nfYI+epU/FK9HZQHPSq/rLVuv46dLeIK fr+m6VCS+wHbRT5CEaDOHL2VH9Q0q8ZTO8oo3OdY= From: Vincent Fazio To: linux-gpio@vger.kernel.org Cc: vfazio@gmail.com, Vincent Fazio Subject: [libgpiod][PATCH 19/22] bindings: python: tests: ignore purposeful type errors Date: Fri, 27 Sep 2024 13:53:55 -0500 Message-Id: <20240927-vfazio-mypy-v1-19-91a7c2e20884@xes-inc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240927-vfazio-mypy-v1-0-91a7c2e20884@xes-inc.com> References: <20240927-vfazio-mypy-v1-0-91a7c2e20884@xes-inc.com> Precedence: bulk X-Mailing-List: linux-gpio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Signed-off-by: Vincent Fazio --- bindings/python/tests/tests_chip.py | 12 ++++++------ bindings/python/tests/tests_chip_info.py | 6 +++--- bindings/python/tests/tests_info_event.py | 12 ++++++------ bindings/python/tests/tests_line_info.py | 2 +- bindings/python/tests/tests_line_request.py | 16 ++++++++-------- bindings/python/tests/tests_module.py | 6 +++--- 6 files changed, 27 insertions(+), 27 deletions(-) diff --git a/bindings/python/tests/tests_chip.py b/bindings/python/tests/tests_chip.py index 9c8f87579469e684ed3b6a5dbcef35e0856127ba..89d5df4341eceefbc0eed9b880ac641caa682af5 100644 --- a/bindings/python/tests/tests_chip.py +++ b/bindings/python/tests/tests_chip.py @@ -52,11 +52,11 @@ class ChipConstructor(TestCase): def test_missing_path(self) -> None: with self.assertRaises(TypeError): - gpiod.Chip() + gpiod.Chip() # type: ignore[call-arg] def test_invalid_type_for_path(self) -> None: with self.assertRaises(TypeError): - gpiod.Chip(4) + gpiod.Chip(4) # type: ignore[arg-type] class ChipBooleanConversion(TestCase): @@ -85,10 +85,10 @@ class ChipProperties(TestCase): def test_properties_are_immutable(self) -> None: with self.assertRaises(AttributeError): - self.chip.path = "foobar" + self.chip.path = "foobar" # type: ignore[misc] with self.assertRaises(AttributeError): - self.chip.fd = 4 + self.chip.fd = 4 # type: ignore[misc] class ChipDevPathFromLink(TestCase): @@ -172,7 +172,7 @@ class ClosedChipCannotBeUsed(TestCase): chip.close() with self.assertRaises(gpiod.ChipClosedError): - chip.path + _ = chip.path def test_close_chip_and_try_controlled_execution(self) -> None: sim = gpiosim.Chip() @@ -182,7 +182,7 @@ class ClosedChipCannotBeUsed(TestCase): with self.assertRaises(gpiod.ChipClosedError): with chip: - chip.fd + _ = chip.fd def test_close_chip_twice(self) -> None: sim = gpiosim.Chip(label="foobar") diff --git a/bindings/python/tests/tests_chip_info.py b/bindings/python/tests/tests_chip_info.py index acb0da9d1f302186a2a6bca3e2f5a46abd3ebc51..99259af307fa25bc3ff39574a1bea1cc9dc254a6 100644 --- a/bindings/python/tests/tests_chip_info.py +++ b/bindings/python/tests/tests_chip_info.py @@ -31,13 +31,13 @@ class ChipInfoProperties(TestCase): def test_chip_info_properties_are_immutable(self) -> None: with self.assertRaises(AttributeError): - self.info.name = "foobar" + self.info.name = "foobar" # type: ignore[misc] with self.assertRaises(AttributeError): - self.info.num_lines = 4 + self.info.num_lines = 4 # type: ignore[misc] with self.assertRaises(AttributeError): - self.info.label = "foobar" + self.info.label = "foobar" # type: ignore[misc] class ChipInfoStringRepresentation(TestCase): diff --git a/bindings/python/tests/tests_info_event.py b/bindings/python/tests/tests_info_event.py index 7e12b8e33f1a425423a1b2f30dd5af9a331906e9..1e6ab941799047c7e5383a6d0a2512c669655d19 100644 --- a/bindings/python/tests/tests_info_event.py +++ b/bindings/python/tests/tests_info_event.py @@ -28,13 +28,13 @@ class InfoEventDataclassBehavior(TestCase): event = chip.read_info_event() with self.assertRaises(FrozenInstanceError): - event.event_type = 4 + event.event_type = 4 # type: ignore[misc, assignment] with self.assertRaises(FrozenInstanceError): - event.timestamp_ns = 4 + event.timestamp_ns = 4 # type: ignore[misc] with self.assertRaises(FrozenInstanceError): - event.line_info = 4 + event.line_info = 4 # type: ignore[misc, assignment] def request_reconfigure_release_line(chip_path: str, offset: int) -> None: @@ -75,14 +75,14 @@ class WatchingInfoEventWorks(TestCase): def test_watch_line_info_no_arguments(self) -> None: with self.assertRaises(TypeError): - self.chip.watch_line_info() + self.chip.watch_line_info() # type: ignore[call-arg] def test_watch_line_info_by_line_name(self) -> None: self.chip.watch_line_info("foobar") def test_watch_line_info_invalid_argument_type(self) -> None: with self.assertRaises(TypeError): - self.chip.watch_line_info(None) + self.chip.watch_line_info(None) # type: ignore[arg-type] def test_wait_for_event_timeout(self) -> None: info = self.chip.watch_line_info(7) @@ -161,7 +161,7 @@ class UnwatchingLineInfo(TestCase): def test_unwatch_line_info_no_argument(self) -> None: with self.assertRaises(TypeError): - self.chip.unwatch_line_info() + self.chip.unwatch_line_info() # type: ignore[call-arg] def test_unwatch_line_info_by_line_name(self) -> None: self.chip.watch_line_info(4) diff --git a/bindings/python/tests/tests_line_info.py b/bindings/python/tests/tests_line_info.py index 9828349810eed0e3fa755f8557ec314d3e86ed7a..33d38a6de486447d326e8e3cb73934898ea2aba2 100644 --- a/bindings/python/tests/tests_line_info.py +++ b/bindings/python/tests/tests_line_info.py @@ -46,7 +46,7 @@ class GetLineInfo(TestCase): def test_no_offset(self) -> None: with self.assertRaises(TypeError): - self.chip.get_line_info() + self.chip.get_line_info() # type: ignore[call-arg] class LinePropertiesCanBeRead(TestCase): diff --git a/bindings/python/tests/tests_line_request.py b/bindings/python/tests/tests_line_request.py index 76edb1d273f103c1b2f72974f5364728f121b05b..bae8815b98654145c26071c4fc40816469313192 100644 --- a/bindings/python/tests/tests_line_request.py +++ b/bindings/python/tests/tests_line_request.py @@ -24,10 +24,10 @@ class ChipLineRequestsBehaveCorrectlyWithInvalidArguments(TestCase): def test_passing_invalid_types_as_configs(self) -> None: with self.assertRaises(AttributeError): - self.chip.request_lines("foobar") + self.chip.request_lines("foobar") # type: ignore[arg-type] with self.assertRaises(AttributeError): - self.chip.request_lines(None, "foobar") + self.chip.request_lines(None, "foobar") # type: ignore[arg-type] def test_offset_out_of_range(self) -> None: with self.assertRaises(ValueError): @@ -39,7 +39,7 @@ class ChipLineRequestsBehaveCorrectlyWithInvalidArguments(TestCase): def test_request_no_arguments(self) -> None: with self.assertRaises(TypeError): - self.chip.request_lines() + self.chip.request_lines() # type: ignore[call-arg] class ModuleLineRequestsBehaveCorrectlyWithInvalidArguments(TestCase): @@ -51,10 +51,10 @@ class ModuleLineRequestsBehaveCorrectlyWithInvalidArguments(TestCase): def test_passing_invalid_types_as_configs(self) -> None: with self.assertRaises(AttributeError): - gpiod.request_lines(self.sim.dev_path, "foobar") + gpiod.request_lines(self.sim.dev_path, "foobar") # type: ignore[arg-type] with self.assertRaises(AttributeError): - gpiod.request_lines(self.sim.dev_path, None, "foobar") + gpiod.request_lines(self.sim.dev_path, None, "foobar") # type: ignore[arg-type] def test_offset_out_of_range(self) -> None: with self.assertRaises(ValueError): @@ -66,7 +66,7 @@ class ModuleLineRequestsBehaveCorrectlyWithInvalidArguments(TestCase): def test_request_no_arguments(self) -> None: with self.assertRaises(TypeError): - gpiod.request_lines() + gpiod.request_lines() # type: ignore[call-arg] class ChipLineRequestWorks(TestCase): @@ -200,7 +200,7 @@ class LineRequestGettingValues(TestCase): def test_get_values_invalid_argument_type(self) -> None: with self.assertRaises(TypeError): - self.req.get_values(True) + self.req.get_values(True) # type: ignore[arg-type] class LineRequestGettingValuesByName(TestCase): @@ -602,7 +602,7 @@ class ReleasedLineRequestCannotBeUsed(TestCase): req.release() with self.assertRaises(gpiod.RequestReleasedError): - req.fd + _ = req.fd class LineRequestSurvivesParentChip(TestCase): diff --git a/bindings/python/tests/tests_module.py b/bindings/python/tests/tests_module.py index 2718624c7e0dd41259c7006e37d48f52cc279b1d..efd49db59e6567b9bc5ee0096ccce3281ac466f3 100644 --- a/bindings/python/tests/tests_module.py +++ b/bindings/python/tests/tests_module.py @@ -17,15 +17,15 @@ class IsGPIOChip(TestCase): def test_is_gpiochip_invalid_argument(self) -> None: with self.assertRaises(TypeError): - gpiod.is_gpiochip_device(4) + 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) + 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() + gpiod.is_gpiochip_device() # type: ignore[call-arg] def test_is_gpiochip_good(self) -> None: sim = gpiosim.Chip() From patchwork Fri Sep 27 18:53:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Fazio X-Patchwork-Id: 831084 Received: from mail.xes-mad.com (mail.xes-mad.com [162.248.234.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B2F271C231C for ; Fri, 27 Sep 2024 18:55:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=162.248.234.2 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727463329; cv=none; b=bCP42eSIj1CU5nIopgMXQV1U/cpW7xLLKnmdz1KoK5jjVAwmW8RfgJofwEceMDM10MDQp0AfeLCIQsG3SjrE7rt0hYdIn30P0ks/RGfO60b9wSHu3rmhOCuEuXo8M5abWdb/MJQSnlJfo/F4cpUMdp62ueaaNHR8FlIZLKSxAsM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727463329; c=relaxed/simple; bh=lvXyXdy0hx9zA2Fk9QricScjcp3Drs+CDsP8uEgtRlU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=R8gffr2YC1JTHkJnE36Uu0Ifes0GSe/oZNm54TzHjBOC6qTPBorZCL4fcgEimXmxjKv31bzPtyrp4CEXkAkHWBX9JqtPQjlUGtf8+jcxgWVApRvb19sT49pNA8I5MsvPPsCBdBPw6UZNxQIwB/r99r7oD7th+QaygXDkTg0y5A8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=xes-inc.com; spf=pass smtp.mailfrom=xes-inc.com; dkim=pass (1024-bit key) header.d=xes-inc.com header.i=@xes-inc.com header.b=Fs6nEMui; arc=none smtp.client-ip=162.248.234.2 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=xes-inc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=xes-inc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=xes-inc.com header.i=@xes-inc.com header.b="Fs6nEMui" Received: from vfazio4.xes-mad.com (vfazio4.xes-mad.com [10.52.19.201]) by mail.xes-mad.com (Postfix) with ESMTP id 937FE22ADB; Fri, 27 Sep 2024 13:55:17 -0500 (CDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=xes-inc.com; s=mail; t=1727463317; bh=lvXyXdy0hx9zA2Fk9QricScjcp3Drs+CDsP8uEgtRlU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Fs6nEMuiaGhj2OUVDOod9rxJhoOn7tWDI8pxpY+pXQSBrCOjUFKR4sr0RZ7DjjhzK fJhPjIWT1E9jq1lnik/7+BhA4zJT3OzE4X5Nn/W45C49rDyxmD9eyIfKJ/dzI0sdRy O9RJf97iSGeJmdtIvlH8TmP2+KLC4zlYv6nIvvHo= From: Vincent Fazio To: linux-gpio@vger.kernel.org Cc: vfazio@gmail.com, Vincent Fazio Subject: [libgpiod][PATCH 20/22] bindings: python: tests: annotate internal members Date: Fri, 27 Sep 2024 13:53:56 -0500 Message-Id: <20240927-vfazio-mypy-v1-20-91a7c2e20884@xes-inc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240927-vfazio-mypy-v1-0-91a7c2e20884@xes-inc.com> References: <20240927-vfazio-mypy-v1-0-91a7c2e20884@xes-inc.com> Precedence: bulk X-Mailing-List: linux-gpio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Signed-off-by: Vincent Fazio --- bindings/python/tests/tests_chip.py | 10 +++++++--- bindings/python/tests/tests_chip_info.py | 13 ++++++++++--- bindings/python/tests/tests_edge_event.py | 11 +++++++++-- bindings/python/tests/tests_info_event.py | 30 +++++++++++++++++++++++++----- bindings/python/tests/tests_line_info.py | 13 +++++++++++-- 5 files changed, 62 insertions(+), 15 deletions(-) diff --git a/bindings/python/tests/tests_chip.py b/bindings/python/tests/tests_chip.py index 89d5df4341eceefbc0eed9b880ac641caa682af5..b719f6ba402c962b3ba8029cef61ed28fd1a525a 100644 --- a/bindings/python/tests/tests_chip.py +++ b/bindings/python/tests/tests_chip.py @@ -3,6 +3,7 @@ import errno import os +from typing import Optional from unittest import TestCase import gpiod @@ -70,7 +71,7 @@ class ChipBooleanConversion(TestCase): class ChipProperties(TestCase): def setUp(self) -> None: - self.sim = gpiosim.Chip() + self.sim: Optional[gpiosim.Chip] = gpiosim.Chip() self.chip = gpiod.Chip(self.sim.dev_path) def tearDown(self) -> None: @@ -78,6 +79,7 @@ class ChipProperties(TestCase): self.sim = None def test_get_chip_path(self) -> None: + assert self.sim self.assertEqual(self.sim.dev_path, self.chip.path) def test_get_fd(self) -> None: @@ -195,7 +197,7 @@ class ClosedChipCannotBeUsed(TestCase): class StringRepresentation(TestCase): def setUp(self) -> None: - self.sim = gpiosim.Chip(num_lines=4, label="foobar") + self.sim: Optional[gpiosim.Chip] = gpiosim.Chip(num_lines=4, label="foobar") self.chip = gpiod.Chip(self.sim.dev_path) def tearDown(self) -> None: @@ -203,12 +205,14 @@ class StringRepresentation(TestCase): self.sim = None def test_repr(self) -> None: + assert self.sim self.assertEqual(repr(self.chip), 'gpiod.Chip("{}")'.format(self.sim.dev_path)) cmp = eval(repr(self.chip)) self.assertEqual(self.chip.path, cmp.path) def test_str(self) -> None: + assert self.sim info = self.chip.get_info() self.assertEqual( str(self.chip), @@ -220,7 +224,7 @@ class StringRepresentation(TestCase): class StringRepresentationClosed(TestCase): def setUp(self) -> None: - self.sim = gpiosim.Chip(num_lines=4, label="foobar") + self.sim: Optional[gpiosim.Chip] = gpiosim.Chip(num_lines=4, label="foobar") self.chip = gpiod.Chip(self.sim.dev_path) def tearDown(self) -> None: diff --git a/bindings/python/tests/tests_chip_info.py b/bindings/python/tests/tests_chip_info.py index 99259af307fa25bc3ff39574a1bea1cc9dc254a6..463f07ab8edeec7dde8dacc4829b86dd3b1d6ebd 100644 --- a/bindings/python/tests/tests_chip_info.py +++ b/bindings/python/tests/tests_chip_info.py @@ -1,6 +1,7 @@ # SPDX-License-Identifier: GPL-2.0-or-later # SPDX-FileCopyrightText: 2022 Bartosz Golaszewski +from typing import Optional from unittest import TestCase import gpiod @@ -10,26 +11,32 @@ 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() + self.sim: Optional[gpiosim.Chip] = gpiosim.Chip(label="foobar", num_lines=16) + self.chip: Optional[gpiod.Chip] = gpiod.Chip(self.sim.dev_path) + self.info: Optional[gpiod.ChipInfo] = self.chip.get_info() def tearDown(self) -> None: + assert self.chip self.info = None self.chip.close() self.chip = None self.sim = None def test_chip_info_name(self) -> None: + assert self.sim + assert self.info self.assertEqual(self.info.name, self.sim.name) def test_chip_info_label(self) -> None: + assert self.info self.assertEqual(self.info.label, "foobar") def test_chip_info_num_lines(self) -> None: + assert self.info self.assertEqual(self.info.num_lines, 16) def test_chip_info_properties_are_immutable(self) -> None: + assert self.info with self.assertRaises(AttributeError): self.info.name = "foobar" # type: ignore[misc] diff --git a/bindings/python/tests/tests_edge_event.py b/bindings/python/tests/tests_edge_event.py index f80d6a52680c48405b935fca8e47e2a2817a2fac..fc938f0492811631a1d3855f1c41203d3bc4a4fc 100644 --- a/bindings/python/tests/tests_edge_event.py +++ b/bindings/python/tests/tests_edge_event.py @@ -5,6 +5,7 @@ import time from datetime import timedelta from functools import partial from threading import Thread +from typing import Optional from unittest import TestCase import gpiod @@ -53,8 +54,8 @@ class EdgeEventInvalidConfig(TestCase): class WaitingForEdgeEvents(TestCase): def setUp(self) -> None: - self.sim = gpiosim.Chip(num_lines=8) - self.thread = None + self.sim: Optional[gpiosim.Chip] = gpiosim.Chip(num_lines=8) + self.thread: Optional[Thread] = None def tearDown(self) -> None: if self.thread: @@ -63,6 +64,7 @@ class WaitingForEdgeEvents(TestCase): self.sim = None def trigger_falling_and_rising_edge(self, offset: int) -> None: + assert self.sim time.sleep(0.05) self.sim.set_pull(offset, Pull.UP) time.sleep(0.05) @@ -71,12 +73,14 @@ class WaitingForEdgeEvents(TestCase): def trigger_rising_edge_events_on_two_offsets( self, offset0: int, offset1: int ) -> None: + assert self.sim time.sleep(0.05) self.sim.set_pull(offset0, Pull.UP) time.sleep(0.05) self.sim.set_pull(offset1, Pull.UP) def test_both_edge_events(self) -> None: + assert self.sim with gpiod.request_lines( self.sim.dev_path, {2: gpiod.LineSettings(edge_detection=Edge.BOTH)} ) as req: @@ -104,6 +108,7 @@ class WaitingForEdgeEvents(TestCase): self.assertGreater(ts_falling, ts_rising) def test_rising_edge_event(self) -> None: + assert self.sim with gpiod.request_lines( self.sim.dev_path, {6: gpiod.LineSettings(edge_detection=Edge.RISING)} ) as req: @@ -122,6 +127,7 @@ class WaitingForEdgeEvents(TestCase): self.assertFalse(req.wait_edge_events(timedelta(microseconds=10000))) def test_falling_edge_event(self) -> None: + assert self.sim with gpiod.request_lines( self.sim.dev_path, {6: gpiod.LineSettings(edge_detection=Edge.FALLING)} ) as req: @@ -140,6 +146,7 @@ class WaitingForEdgeEvents(TestCase): self.assertFalse(req.wait_edge_events(timedelta(microseconds=10000))) def test_sequence_numbers(self) -> None: + assert self.sim with gpiod.request_lines( self.sim.dev_path, {(2, 4): gpiod.LineSettings(edge_detection=Edge.BOTH)} ) as req: diff --git a/bindings/python/tests/tests_info_event.py b/bindings/python/tests/tests_info_event.py index 1e6ab941799047c7e5383a6d0a2512c669655d19..3328335d478ff694e8b2ff3189738475af0a783e 100644 --- a/bindings/python/tests/tests_info_event.py +++ b/bindings/python/tests/tests_info_event.py @@ -7,6 +7,7 @@ import threading import time from dataclasses import FrozenInstanceError from functools import partial +from typing import Optional from unittest import TestCase import gpiod @@ -49,48 +50,60 @@ def request_reconfigure_release_line(chip_path: str, offset: int) -> None: class WatchingInfoEventWorks(TestCase): def setUp(self) -> None: - self.sim = gpiosim.Chip(num_lines=8, line_names={4: "foobar"}) - self.chip = gpiod.Chip(self.sim.dev_path) - self.thread = None + self.sim: Optional[gpiosim.Chip] = gpiosim.Chip( + num_lines=8, line_names={4: "foobar"} + ) + self.chip: Optional[gpiod.Chip] = gpiod.Chip(self.sim.dev_path) + self.thread: Optional[threading.Thread] = None def tearDown(self) -> None: if self.thread: self.thread.join() self.thread = None + assert self.chip self.chip.close() self.chip = None self.sim = None def test_watch_line_info_returns_line_info(self) -> None: + assert self.chip info = self.chip.watch_line_info(7) self.assertEqual(info.offset, 7) def test_watch_line_info_keyword_argument(self) -> None: + assert self.chip info = self.chip.watch_line_info(line=7) def test_watch_line_info_offset_out_of_range(self) -> None: + assert self.chip with self.assertRaises(ValueError): self.chip.watch_line_info(8) def test_watch_line_info_no_arguments(self) -> None: + assert self.chip with self.assertRaises(TypeError): self.chip.watch_line_info() # type: ignore[call-arg] def test_watch_line_info_by_line_name(self) -> None: + assert self.chip self.chip.watch_line_info("foobar") def test_watch_line_info_invalid_argument_type(self) -> None: + assert self.chip with self.assertRaises(TypeError): self.chip.watch_line_info(None) # type: ignore[arg-type] def test_wait_for_event_timeout(self) -> None: + assert self.chip info = self.chip.watch_line_info(7) self.assertFalse( self.chip.wait_info_event(datetime.timedelta(microseconds=10000)) ) def test_request_reconfigure_release_events(self) -> None: + assert self.chip + assert self.sim info = self.chip.watch_line_info(7) self.assertEqual(info.direction, Direction.INPUT) @@ -133,15 +146,19 @@ class WatchingInfoEventWorks(TestCase): class UnwatchingLineInfo(TestCase): def setUp(self) -> None: - self.sim = gpiosim.Chip(num_lines=8, line_names={4: "foobar"}) - self.chip = gpiod.Chip(self.sim.dev_path) + self.sim: Optional[gpiosim.Chip] = gpiosim.Chip( + num_lines=8, line_names={4: "foobar"} + ) + self.chip: Optional[gpiod.Chip] = gpiod.Chip(self.sim.dev_path) def tearDown(self) -> None: + assert self.chip self.chip.close() self.chip = None self.sim = None def test_unwatch_line_info(self) -> None: + assert self.chip self.chip.watch_line_info(0) with self.chip.request_lines(config={0: None}) as request: self.assertTrue(self.chip.wait_info_event(datetime.timedelta(seconds=1))) @@ -154,16 +171,19 @@ class UnwatchingLineInfo(TestCase): ) def test_unwatch_not_watched_line(self) -> None: + assert self.chip with self.assertRaises(OSError) as ex: self.chip.unwatch_line_info(2) self.assertEqual(ex.exception.errno, errno.EBUSY) def test_unwatch_line_info_no_argument(self) -> None: + assert self.chip with self.assertRaises(TypeError): self.chip.unwatch_line_info() # type: ignore[call-arg] def test_unwatch_line_info_by_line_name(self) -> None: + assert self.chip self.chip.watch_line_info(4) with self.chip.request_lines(config={4: None}) as request: self.assertIsNotNone(self.chip.read_info_event()) diff --git a/bindings/python/tests/tests_line_info.py b/bindings/python/tests/tests_line_info.py index 33d38a6de486447d326e8e3cb73934898ea2aba2..7215221ac1fb3b2a0730c189321cdea498da8226 100644 --- a/bindings/python/tests/tests_line_info.py +++ b/bindings/python/tests/tests_line_info.py @@ -1,6 +1,7 @@ # SPDX-License-Identifier: GPL-2.0-or-later # SPDX-FileCopyrightText: 2022 Bartosz Golaszewski +from typing import Optional from unittest import TestCase import gpiod @@ -13,38 +14,46 @@ HogDir = gpiosim.Chip.Direction class GetLineInfo(TestCase): def setUp(self) -> None: - self.sim = gpiosim.Chip( + self.sim: Optional[gpiosim.Chip] = gpiosim.Chip( num_lines=4, line_names={0: "foobar"}, ) - self.chip = gpiod.Chip(self.sim.dev_path) + self.chip: Optional[gpiod.Chip] = gpiod.Chip(self.sim.dev_path) def tearDown(self) -> None: + assert self.chip self.chip.close() self.chip = None self.sim = None def test_get_line_info_by_offset(self) -> None: + assert self.chip self.chip.get_line_info(0) def test_get_line_info_by_offset_keyword(self) -> None: + assert self.chip self.chip.get_line_info(line=0) def test_get_line_info_by_name(self) -> None: + assert self.chip self.chip.get_line_info("foobar") def test_get_line_info_by_name_keyword(self) -> None: + assert self.chip self.chip.get_line_info(line="foobar") def test_get_line_info_by_offset_string(self) -> None: + assert self.chip self.chip.get_line_info("2") def test_offset_out_of_range(self) -> None: + assert self.chip with self.assertRaises(ValueError) as ex: self.chip.get_line_info(4) def test_no_offset(self) -> None: + assert self.chip with self.assertRaises(TypeError): self.chip.get_line_info() # type: ignore[call-arg]