1
0
mirror of https://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git synced 2026-10-28 13:55:08 +03:00

16 Commits

Author SHA1 Message Date
Bartosz Golaszewski
ba8ee34516 bindings: python: bail-out if the line was not found in gpiofind.py
Currently we're not checking if the object returned from
gpiod.fine_line() is None which results in an attribute error being
raised when we try to call line methods on a non-line object.

Add an if and bail-out with an error code if the line with given name
was not found.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
2018-07-31 14:40:09 +02:00
Bartosz Golaszewski
cdf5ef94c4 bindings: python: fix gpiod_Chip_find_lines() for nonexistent lines
Currently if we call gpiod_Chip_find_lines() with some names that
cannot be looked up, we end up getting an exception from the LineBulk
object's constructor (because None is not a Line and LineBulk can only
hold Line objects).

Fix the behavior of gpiod_Chip_find_lines() for nonexistent lines by
raising an explicit exception if the underlying gpiod_Chip_find_line()
call returns None. Also: add a relevant test case.

Fixes: 96c524c495 ("bindings: implement python bindings")
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
2018-07-31 14:30:46 +02:00
Bartosz Golaszewski
1d87088b1e bindings: python: examples: close chip objects where needed
Unlike the C++ bindings: we can't expect the python runtime to call
the Chip object's destructor when all references are dropped. We need
to close each chip explicitly. Either call the close() method directly
or use controlled execution in all examples.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
2018-07-31 14:30:46 +02:00
Bartosz Golaszewski
445793aabf bindings: python: examples: new test case
Add a test case for incorrect number of default values in line
requests.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
2018-07-22 20:14:50 +02:00
Bartosz Golaszewski
e03e802add bindings: python: add test cases for default values in line requests
Add two new tests verifying the default_vals argument in line requests
for single and multiple lines.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
2018-07-20 10:35:35 +02:00
Bartosz Golaszewski
a610c5077e bindings: python: examples: remove unnecessary import
We no longer need sys in gpiod_tests.py. Remove it.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
2018-07-13 19:47:37 +02:00
Bartosz Golaszewski
ce2853562e bindings: python: examples: don't use sys.argv[0] as consumer string
Strings with slashes trigger a warning in the kernel in
fs/proc/generic.c. Use a hardcoded consumer string.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
2018-07-13 16:01:06 +02:00
Bartosz Golaszewski
e421f0d776 bindings: python: add a test case for line_event's __repr__
Check if an event's representation string is generated correctly.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
2018-06-07 09:25:48 +02:00
Bartosz Golaszewski
2dfb43260a bindings: python: add support for controlled execution
Provide __enter__ and __exit__ callbacks for Chip so that it can be
used with the 'with' statement.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
2018-05-16 12:29:17 +02:00
Bartosz Golaszewski
e04d4d45c2 bindings: python: provide better resource control
So far we rely on cpython's reference counting for closing the GPIO
chips and freeing the underlying resources. This is however wrong.
Python doesn't guarantee anything regarding the lifetime of an object.

Provide a method for closing the underlying chip handle and add
relevant checks to all methods using the resources associated with
a GPIO chip, so that we raise an error should the user use a chip
after closing it.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
2018-05-16 12:01:45 +02:00
Bartosz Golaszewski
7cc5304f33 bindings: python: provide gpiod.version_string()
Implement a python wrapper around gpiod_version_string().

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
2018-05-16 10:39:11 +02:00
Bartosz Golaszewski
3107d63692 bindings: python: test case for line flags
Add a new test case verifying that line flags work as expected.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
2018-05-15 18:35:16 +02:00
Bartosz Golaszewski
345d408836 bindings: python: improve readability in test cases
Mostly just add new lines for improved readability.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
2018-05-15 18:13:36 +02:00
Bartosz Golaszewski
0596dfb0b5 bindings: python: new test cases/examples
Add more test cases/code examples for python bindings.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
2018-05-15 14:51:00 +02:00
Bartosz Golaszewski
2df328e989 bindings: python: extend tests
Add more test cases/examples, implement some helper functions, tweak
the output messages, mention the need for a dummy chip in the system
in the module's pydoc string.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
2018-05-14 12:01:13 +02:00
Bartosz Golaszewski
96c524c495 bindings: implement python bindings
Create a C extension module wrapping the functionality of libgpiod
in a set of Python classes.

Add code examples including simplified reimplementations of gpio-tools
in Python.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
2018-04-17 10:19:34 +02:00