style(wallpaper_changer): fix Ruff linting and formatting issues
fix declarations to acommodate None organize imports fix with indents
This commit is contained in:
1 parent
1b4e93fc94
commit
0bc4b06893
8 files changed
+52
-53
No files matched your search
@@ -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(
|
||||
|
||||
Reference in new issue
Block a user