Skip to content

Commit eebbd7e

Browse files
committed
test(MOCKS): simplify patched mocks
1 parent fcc2503 commit eebbd7e

File tree

3 files changed

+18
-12
lines changed

3 files changed

+18
-12
lines changed

pi_portal/modules/configuration/tests/test_user_config.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ def setUp(self) -> None:
5858

5959
@mock.patch(
6060
json_file.__name__ + ".JSONFileReader.load_json_file",
61-
return_value=MOCK_JSON
61+
mock.Mock(return_value=MOCK_JSON)
6262
)
63-
def test_load(self, _: mock.Mock) -> None:
63+
def test_load(self) -> None:
6464
with mock.patch.object(self.configuration, 'validate') as m_validate:
6565
self.configuration.load()
6666
self.assertEqual(self.configuration.user_config, MOCK_JSON)

pi_portal/modules/integrations/gpio/components/bases/tests/test_monitor.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ def setUpClass(cls) -> None:
3030
cls.test_class = concrete_monitor.ConcreteGPIOMonitor
3131

3232
@gpio_loop.patch_gpio_loop(monitor.__name__ + ".GPIOMonitorBase")
33-
@mock.patch(monitor.__name__ + ".RPi.GPIO")
34-
def test_loop_no_change(self, _: mock.Mock) -> None:
33+
@mock.patch(monitor.__name__ + ".RPi.GPIO", mock.Mock())
34+
def test_loop_no_change(self) -> None:
3535

3636
with gpio_change.patch_gpio_input_change(self.instance.gpio_pins, False):
3737
mock_logger_message = "No New Messages"
@@ -46,8 +46,8 @@ def test_loop_no_change(self, _: mock.Mock) -> None:
4646
)
4747

4848
@gpio_loop.patch_gpio_loop(monitor.__name__ + ".GPIOMonitorBase")
49-
@mock.patch(monitor.__name__ + ".RPi.GPIO")
50-
def test_loop_when_logging_all_states(self, _: mock.Mock) -> None:
49+
@mock.patch(monitor.__name__ + ".RPi.GPIO", mock.Mock())
50+
def test_loop_when_logging_all_states(self) -> None:
5151
self.instance.gpio_log_changes_only = False
5252
with gpio_change.patch_gpio_input_change(self.instance.gpio_pins, False):
5353
mock_logger_message = "No New Messages"
@@ -71,8 +71,8 @@ def test_loop_when_logging_all_states(self, _: mock.Mock) -> None:
7171
)
7272

7373
@gpio_loop.patch_gpio_loop(monitor.__name__ + ".GPIOMonitorBase")
74-
@mock.patch(monitor.__name__ + ".RPi.GPIO")
75-
def test_loop_with_change(self, _: mock.Mock) -> None:
74+
@mock.patch(monitor.__name__ + ".RPi.GPIO", mock.Mock())
75+
def test_loop_with_change(self) -> None:
7676

7777
with gpio_change.patch_gpio_input_change(self.instance.gpio_pins, True):
7878
mock_logger_message = "No New Messages"

pi_portal/modules/integrations/gpio/tests/test_shim.py

+10-4
Original file line numberDiff line numberDiff line change
@@ -64,16 +64,22 @@ def test_import_or_mock_arm(self) -> None:
6464
self.assertIsInstance(shim.import_or_mock("adafruit_dht"), ModuleType)
6565

6666
@mock.patch(shim.__name__ + ".os.uname", MOCK_ARM)
67-
@mock.patch(shim.__name__ + ".import_module", side_effect=NotImplementedError)
68-
def test_import_or_mock_arm_exception(self, _: mock.Mock) -> None:
67+
@mock.patch(
68+
shim.__name__ + ".import_module",
69+
mock.Mock(side_effect=NotImplementedError)
70+
)
71+
def test_import_or_mock_arm_exception(self) -> None:
6972
self.assertIsInstance(
7073
shim.import_or_mock("board"),
7174
mock.MagicMock,
7275
)
7376

7477
@mock.patch(shim.__name__ + ".os.uname", MOCK_ARM)
75-
@mock.patch(shim.__name__ + ".import_module", side_effect=NotImplementedError)
76-
def test_import_or_mock_arm_exception_dual_import(self, _: mock.Mock) -> None:
78+
@mock.patch(
79+
shim.__name__ + ".import_module",
80+
mock.Mock(side_effect=NotImplementedError)
81+
)
82+
def test_import_or_mock_arm_exception_dual_import(self) -> None:
7783
first_import = shim.import_or_mock("board")
7884
second_import = shim.import_or_mock("board")
7985

0 commit comments

Comments
 (0)