Skip to content

Commit

Permalink
Fix broken pytest
Browse files Browse the repository at this point in the history
  • Loading branch information
Pasarus committed Jun 24, 2024
1 parent 4851ea8 commit 9def462
Showing 1 changed file with 24 additions and 6 deletions.
30 changes: 24 additions & 6 deletions test/file_watcher/test_lastrun_file_monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import unittest
from datetime import datetime, timedelta
from pathlib import Path
from unittest import mock
from unittest.mock import call, patch, MagicMock

from file_watcher.lastrun_file_monitor import create_last_run_detector
Expand Down Expand Up @@ -95,7 +96,7 @@ def test_watch_for_new_runs_checks_for_latest_cycle_after_6_hours(self):

self.assertEqual(self.lrd.get_latest_cycle.call_count, 0)

self.lrd.watch_for_new_runs(run_once=True)
self.lrd.watch_for_new_runs(mock.MagicMock(), run_once=True)

self.assertEqual(self.lrd.get_latest_cycle.call_count, 1)
self.assertGreater(self.lrd.last_cycle_folder_check, now)
Expand All @@ -112,10 +113,27 @@ def test_watch_for_new_runs_checks_contents_of_last_run_file(self):
)
self.lrd.get_last_run_from_file = MagicMock()

self.lrd.watch_for_new_runs(run_once=True)
self.lrd.watch_for_new_runs(mock.MagicMock(), run_once=True)

self.lrd.get_last_run_from_file.assert_called_once_with()

def test_watch_for_new_runs_calls_callback_func(self):
self.lrd = create_last_run_detector(
self.archive_path,
self.instrument,
self.callback,
self.run_file_prefix,
self.db_ip,
self.db_username,
self.db_password,
)
callback_func = mock.MagicMock()

self.lrd.watch_for_new_runs(callback_func, run_once=True)

callback_func.assert_called_once_with()


def test_watch_for_new_runs_handles_exceptions_from_get_last_run_from_file(self):
self.lrd = create_last_run_detector(
self.archive_path,
Expand All @@ -134,7 +152,7 @@ def raise_exception():
self.lrd.get_last_run_from_file = MagicMock(side_effect=raise_exception)

with patch("file_watcher.lastrun_file_monitor.logger") as logger:
self.lrd.watch_for_new_runs(run_once=True)
self.lrd.watch_for_new_runs(mock.MagicMock(), run_once=True)

self.lrd.get_last_run_from_file.assert_called_once_with()

Expand All @@ -153,7 +171,7 @@ def test_latest_run_is_new(self):
self.lrd.get_last_run_from_file = MagicMock(return_value="0002")
self.lrd.new_run_detected = AwaitableNonAsyncMagicMock()

self.lrd.watch_for_new_runs(run_once=True)
self.lrd.watch_for_new_runs(mock.MagicMock(), run_once=True)

self.lrd.get_last_run_from_file.assert_called_once_with()
self.lrd.new_run_detected.assert_called_once_with("0002")
Expand All @@ -171,7 +189,7 @@ def test_latest_run_is_new_and_more_than_one_file(self):
self.lrd.get_last_run_from_file = MagicMock(return_value="0003")
self.lrd.recover_lost_runs = AwaitableNonAsyncMagicMock()

self.lrd.watch_for_new_runs(run_once=True)
self.lrd.watch_for_new_runs(mock.MagicMock(), run_once=True)

self.lrd.get_last_run_from_file.assert_called_once_with()
self.lrd.recover_lost_runs.assert_called_with("0001", "0003")
Expand All @@ -190,7 +208,7 @@ def test_latest_run_is_not_new(self):
self.lrd.recover_lost_runs = AwaitableNonAsyncMagicMock()
self.lrd.new_run_detected = AwaitableNonAsyncMagicMock()

self.lrd.watch_for_new_runs(run_once=True)
self.lrd.watch_for_new_runs(mock.MagicMock(), run_once=True)

self.lrd.get_last_run_from_file.assert_called_once_with()
self.lrd.recover_lost_runs.assert_not_called()
Expand Down

0 comments on commit 9def462

Please sign in to comment.