bindings: python: tests: ignore purposeful type errors
authorVincent Fazio <vfazio@xes-inc.com>
Thu, 14 Nov 2024 14:51:14 +0000 (08:51 -0600)
committerBartosz Golaszewski <bartosz.golaszewski@linaro.org>
Tue, 19 Nov 2024 14:23:58 +0000 (15:23 +0100)
Some of the unit tests intentionally call methods or assign properties
with invalid values to ensure they fail in an expected way.

Type checkers complain for these instances so inform them via directive
that these lines should be ignore for specific errors.

Additionally, some lines that access properties without assigning the
value look like they perform no action to linters.

To appease the linter, read the value into a throw-away variable.

Signed-off-by: Vincent Fazio <vfazio@xes-inc.com>
Link: https://lore.kernel.org/r/20241114145116.2123714-22-vfazio@xes-inc.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
bindings/python/tests/tests_chip.py
bindings/python/tests/tests_chip_info.py
bindings/python/tests/tests_info_event.py
bindings/python/tests/tests_line_info.py
bindings/python/tests/tests_line_request.py
bindings/python/tests/tests_module.py

index 218f238c699c6bc5b76305324f3ccd0116fb7b15..9b31e306e92aab3edd080917d0cab8e894dcf352 100644 (file)
@@ -52,11 +52,11 @@ class ChipConstructor(TestCase):
 
     def test_missing_path(self) -> None:
         with self.assertRaises(TypeError):
-            gpiod.Chip()
+            gpiod.Chip()  # type: ignore[call-arg]
 
     def test_invalid_type_for_path(self) -> None:
         with self.assertRaises(TypeError):
-            gpiod.Chip(4)
+            gpiod.Chip(4)  # type: ignore[arg-type]
 
 
 class ChipBooleanConversion(TestCase):
@@ -85,10 +85,10 @@ class ChipProperties(TestCase):
 
     def test_properties_are_immutable(self) -> None:
         with self.assertRaises(AttributeError):
-            self.chip.path = "foobar"
+            self.chip.path = "foobar"  # type: ignore[misc]
 
         with self.assertRaises(AttributeError):
-            self.chip.fd = 4
+            self.chip.fd = 4  # type: ignore[misc]
 
 
 class ChipDevPathFromLink(TestCase):
@@ -172,7 +172,7 @@ class ClosedChipCannotBeUsed(TestCase):
         chip.close()
 
         with self.assertRaises(gpiod.ChipClosedError):
-            chip.path
+            _ = chip.path
 
     def test_close_chip_and_try_controlled_execution(self) -> None:
         sim = gpiosim.Chip()
@@ -182,7 +182,7 @@ class ClosedChipCannotBeUsed(TestCase):
 
         with self.assertRaises(gpiod.ChipClosedError):
             with chip:
-                chip.fd
+                _ = chip.fd
 
     def test_close_chip_twice(self) -> None:
         sim = gpiosim.Chip(label="foobar")
index aabfbeeb41de5c1303ddb8db452aca6cd4ef00f9..fdceda9df949778e6b6a8b3e4c6af144801b7e5d 100644 (file)
@@ -31,13 +31,13 @@ class ChipInfoProperties(TestCase):
 
     def test_chip_info_properties_are_immutable(self) -> None:
         with self.assertRaises(AttributeError):
-            self.info.name = "foobar"
+            self.info.name = "foobar"  # type: ignore[misc]
 
         with self.assertRaises(AttributeError):
-            self.info.num_lines = 4
+            self.info.num_lines = 4  # type: ignore[misc]
 
         with self.assertRaises(AttributeError):
-            self.info.label = "foobar"
+            self.info.label = "foobar"  # type: ignore[misc]
 
 
 class ChipInfoStringRepresentation(TestCase):
index 100564702e96336b2ea6641ce3de29c1f02e3c00..e726a545096fdac946dd42855f44ce4822f7a8a1 100644 (file)
@@ -29,13 +29,13 @@ class InfoEventDataclassBehavior(TestCase):
                 event = chip.read_info_event()
 
                 with self.assertRaises(FrozenInstanceError):
-                    event.event_type = 4
+                    event.event_type = 4  # type: ignore[misc, assignment]
 
                 with self.assertRaises(FrozenInstanceError):
-                    event.timestamp_ns = 4
+                    event.timestamp_ns = 4  # type: ignore[misc]
 
                 with self.assertRaises(FrozenInstanceError):
-                    event.line_info = 4
+                    event.line_info = 4  # type: ignore[misc, assignment]
 
 
 def request_reconfigure_release_line(chip_path: str, offset: int) -> None:
@@ -76,14 +76,14 @@ class WatchingInfoEventWorks(TestCase):
 
     def test_watch_line_info_no_arguments(self) -> None:
         with self.assertRaises(TypeError):
-            self.chip.watch_line_info()
+            self.chip.watch_line_info()  # type: ignore[call-arg]
 
     def test_watch_line_info_by_line_name(self) -> None:
         self.chip.watch_line_info("foobar")
 
     def test_watch_line_info_invalid_argument_type(self) -> None:
         with self.assertRaises(TypeError):
