From patchwork Wed May 22 00:46:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kent Gibson X-Patchwork-Id: 799022 Received: from mail-oa1-f44.google.com (mail-oa1-f44.google.com [209.85.160.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4FEF917F3 for ; Wed, 22 May 2024 00:47:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716338834; cv=none; b=lkokSov4r62VNmab4zSdpzHJ+omGXpxK/rj8JO8pUYm6yDLvg+kfi161xYwfZhXxjqI/3Twheqvs28SkreClcEEOjs0ZURlqi6yu06HoNB9Thk1P7Odbd3BJsLs2Rkkq+mMI7I/Iy0SOyGyxRHiRGjVnV4Q+KuojfNE1u9e2dkY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716338834; c=relaxed/simple; bh=U+qb/7NUGmaaqm/cwxdz3GdDmrX34nI/tJwNaILIpzE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Rs0fhL7g1wk2tdskXxLtOFHXkBJGlJt86AA2zIs/knlxNxIQEQWNTyfKNRay3dCvozRH/Ldtuxp1fJ8xoph+juA184uvgvRuaxiDDf1RXQF5ZPoPFuS1fP22W/0TwWPJU3J3KhOw1GOYzxjVhA/oGdgxCFmZOM7eTDBKswuNML0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=ZpAe7v2R; arc=none smtp.client-ip=209.85.160.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ZpAe7v2R" Received: by mail-oa1-f44.google.com with SMTP id 586e51a60fabf-24c0dbd2866so1433819fac.0 for ; Tue, 21 May 2024 17:47:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1716338832; x=1716943632; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=A12K4rpwI7fiEuQ/0HQSvwY/yqZqmCQDFLukUYTEfc4=; b=ZpAe7v2RuhyXXAi3T8DWtvfaMYegFmG+oPT7YbU8ojHhcyJj5TwygrIa5ALYnl+9T5 G8wr1h2wU4GvQzOFLBWmTf4d9C/rkra3Quu4Z+rLCIcot75Z2O048nbOhXr0JrS1n+v5 1WncZ0ZgA3LTnbB7jgky8SpXb8jSbJxoKdOXaBgXb9B19kmoPgbf2VUdZgajfBWGGjPP bafo7+Bb++vMkBoQPGjHx8JxHrEZXSjxGNvULh9XFPorFCRoQB7K0cN4Zjt2Re6MMKAB By8kgngSg8HJLziAsSWopEsHI3oIGZp6kD79isDwdO/5tb7mDfr79utdar96SmPErXz1 13uQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716338832; x=1716943632; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=A12K4rpwI7fiEuQ/0HQSvwY/yqZqmCQDFLukUYTEfc4=; b=cwRn9/oUhQO6T5YFoCVP9e/4EwhKfsS7F4tCHTghDEkMYqa3ImMJGtpc8pGFNkV4C8 FMEh8my59LYVhMdks629Mr4Q3/63hJtsQCgELnzqSvTcTh7Cx1aH/KHxyX7G3JdDMRxk rgNmYdfN3Oflh6jiTpmPWZbYt62JRJ3+XDsHFN6QbvJeR3yLy8AGB0xYLW1zkRfqVt+5 Ga2wPG9NAiXuGdPe+HtVoZg2J8qlT9wmA1gHk6XXq0pAAQIueM889OYh9ADqGsVsbYUs mljGcGnQ+7ncSEWKMT+7XgZxjolchD2z2hsl1C6mLwQ/TDUdQ6OK9xrbUc+YfZl122yT 0+Aw== X-Gm-Message-State: AOJu0YwkAikuaq36ssc9+M75l3b1HfEXy/XoNTDwq5MKb5roY7/I4kGQ t2amJ6RkMSh0e3+fEiHTdCB6y7NzzR0LeKZ46jfCPYuxet4r1v34NsPlag== X-Google-Smtp-Source: AGHT+IGGYvofGLDmjFBKqlf35NlX4URPUDBPxH7SZCLI3yF9EhIWcC7QBETr1W9deMYe7Ql9BhtXfg== X-Received: by 2002:a05:6870:b601:b0:23c:a69b:645b with SMTP id 586e51a60fabf-24c68adabaamr748652fac.14.1716338831334; Tue, 21 May 2024 17:47:11 -0700 (PDT) Received: from rigel.home.arpa (60-241-107-82.static.tpgi.com.au. [60.241.107.82]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-6f4d2af2c36sm22066302b3a.173.2024.05.21.17.47.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 May 2024 17:47:11 -0700 (PDT) From: Kent Gibson To: linux-gpio@vger.kernel.org, brgl@bgdev.pl Cc: Kent Gibson Subject: [libgpiod][PATCH 1/2] bindings: python: tests: add test for casting line.Value to bool Date: Wed, 22 May 2024 08:46:42 +0800 Message-Id: <20240522004643.96863-2-warthog618@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240522004643.96863-1-warthog618@gmail.com> References: <20240522004643.96863-1-warthog618@gmail.com> Precedence: bulk X-Mailing-List: linux-gpio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The line.Value represents the logical line state, so intuitively you would expect it to be able to be cast to bool, with ACTIVE corresponding to True, and INACTIVE to False. Add a test that line.Value can be cast to bool. Signed-off-by: Kent Gibson --- bindings/python/tests/Makefile.am | 1 + bindings/python/tests/tests_line.py | 11 +++++++++++ 2 files changed, 12 insertions(+) create mode 100644 bindings/python/tests/tests_line.py diff --git a/bindings/python/tests/Makefile.am b/bindings/python/tests/Makefile.am index c89241e..3118d5f 100644 --- a/bindings/python/tests/Makefile.am +++ b/bindings/python/tests/Makefile.am @@ -11,6 +11,7 @@ EXTRA_DIST = \ tests_chip.py \ tests_edge_event.py \ tests_info_event.py \ + tests_line.py \ tests_line_info.py \ tests_line_request.py \ tests_line_settings.py \ diff --git a/bindings/python/tests/tests_line.py b/bindings/python/tests/tests_line.py new file mode 100644 index 0000000..70aa09b --- /dev/null +++ b/bindings/python/tests/tests_line.py @@ -0,0 +1,11 @@ +# SPDX-License-Identifier: LGPL-2.1-or-later +# SPDX-FileCopyrightText: 2024 Kent Gibson + +from gpiod.line import Value +from unittest import TestCase + + +class LineValue(TestCase): + def test_cast_bool(self): + self.assertTrue(bool(Value.ACTIVE)) + self.assertFalse(bool(Value.INACTIVE)) From patchwork Wed May 22 00:46:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kent Gibson X-Patchwork-Id: 798252 Received: from mail-oi1-f170.google.com (mail-oi1-f170.google.com [209.85.167.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 263FD17F3 for ; Wed, 22 May 2024 00:47:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716338843; cv=none; b=cXKhrEg1f12uwuIku6s0/PUfGAjgEdY/tQ1xr5+c9ITE3QsM6RY8XV8M80PyCc8vyiGKtkuG1gpgZjJP1mlTlX0cCO08t7ZZ5MFKN4igSe5v9QRulQqbGf1bltviDDx8ANGqi1kVnLJ2TVRp9fL3ZlhakWfS0v7H7VPagLHSQog= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716338843; c=relaxed/simple; bh=n4WM0inoYP5e6tnqlSYqVmwOg9f3zNOZzwSHGIgLTRY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=KsgNJA1jjsT6fiH4KMtyEAzbLnFKvUtLHTHVhyqPyCOuxuifTmbEuhp3OQn5nGPTqkKTin3+2G66w811FrBTMwWyuRDSKd4GCdjsTVUse5BjAa3pR9eO5l/JFscVXJXQIwLQKLBps1Sukf5R+ZrAdMBiJIV/S59aF2yz/Ueh5a0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=RL1+OoRc; arc=none smtp.client-ip=209.85.167.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="RL1+OoRc" Received: by mail-oi1-f170.google.com with SMTP id 5614622812f47-3c99257e0cbso2503217b6e.3 for ; Tue, 21 May 2024 17:47:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1716338841; x=1716943641; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Fy36U9EGP1XWWTkLDr1/cKH5m04PRzmxJGh+lK+WQuI=; b=RL1+OoRcdJtHXbvjLWu7IFwINljQbs15+yvH5fFLIX78iq1J/NzoJrNMFGtj0IKCoC +Q72wVYrecqGTwKaX+eDBwM0iWYmkBlCYj+tsZNxEunPo/rP1L3eAhfLJJoSuB4O2KVj Qqa65c7ULVdRMg/vPnVBvA06tkKyO8kpcxzHPdb9nnwKE0msg8tkfyqvpDFmYvRQ8qY4 YbV3SK63BhYAI+oxyjtwrsIJxwJq5kyM9QgNmqT2shxZxNffyFawSu2sgBalwPyCgCPr tpqX77RIIBezIbFfxqhv69BkWOXzl/xDnsYP47iElJVfGvo9RMGy2eR3pyGWwD7fOHkf eKAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716338841; x=1716943641; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Fy36U9EGP1XWWTkLDr1/cKH5m04PRzmxJGh+lK+WQuI=; b=SbAtDSr6/BH49UmFcD9YilZ3HdhD8rIQg+fBkpAydxdgd81qAcOH969QK8VDJ2fhUw UYAX1tMLBaA4JPSQ5qt9Ud0Mj+ikYGqM5erIwR/tTYSRBMjiamY4VDA+iITNaAUpXkbG 0UyPkPkcUcANz76wvdWJ8EwVErYHFTIdQYhTvi+wUFQseS/7Fku+szzDCaBmGIW+RHTP YpXpQFEPWS3LZU2fBRToeIdTTMB3q95vK5OleY6Of7azLGNzf9Mxn7AUIXI/KEMGlicT tOG/r9cpEm9xsE86SwTgi1iEvioxT/iD1zs+Ks/fYufNS6XVPI0zJK4+K+fgHLYoQEY7 CCRQ== X-Gm-Message-State: AOJu0YwDX4gp85vIhsLkoUBQvXgLekYTbraqj8LURwydOVyHK9aJMesy njJniyPKHisLZKD0L9G1BAAKKbrQFOUyVxOuMEcRNuRlbnwAQG4fgaH1RA== X-Google-Smtp-Source: AGHT+IFMf6H0aL/oXisWPpq041o7IIY9gC/QQl6kNyjIhpXJ7HcLrAuqV0vMsmFpmptm92e7eDsiQQ== X-Received: by 2002:a05:6358:5d86:b0:192:4dd2:2b49 with SMTP id e5c5f4694b2df-19791ddc7f5mr47940355d.4.1716338841064; Tue, 21 May 2024 17:47:21 -0700 (PDT) Received: from rigel.home.arpa (60-241-107-82.static.tpgi.com.au. [60.241.107.82]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-6f4d2af2c36sm22066302b3a.173.2024.05.21.17.47.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 May 2024 17:47:20 -0700 (PDT) From: Kent Gibson To: linux-gpio@vger.kernel.org, brgl@bgdev.pl Cc: Kent Gibson Subject: [libgpiod][PATCH 2/2] bindings: python: support casting line.Value to bool Date: Wed, 22 May 2024 08:46:43 +0800 Message-Id: <20240522004643.96863-3-warthog618@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240522004643.96863-1-warthog618@gmail.com> References: <20240522004643.96863-1-warthog618@gmail.com> Precedence: bulk X-Mailing-List: linux-gpio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Python types default to being truthy when cast to bool, so casting line.Value to bool always returns True. Add a line.Value.__bool__() operator to map the line value to bool as one would intuitively expect, so ACTIVE is True and INACTIVE is False. Signed-off-by: Kent Gibson --- bindings/python/gpiod/line.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/bindings/python/gpiod/line.py b/bindings/python/gpiod/line.py index 1cc512f..d088fb4 100644 --- a/bindings/python/gpiod/line.py +++ b/bindings/python/gpiod/line.py @@ -14,6 +14,9 @@ class Value(Enum): INACTIVE = _ext.VALUE_INACTIVE ACTIVE = _ext.VALUE_ACTIVE + def __bool__(self): + return self == self.ACTIVE + class Direction(Enum): """Direction settings."""