1
0
mirror of https://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git synced 2026-10-25 12:39:18 +03:00
Files
libgpiod/bindings/python/tests/tests_chip_info.py
Bartosz Golaszewski b7ba732e6a treewide: libgpiod v2 implementation
This commit is the result of a squash of all the commits created during
the development of libgpiod v2. This is done to preserve bisectability
of the git tree. It contains significant re-writes of the core C library
as well as C++ and python bindings. The tools have been adjusted to work
with the new API but have not undergone significant changes yet.

This commit contains the bulk of the work on libgpiod v2 but the
development continues with more changes planned.

Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>
[Ben: fix format specifier for uint64_t]
Signed-off-by: Ben Hutchings <ben.hutchings@mind.be>
[Viresh: Fix ioctl number for gpiod_line_request_reconfigure_lines()]
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
[Kent: bug fixes, improvements, better pointer contracts, type strictness]
Signed-off-by: Kent Gibson <warthog618@gmail.com>
2022-10-31 11:15:14 +01:00

53 lines
1.4 KiB
Python

# SPDX-License-Identifier: GPL-2.0-or-later
# SPDX-FileCopyrightText: 2022 Bartosz Golaszewski <brgl@bgdev.pl>
import gpiod
from . import gpiosim
from unittest import TestCase
class ChipInfoProperties(TestCase):
def setUp(self):
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):
self.info = None
self.chip.close()
self.chip = None
self.sim = None
def test_chip_info_name(self):
self.assertEqual(self.info.name, self.sim.name)
def test_chip_info_label(self):
self.assertEqual(self.info.label, "foobar")
def test_chip_info_num_lines(self):
self.assertEqual(self.info.num_lines, 16)
def test_chip_info_properties_are_immutable(self):
with self.assertRaises(AttributeError):
self.info.name = "foobar"
with self.assertRaises(AttributeError):
self.info.num_lines = 4
with self.assertRaises(AttributeError):
self.info.label = "foobar"
class ChipInfoStringRepresentation(TestCase):
def test_chip_info_str(self):
sim = gpiosim.Chip(label="foobar", num_lines=16)
with gpiod.Chip(sim.dev_path) as chip:
info = chip.get_info()
self.assertEqual(
str(info),
'<ChipInfo name="{}" label="foobar" num_lines=16>'.format(sim.name),
)