|
@@ -139,11 +139,11 @@ def test_unlock_spi_device_no_lock(spidev_mock):
|
|
transceiver.unlock_spi_device()
|
|
transceiver.unlock_spi_device()
|
|
|
|
|
|
|
|
|
|
-def test_unlock_on_exception(spidev_mock):
|
|
+def test_unlock_on_exception_within_context(spidev_mock):
|
|
|
|
+ with unittest.mock.patch("spidev.SpiDev", spidev_mock):
|
|
|
|
+ transceiver1 = cc1101.CC1101(lock_spi_device=True)
|
|
|
|
+ transceiver2 = cc1101.CC1101(lock_spi_device=True)
|
|
with _mock_hardware_access():
|
|
with _mock_hardware_access():
|
|
- with unittest.mock.patch("spidev.SpiDev", spidev_mock):
|
|
|
|
- transceiver1 = cc1101.CC1101(lock_spi_device=True)
|
|
|
|
- transceiver2 = cc1101.CC1101(lock_spi_device=True)
|
|
|
|
with pytest.raises(ValueError, match=r"^test$"):
|
|
with pytest.raises(ValueError, match=r"^test$"):
|
|
with transceiver1:
|
|
with transceiver1:
|
|
raise ValueError("test")
|
|
raise ValueError("test")
|
|
@@ -158,3 +158,26 @@ def test_unlock_on_exception(spidev_mock):
|
|
with pytest.raises(BlockingIOError):
|
|
with pytest.raises(BlockingIOError):
|
|
with transceiver1:
|
|
with transceiver1:
|
|
pass
|
|
pass
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+def test_unlock_on_exception_when_entering_context(spidev_mock):
|
|
|
|
+ with unittest.mock.patch("spidev.SpiDev", spidev_mock):
|
|
|
|
+ transceiver1 = cc1101.CC1101(lock_spi_device=True)
|
|
|
|
+ transceiver2 = cc1101.CC1101(lock_spi_device=True)
|
|
|
|
+ with _mock_hardware_access():
|
|
|
|
+ with unittest.mock.patch.object(
|
|
|
|
+ cc1101.CC1101, "_verify_chip", side_effect=ValueError("test")
|
|
|
|
+ ), pytest.raises(ValueError, match=r"^test$"):
|
|
|
|
+ with transceiver1:
|
|
|
|
+ pass
|
|
|
|
+ with transceiver2:
|
|
|
|
+ pass
|
|
|
|
+
|
|
|
|
+ with transceiver1:
|
|
|
|
+ with pytest.raises(BlockingIOError):
|
|
|
|
+ with transceiver2:
|
|
|
|
+ pass
|
|
|
|
+ with transceiver2:
|
|
|
|
+ with pytest.raises(BlockingIOError):
|
|
|
|
+ with transceiver1:
|
|
|
|
+ pass
|