from unittest.mock import MagicMock, patch from control_backend.logging.dated_file_handler import DatedFileHandler @patch("control_backend.logging.file_handler.DatedFileHandler._open") def test_reset(open_): stream = MagicMock() open_.return_value = stream # A file should be opened when the logger is created handler = DatedFileHandler(prefix="anything") assert open_.call_count == 1 # Upon reset, the current file should be closed, and a new one should be opened handler.do_rollover() assert stream.close.call_count == 1 assert open_.call_count == 2