On Wed, May 22, 2024 at 09:22:50AM -0700, brgl@xxxxxxxx wrote: > On Wed, 22 May 2024 02:46:41 +0200, Kent Gibson <warthog618@xxxxxxxxx> said: > > 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. > > > > Ha! Interesting. Do you think we may need it anywhere else too? > I guess the same applies to the C++ and Rust bindings - I'll have to check. > > 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 > > > > I typically run it like this: > > PYTHONPATH=./bindings/python > LD_LIBRARY_PATH=./lib/.libs/:./tests/gpiosim/.libs/:bindings/python/ > python -B -m tests > So a one-liner? That gives me: $ PYTHONPATH=./bindings/python LD_LIBRARY_PATH=./lib/.libs/:./tests/gpiosim/.libs/:bindings/python/ python3 -B -m tests Traceback (most recent call last): File "<frozen runpy>", line 198, in _run_module_as_main File "<frozen runpy>", line 88, in _run_code File "/home/kent/libgpiod/bindings/python/tests/__main__.py", line 7, in <module> from .tests_chip import * File "/home/kent/libgpiod/bindings/python/tests/tests_chip.py", line 8, in <module> from . import gpiosim File "/home/kent/libgpiod/bindings/python/tests/gpiosim/__init__.py", line 4, in <module> from .chip import Chip File "/home/kent/libgpiod/bindings/python/tests/gpiosim/chip.py", line 4, in <module> from . import _ext FileNotFoundError: [Errno 2] No such file or directory That might also be as far as I got previously - I may've been mis-remembering that the final hurdle was an import error, not an ld issue, though both are looking for a module they can't find, so basically the same thing. Cheers, Kent.