style(wallpaper_changer): fix Ruff linting and formatting issues

fix declarations to acommodate None
organize imports
fix with indents
This commit is contained in:
Lucas Vivo committed 2026-11-13 11:28:11 +01:00
1 parent 1b4e93fc94
commit 0bc4b06893
8 files changed
+52 -53

No files matched your search

+26 -28
View File
@@ -1,7 +1,7 @@
import unittest
from contextlib import redirect_stdout
from importlib.metadata import version
from io import StringIO
import unittest
from pathlib import Path
from tempfile import TemporaryDirectory
from unittest.mock import patch
@@ -68,30 +68,29 @@ class ConfigTests(unittest.TestCase):
(("x", "/tmp/custom-wallpapers"), "/tmp/custom-wallpapers", Path("/tmp/custom-wallpapers")),
)
with patch("wallpaper_changer.config.socket.gethostname", return_value="testhost"):
with patch("pathlib.Path.home", return_value=home):
for (mode, folder), expected_folder, expected_img_dir in cases:
with self.subTest(mode=mode, folder=folder):
arguments = [
"--mode",
mode,
"--temp-dir",
"/tmp/wallpaper-cache",
"--private-key",
"/tmp/private-key.pem",
]
if folder is not None:
arguments.extend(("--folder", folder))
args = self.parse_args(*arguments)
with patch("wallpaper_changer.config.socket.gethostname", return_value="testhost"), \
patch("pathlib.Path.home", return_value=home):
for (mode, folder), expected_folder, expected_img_dir in cases:
with self.subTest(mode=mode, folder=folder):
arguments = [
"--mode",
mode,
"--temp-dir",
"/tmp/wallpaper-cache",
"--private-key",
"/tmp/private-key.pem",
]
if folder is not None:
arguments.extend(("--folder", folder))
args = self.parse_args(*arguments)
config = Config.load(args)
self.assertEqual(config.host, "testhost")
self.assertEqual(config.img_folder, expected_folder)
self.assertEqual(config.img_dir, expected_img_dir)
self.assertEqual(config.wallpaper_dir, Path("/tmp/wallpaper-cache/wallpaper"))
self.assertEqual(config.private_key, Path("/tmp/private-key.pem"))
config = Config.load(args)
self.assertEqual(config.host, "testhost")
self.assertEqual(config.img_folder, expected_folder)
self.assertEqual(config.img_dir, expected_img_dir)
self.assertEqual(config.wallpaper_dir, Path("/tmp/wallpaper-cache/wallpaper"))
self.assertEqual(config.private_key, Path("/tmp/private-key.pem"))
def test_load_uses_config_default_private_key_when_not_set(self) -> None:
home = Path("/home/test-user")
@@ -112,8 +111,8 @@ class ConfigTests(unittest.TestCase):
assets = Path(__file__).resolve().parents[1] / "assets"
args.private_key = assets / "test_privateKey.pem"
with patch("wallpaper_changer.config.socket.gethostname", return_value="testhost"):
with patch("pathlib.Path.home", return_value=home):
with patch("wallpaper_changer.config.socket.gethostname", return_value="testhost"), \
patch("pathlib.Path.home", return_value=home):
config = Config.load(args)
self.assertEqual(config.private_key, args.private_key)
@@ -139,9 +138,8 @@ class VersionArgumentTests(unittest.TestCase):
for flag in ("--version", "-v"):
with self.subTest(flag=flag):
output = StringIO()
with redirect_stdout(output):
with self.assertRaises(SystemExit) as raised:
parse_args([flag])
with redirect_stdout(output), self.assertRaises(SystemExit) as raised:
parse_args([flag])
self.assertEqual(raised.exception.code, 0)
self.assertEqual(
@@ -1,12 +1,12 @@
import hashlib
import shutil
import unittest
import hashlib
from pathlib import Path
from tempfile import TemporaryDirectory
from wallpaper_changer.image_repository import ImageRepository
from wallpaper_changer.config import Config
from wallpaper_changer.argument_parser import parse_args
from wallpaper_changer.config import Config
from wallpaper_changer.image_repository import ImageRepository
class ImageRepositoryTests(unittest.TestCase):