test(wallpaper_changer): add daemon tests
This commit is contained in:
1 parent
624ee3770c
commit
3c556dde9a
1 file changed
+52
-1
@@ -1,5 +1,7 @@
|
||||
import unittest
|
||||
from unittest.mock import patch
|
||||
from pathlib import Path
|
||||
from tempfile import TemporaryDirectory
|
||||
from unittest.mock import call, patch
|
||||
|
||||
from wallpaper_changer.argument_parser import parse_args
|
||||
from wallpaper_changer.config import Config
|
||||
@@ -62,6 +64,55 @@ class DaemonRunnerTests(unittest.TestCase):
|
||||
)
|
||||
event.wait.assert_called_once_with(5 * 60)
|
||||
|
||||
def test_run_uses_search_terms_updated_in_config(self) -> None:
|
||||
with TemporaryDirectory() as temporary_directory:
|
||||
config_dir = Path(temporary_directory)
|
||||
config_file = config_dir / "wpD.conf"
|
||||
config_file.write_text("--search mountain --minutes 5\n")
|
||||
initial_args = parse_args(
|
||||
["--daemon","--config","--conf-dir", str(config_dir)]
|
||||
)
|
||||
cfg = Config.load(initial_args)
|
||||
|
||||
waits = 0
|
||||
|
||||
def update_config_between_iterations(interval):
|
||||
nonlocal waits
|
||||
waits += 1
|
||||
if waits == 1:
|
||||
config_file.write_text(
|
||||
"--search lake --search-mon city --exclude night --minutes 5\n"
|
||||
)
|
||||
return waits == 3
|
||||
|
||||
with (
|
||||
patch("wallpaper_changer.daemon.threading.Event") as event_factory,
|
||||
patch("wallpaper_changer.daemon.WallpaperChanger") as changer_factory,
|
||||
):
|
||||
event = event_factory.return_value
|
||||
event.is_set.return_value = False
|
||||
event.wait.side_effect = update_config_between_iterations
|
||||
|
||||
DaemonRunner().run(
|
||||
cfg,
|
||||
self.layout,
|
||||
initial_args.search,
|
||||
initial_args.search_mon,
|
||||
initial_args.exclude,
|
||||
)
|
||||
self.assertEqual(
|
||||
changer_factory.return_value.change_wallpaper.call_args_list,
|
||||
[
|
||||
call(cfg, self.layout, ["mountain"], None, ["elements"]),
|
||||
call(cfg, self.layout, ["mountain"], None, ["elements"]),
|
||||
call(cfg, self.layout, ["lake"], ["city"], ["night"]),
|
||||
],
|
||||
)
|
||||
self.assertEqual(
|
||||
event.wait.call_args_list[:3],
|
||||
[call(5 * 60), call(5 * 60), call(5 * 60)],
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user