linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [libgpiod][PATCH 0/2] support casting line.Value to bool
@ 2024-05-22  0:46 Kent Gibson
  2024-05-22  0:46 ` [libgpiod][PATCH 1/2] bindings: python: tests: add test for " Kent Gibson
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: Kent Gibson @ 2024-05-22  0:46 UTC (permalink / raw)
  To: linux-gpio, brgl; +Cc: Kent Gibson

While writing a gpiod plugin for gpiozero (Python), I had to map line.Value
to its bool equivalent.  Casting seemed the obvious way to go, as it is
essentially a boolean, but that didn't work as I expected - it always
returned True. This is the case for any Python type that does not provide
a suitable conversion operator.

This series adds support for casting line.Value to bool.

Patch 1 adds a test that comfirms the existing behaviour.
Patch 2 adds the __bool__() operator to make the Value behave as one
might expect.

As an aside, I couldn't for the life of me work out how to run the complete
python test suite.  There are no hints in the documentation.

There is a python-tests-run target in the Makefile, but that didn't work:

~/libgpiod/bindings/python$ make python-tests-run
PYTHONPATH=/home/kent/libgpiod/bindings/python
LD_LIBRARY_PATH=/home/kent/libgpiod/lib/.libs/:\
	/home/kent/libgpiod/tests/gpiosim/.libs/ \
python3 -B -m tests
/bin/bash: line 2: /home/kent/libgpiod/tests/gpiosim/.libs/: Is a directory
make: *** [Makefile:677: python-tests-run] Error 126

I tried fixing that but I still couldn't satisfy ld wrt the gpiosim
(I don't have libgpiod installed - just using the local build),
so gave up and called this particular test directly with

$ python -m unittest tests_line.py

While that passes, I can't guarantee it hasn't caused some other
breakage, though it seems very unlikely.

Kent Gibson (2):
  bindings: python: tests: add test for casting line.Value to bool
  bindings: python: support casting line.Value to bool

 bindings/python/gpiod/line.py       |  3 +++
 bindings/python/tests/Makefile.am   |  1 +
 bindings/python/tests/tests_line.py | 11 +++++++++++
 3 files changed, 15 insertions(+)
 create mode 100644 bindings/python/tests/tests_line.py

--
2.39.2


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2024-05-23  7:55 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-05-22  0:46 [libgpiod][PATCH 0/2] support casting line.Value to bool Kent Gibson
2024-05-22  0:46 ` [libgpiod][PATCH 1/2] bindings: python: tests: add test for " Kent Gibson
2024-05-22  0:46 ` [libgpiod][PATCH 2/2] bindings: python: support " Kent Gibson
2024-05-22 16:22 ` [libgpiod][PATCH 0/2] " brgl
2024-05-22 23:57   ` Kent Gibson
2024-05-23  0:32     ` Kent Gibson
2024-05-23  7:50       ` Bartosz Golaszewski
2024-05-23  7:55 ` Bartosz Golaszewski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).