Skip to content

Commit

Permalink
Update file watcher version and fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Pasarus committed Jun 25, 2024
1 parent b7fa791 commit 03f807c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion container/file_watcher.D
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM python:3.10
FROM python:3.12-slim

WORKDIR /file_watcher

Expand Down
14 changes: 8 additions & 6 deletions test/file_watcher/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from unittest import mock
from unittest.mock import patch

from file_watcher.main import load_config, FileWatcher, main
from file_watcher.main import load_config, FileWatcher, main, write_readiness_probe_file
from test.file_watcher.utils import AwaitableNonAsyncMagicMock


Expand Down Expand Up @@ -92,15 +92,16 @@ def test_file_watcher_on_event_skips_dir_creation(self, mock_producer, logger):
self.assertEqual(logger.info.call_count, 1)
mock_producer.assert_not_called()

@patch("file_watcher.main.write_readiness_probe_file")
@patch("file_watcher.main.create_last_run_detector")
@patch("file_watcher.main.logger")
def test_file_watcher_start_watching_handles_exceptions_from_watcher(
self, mock_logger, mock_create_last_run_detector
self, mock_logger, mock_create_last_run_detector, mock_write_readiness_probe_file
):
self.file_watcher = FileWatcher(self.config)
exception = Exception("CRAZY EXCEPTION!")

def raise_exception():
def raise_exception(callback_func):
raise exception

mock_create_last_run_detector.return_value.watch_for_new_runs = AwaitableNonAsyncMagicMock(
Expand All @@ -110,17 +111,18 @@ def raise_exception():
# Should not raise, if raised it does not handle exceptions correctly
self.file_watcher.start_watching()

mock_create_last_run_detector.return_value.watch_for_new_runs.assert_called_once_with()
mock_create_last_run_detector.return_value.watch_for_new_runs.assert_called_once_with(callback_func=mock_write_readiness_probe_file)
mock_logger.info.assert_called_with("File observer fell over watching because of the following exception:")
mock_logger.exception.assert_called_with(exception)

@patch("file_watcher.main.create_last_run_detector")
def test_file_watcher_start_watching_creates_last_run_detector(self, mock_create_last_run_detector):
self.file_watcher = FileWatcher(self.config)

self.file_watcher.start_watching()
with mock.patch("file_watcher.main.write_readiness_probe_file") as write_readiness_probe_file_mock:
self.file_watcher.start_watching()

mock_create_last_run_detector.return_value.watch_for_new_runs.assert_called_once_with()
mock_create_last_run_detector.return_value.watch_for_new_runs.assert_called_once_with(callback_func=write_readiness_probe_file_mock)

@patch("file_watcher.main.load_config")
@patch("file_watcher.main.FileWatcher")
Expand Down

0 comments on commit 03f807c

Please sign in to comment.