-            self.chip.watch_line_info(None)
+            self.chip.watch_line_info(None)  # type: ignore[arg-type]
 
     def test_wait_for_event_timeout(self) -> None:
         info = self.chip.watch_line_info(7)
@@ -162,7 +162,7 @@ class UnwatchingLineInfo(TestCase):
 
     def test_unwatch_line_info_no_argument(self) -> None:
         with self.assertRaises(TypeError):
-            self.chip.unwatch_line_info()
+            self.chip.unwatch_line_info()  # type: ignore[call-arg]
 
     def test_unwatch_line_info_by_line_name(self) -> None:
         self.chip.watch_line_info(4)
index 7bc244dfea2c58db15ac5a80b021d9b9d1af618c..5eb6cd526df88234ba9a71e7299bb0e7f1da87a4 100644 (file)
@@ -46,7 +46,7 @@ class GetLineInfo(TestCase):
 
     def test_no_offset(self) -> None:
         with self.assertRaises(TypeError):
-            self.chip.get_line_info()
+            self.chip.get_line_info()  # type: ignore[call-arg]
 
 
 class LinePropertiesCanBeRead(TestCase):
index 76edb1d273f103c1b2f72974f5364728f121b05b..bae8815b98654145c26071c4fc40816469313192 100644 (file)
@@ -24,10 +24,10 @@ class ChipLineRequestsBehaveCorrectlyWithInvalidArguments(TestCase):
 
     def test_passing_invalid_types_as_configs(self) -> None:
         with self.assertRaises(AttributeError):
-            self.chip.request_lines("foobar")
+            self.chip.request_lines("foobar")  # type: ignore[arg-type]
 
         with self.assertRaises(AttributeError):
-            self.chip.request_lines(None, "foobar")
+            self.chip.request_lines(None, "foobar")  # type: ignore[arg-type]
 
     def test_offset_out_of_range(self) -> None:
         with self.assertRaises(ValueError):
@@ -39,7 +39,7 @@ class ChipLineRequestsBehaveCorrectlyWithInvalidArguments(TestCase):
 
     def test_request_no_arguments(self) -> None:
         with self.assertRaises(TypeError):
-            self.chip.request_lines()
+            self.chip.request_lines()  # type: ignore[call-arg]
 
 
 class ModuleLineRequestsBehaveCorrectlyWithInvalidArguments(TestCase):
@@ -51,10 +51,10 @@ class ModuleLineRequestsBehaveCorrectlyWithInvalidArguments(TestCase):
 
     def test_passing_invalid_types_as_configs(self) -> None:
         with self.assertRaises(AttributeError):
-            gpiod.request_lines(self.sim.dev_path, "foobar")
+            gpiod.request_lines(self.sim.dev_path, "foobar")  # type: ignore[arg-type]
 
         with self.assertRaises(AttributeError):
-            gpiod.request_lines(self.sim.dev_path, None, "foobar")
+            gpiod.request_lines(self.sim.dev_path, None, "foobar")  # type: ignore[arg-type]
 
     def test_offset_out_of_range(self) -> None:
         with self.assertRaises(ValueError):
@@ -66,7 +66,7 @@ class ModuleLineRequestsBehaveCorrectlyWithInvalidArguments(TestCase):
 
     def test_request_no_arguments(self) -> None:
         with self.assertRaises(TypeError):
-            gpiod.request_lines()
+            gpiod.request_lines()  # type: ignore[call-arg]
 
 
 class ChipLineRequestWorks(TestCase):
@@ -200,7 +200,7 @@ class LineRequestGettingValues(TestCase):
 
     def test_get_values_invalid_argument_type(self) -> None:
         with self.assertRaises(TypeError):
-            self.req.get_values(True)
+            self.req.get_values(True)  # type: ignore[arg-type]
 
 
 class LineRequestGettingValuesByName(TestCase):
@@ -602,7 +602,7 @@ class ReleasedLineRequestCannotBeUsed(TestCase):
             req.release()
 
             with self.assertRaises(gpiod.RequestReleasedError):
-                req.fd
+                _ = req.fd
 
 
 class LineRequestSurvivesParentChip(TestCase):
index 2718624c7e0dd41259c7006e37d48f52cc279b1d..efd49db59e6567b9bc5ee0096ccce3281ac466f3 100644 (file)
@@ -17,15 +17,15 @@ class IsGPIOChip(TestCase):
 
     def test_is_gpiochip_invalid_argument(self) -> None:
         with self.assertRaises(TypeError):
-            gpiod.is_gpiochip_device(4)
+            gpiod.is_gpiochip_device(4)  # type: ignore[arg-type]
 
     def test_is_gpiochip_superfluous_argument(self) -> None:
         with self.assertRaises(TypeError):
-            gpiod.is_gpiochip_device("/dev/null", 4)
+            gpiod.is_gpiochip_device("/dev/null", 4)  # type: ignore[call-arg]
 
     def test_is_gpiochip_missing_argument(self) -> None:
         with self.assertRaises(TypeError):
-            gpiod.is_gpiochip_device()
+            gpiod.is_gpiochip_device()  # type: ignore[call-arg]
 
     def test_is_gpiochip_good(self) -> None:
         sim = gpiosim.Chip()