test(wallaper_changer): add tests modules
add tests for monitor_manager, wallpaper_builder, encryption_manager, walpaper_Setter
This commit is contained in:
1 parent
8669499c36
commit
69b39940b0
4 files changed
+1043
No files matched your search
@@ -0,0 +1,69 @@
|
||||
import subprocess
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
from tempfile import TemporaryDirectory
|
||||
from unittest.mock import call, patch
|
||||
|
||||
from wallpaper_changer.wallpaper_setter import WallpaperSetter
|
||||
|
||||
|
||||
class WallpaperSetterTests(unittest.TestCase):
|
||||
def test_set_ubuntu_updates_light_dark_and_layout_settings(self) -> None:
|
||||
with TemporaryDirectory() as directory:
|
||||
wallpaper = Path(directory) / "wallpaper.jpg"
|
||||
wallpaper.write_bytes(b"placeholder")
|
||||
uri = wallpaper.resolve().as_uri()
|
||||
|
||||
with patch("wallpaper_changer.wallpaper_setter.subprocess.run") as run:
|
||||
WallpaperSetter().set_ubuntu(wallpaper)
|
||||
|
||||
self.assertEqual(run.call_args_list, [
|
||||
call(
|
||||
["gsettings", "set", "org.gnome.desktop.background",
|
||||
"picture-uri", uri],
|
||||
check=True,
|
||||
),
|
||||
call(
|
||||
["gsettings", "set", "org.gnome.desktop.background",
|
||||
"picture-uri-dark", uri],
|
||||
check=True,
|
||||
),
|
||||
call(
|
||||
["gsettings", "set", "org.gnome.desktop.background",
|
||||
"picture-options", "spanned"],
|
||||
check=True,
|
||||
),
|
||||
])
|
||||
|
||||
def test_set_ubuntu_rejects_missing_wallpaper(self) -> None:
|
||||
"""Verify a missing wallpaper path raises FileNotFoundError."""
|
||||
wallpaper = Path("wallpaper.jpg")
|
||||
with patch("wallpaper_changer.wallpaper_setter.subprocess.run"), \
|
||||
self.assertRaises(FileNotFoundError):
|
||||
WallpaperSetter().set_ubuntu(wallpaper)
|
||||
|
||||
def test_set_ubuntu_surfaces_gsettings_failure(self) -> None:
|
||||
"""Verify failures from gsettings are propagated to the caller."""
|
||||
with TemporaryDirectory() as directory:
|
||||
wallpaper = Path(directory) / "wallpaper.jpg"
|
||||
wallpaper.write_bytes(b"placeholder")
|
||||
command = [
|
||||
"gsettings",
|
||||
"set",
|
||||
"org.gnome.desktop.background",
|
||||
"picture-uri",
|
||||
wallpaper.resolve().as_uri(),
|
||||
]
|
||||
|
||||
with patch(
|
||||
"wallpaper_changer.wallpaper_setter.subprocess.run",
|
||||
side_effect=subprocess.CalledProcessError(1, command),
|
||||
) as run, self.assertRaises(subprocess.CalledProcessError) as error:
|
||||
WallpaperSetter().set_ubuntu(wallpaper)
|
||||
|
||||
self.assertEqual(error.exception.returncode, 1)
|
||||
run.assert_called_once_with(command, check=True)
|
||||
|
||||
def test_set_gnome_delegates_to_set_ubuntu(self) -> None:
|
||||
"""Verify the GNOME entry point delegates to the Ubuntu setter."""
|
||||
self.skipTest("TODO: assert delegation")
|
||||
Reference in new issue
Block a user