2026-11-17 11:52:08 +01:00
|
|
|
import unittest
|
|
|
|
|
from pathlib import Path
|
|
|
|
|
from unittest.mock import patch
|
|
|
|
|
|
|
|
|
|
from wallpaper_changer.argument_parser import parse_args
|
|
|
|
|
from wallpaper_changer.config import Config
|
|
|
|
|
from wallpaper_changer.monitor_manager import Monitor, ScreenLayout
|
|
|
|
|
from wallpaper_changer.wallpaper_changer import WallpaperChanger
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class WallpaperChangerTests(unittest.TestCase):
|
|
|
|
|
def parse_args(self, *arguments: str):
|
|
|
|
|
return parse_args(list(arguments))
|
|
|
|
|
def setUp(self) -> None:
|
|
|
|
|
args = self.parse_args("--disable-encryption", "--decode-and-leave", "--minutes", "1")
|
|
|
|
|
self.cfg = Config.load(args)
|
|
|
|
|
self.layout = ScreenLayout((Monitor(1920, 1080, 0, set()),))
|
|
|
|
|
|
|
|
|
|
def test_change_wallpaper_scans_builds_and_sets_wallpaper(self) -> None:
|
|
|
|
|
images = ["image-1"]
|
|
|
|
|
wallpaper_path = Path("/wallpapers/wallpaper.jpg")
|
|
|
|
|
search_terms_gen = ["mountain"]
|
|
|
|
|
search_terms_monitor = ["lake"]
|
|
|
|
|
exclude = ["night"]
|
|
|
|
|
|
|
|
|
|
with (
|
|
|
|
|
patch("wallpaper_changer.wallpaper_changer.ImageRepository") as repository,
|
|
|
|
|
patch("wallpaper_changer.wallpaper_changer.WallpaperBuilder") as builder,
|
|
|
|
|
patch("wallpaper_changer.wallpaper_changer.WallpaperSetter") as setter,
|
|
|
|
|
):
|
|
|
|
|
repository.return_value.scan.return_value = images
|
|
|
|
|
builder.return_value.build.return_value = (wallpaper_path, [])
|
|
|
|
|
|
|
|
|
|
WallpaperChanger().change_wallpaper(
|
|
|
|
|
self.cfg,
|
|
|
|
|
self.layout,
|
|
|
|
|
search_terms_gen,
|
|
|
|
|
search_terms_monitor,
|
|
|
|
|
exclude,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
repository.assert_called_once_with(self.cfg.img_dir)
|
|
|
|
|
repository.return_value.scan.assert_called_once_with(
|
2026-11-20 20:41:36 +01:00
|
|
|
self.cfg.passphrase_file,
|
2026-11-17 11:52:08 +01:00
|
|
|
disable_encryption=True,
|
|
|
|
|
)
|
|
|
|
|
builder.return_value.build.assert_called_once_with(
|
|
|
|
|
images,
|
|
|
|
|
self.layout,
|
2026-11-20 20:41:36 +01:00
|
|
|
passphrase_file=self.cfg.passphrase_file,
|
2026-11-17 11:52:08 +01:00
|
|
|
wallpaper_dir=self.cfg.wallpaper_dir,
|
|
|
|
|
search_terms_monitor=search_terms_monitor,
|
|
|
|
|
search_terms_gen=search_terms_gen,
|
|
|
|
|
exclude=exclude,
|
|
|
|
|
decode_and_leave=True,
|
|
|
|
|
disable_encryption=True,
|
|
|
|
|
)
|
|
|
|
|
setter.return_value.set_ubuntu.assert_called_once_with(wallpaper_path)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
unittest.main()
|