Skip to content

Commit

Permalink
properly mock time funcs in led_control_test
Browse files Browse the repository at this point in the history
  • Loading branch information
kissiel committed Apr 30, 2024
1 parent e53e5cb commit 693a13e
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion providers/base/tests/test_led_control_test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import sys
import unittest
from datetime import datetime
from unittest.mock import patch, Mock
from pathlib import PosixPath, Path
from led_control_test import SysFsLEDController
Expand Down Expand Up @@ -132,9 +133,17 @@ def test_get_initial_state(self, mock_read):
self.led_controller._get_initial_state()
self.assertEqual(expected_data, self.led_controller.initial_state)

@patch("time.sleep", return_value=0)
@patch("led_control_test.datetime")
@patch("led_control_test.SysFsLEDController.off")
@patch("led_control_test.SysFsLEDController.on")
def test_blinking_test(self, mock_on, mock_off):
def test_blinking_test(self, mock_on, mock_off, mock_datetime, mock_sleep):
mock_datetime.now = Mock()
mock_datetime.now.side_effect = [
datetime(2020, 1, 1, 0, 0, 0),
datetime(2020, 1, 1, 0, 0, 1),
datetime(2020, 1, 1, 0, 0, 2),
]

self.led_controller.blinking(1, 0.5)
mock_on.assert_called_with()
Expand Down

0 comments on commit 693a13e

Please sign in to comment.