Browse Source

increase test coverage of cc1101/_gpio.py

Fabian Peter Hammerle 10 months ago
parent
commit
b7a9e955db
2 changed files with 22 additions and 1 deletions
  1. 1 1
      .github/workflows/python.yml
  2. 21 0
      tests/test_gpio.py

+ 1 - 1
.github/workflows/python.yml

@@ -57,7 +57,7 @@ jobs:
       env:
         PYTHON_VERSION: ${{ matrix.python-version }}
     - run: pipenv graph
-    - run: pipenv run pytest --cov="$(cat *.egg-info/top_level.txt)" --cov-report=term-missing --cov-fail-under=94
+    - run: pipenv run pytest --cov="$(cat *.egg-info/top_level.txt)" --cov-report=term-missing --cov-fail-under=95
     - run: pipenv run pylint "$(cat *.egg-info/top_level.txt)"
     # https://github.com/PyCQA/pylint/issues/352
     - run: pipenv run pylint tests/*

+ 21 - 0
tests/test_gpio.py

@@ -37,6 +37,14 @@ def test__load_libgpiod():
     find_library_mock.assert_called_once_with("gpiod")
 
 
+def test_load_libgpiod_not_found():
+    cc1101._gpio._load_libgpiod.cache_clear()
+    with unittest.mock.patch(
+        "ctypes.util.find_library", return_value=None
+    ), pytest.raises(FileNotFoundError):
+        cc1101._gpio._load_libgpiod()
+
+
 @pytest.mark.parametrize("name", ("GPIO24", "GPIO25"))
 def test_line_find_permission_denied(libgpiod_mock, name):
     libgpiod_mock.gpiod_line_find.return_value = 0
@@ -126,3 +134,16 @@ def test_line_wait_for_rising_edge_busy(
         line.wait_for_rising_edge(
             consumer=consumer, timeout=datetime.timedelta(seconds=timeout_seconds)
         )
+
+
+def test_line_wait_for_rising_edge_wait_failed(libgpiod_mock) -> None:
+    line = cc1101._gpio.GPIOLine(pointer=ctypes.c_void_p(42 // 2))
+    libgpiod_mock.gpiod_line_request_rising_edge_events.return_value = 0
+    # "0 if wait timed out, -1 if an error occurred, 1 if an event occurred."
+    libgpiod_mock.gpiod_line_event_wait.return_value = -1
+    with pytest.raises(
+        OSError, match="^Failed to wait for rising edge event notification.$"
+    ):
+        line.wait_for_rising_edge(
+            consumer=b"test", timeout=datetime.timedelta(seconds=1)
+        )