bindings: python: tests: verify the errno field of OSError exceptions
authorBartosz Golaszewski <bgolaszewski@baylibre.com>
Wed, 14 Aug 2019 12:24:29 +0000 (14:24 +0200)
committerBartosz Golaszewski <bgolaszewski@baylibre.com>
Wed, 14 Aug 2019 12:24:29 +0000 (14:24 +0200)
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 <bgolaszewski@baylibre.com>
bindings/python/tests/gpiod_py_test.py

index ede1ae9f34bddfd09ea846fd4099c2d1d587ecc3..a66a22739113e4029c6daafbc2843a4a9d42c841 100755 (executable)
@@ -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: