From f5f4794647e1d99d92af625f89951e638995577c Mon Sep 17 00:00:00 2001 From: Bartosz Golaszewski Date: Wed, 14 Aug 2019 14:24:29 +0200 Subject: [PATCH] bindings: python: tests: verify the errno field of OSError exceptions When a call is expected to raise the OSError exception, verify that its errno field is set to the expected value. Signed-off-by: Bartosz Golaszewski --- bindings/python/tests/gpiod_py_test.py | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/bindings/python/tests/gpiod_py_test.py b/bindings/python/tests/gpiod_py_test.py index ede1ae9..a66a227 100755 --- a/bindings/python/tests/gpiod_py_test.py +++ b/bindings/python/tests/gpiod_py_test.py @@ -417,23 +417,29 @@ class LineRequestBehavior(MockupTestCase): line = chip.get_line(3) line.request(consumer=default_consumer, type=gpiod.LINE_REQ_DIR_IN) - with self.assertRaises(OSError): + with self.assertRaises(OSError) as err_ctx: line.request(consumer=default_consumer, type=gpiod.LINE_REQ_DIR_IN) + self.assertEqual(err_ctx.exception.errno, errno.EBUSY) + def test_line_request_twice_in_bulk(self): with gpiod.Chip(mockup.chip_name(0)) as chip: lines = chip.get_lines(( 2, 3, 6, 6 )) - with self.assertRaises(OSError): + with self.assertRaises(OSError) as err_ctx: lines.request(consumer=default_consumer, type=gpiod.LINE_REQ_DIR_IN) + self.assertEqual(err_ctx.exception.errno, errno.EBUSY) + def test_use_value_unrequested(self): with gpiod.Chip(mockup.chip_name(0)) as chip: line = chip.get_line(3) - with self.assertRaises(OSError): + with self.assertRaises(OSError) as err_ctx: line.get_value() + self.assertEqual(err_ctx.exception.errno, errno.EPERM) + # # Iterator test cases # @@ -610,17 +616,21 @@ class EventFileDescriptor(MockupTestCase): def test_event_get_fd_not_requested(self): with gpiod.Chip(mockup.chip_name(0)) as chip: line = chip.get_line(3) - with self.assertRaises(OSError): + with self.assertRaises(OSError) as err_ctx: fd = line.event_get_fd(); + self.assertEqual(err_ctx.exception.errno, errno.EPERM) + def test_event_get_fd_requested_for_values(self): with gpiod.Chip(mockup.chip_name(0)) as chip: line = chip.get_line(3) line.request(consumer=default_consumer, type=gpiod.LINE_REQ_DIR_IN) - with self.assertRaises(OSError): + with self.assertRaises(OSError) as err_ctx: fd = line.event_get_fd(); + self.assertEqual(err_ctx.exception.errno, errno.EPERM) + def test_event_fd_polling(self): with EventThread(0, 2, 200): with gpiod.Chip(mockup.chip_name(0)) as chip: -- 2.30.2