test(wallpaper_manager): all tests done
added image_repository tests moved decode_all test to iamge_repository
This commit is contained in:
1 parent
7ebead0b53
commit
19da576745
3 files changed
+244
-64
No files matched your search
@@ -67,27 +67,25 @@ class EncryptionManagerTests(unittest.TestCase):
|
||||
|
||||
def test_decrypt_rejects_invalid_or_truncated_ciphertext(self) -> None:
|
||||
"""Verify malformed headers and incomplete ciphertext are rejected."""
|
||||
with TemporaryDirectory() as temporary_directory, \
|
||||
self.assertRaisesRegex(ValueError, "Hash mismatch for"):
|
||||
image_root = Path(temporary_directory)
|
||||
assets = Path(__file__).resolve().parents[1] / "assets"
|
||||
args = self.parse_args("--conf-dir", str(image_root),
|
||||
"--folder", str(image_root / "corrupt"),
|
||||
"--private-key", str(assets / "test_private_key.pem"))
|
||||
config = Config.load(args)
|
||||
shutil.copytree(assets / "corrupt" , config.img_dir)
|
||||
malformed_ciphertexts = (
|
||||
b"invalid header",
|
||||
b"Salted__12345678",
|
||||
b"Salted__12345678" + b"x" * 15,
|
||||
b"Salted__12345678" + b"x" * 17,
|
||||
)
|
||||
manager = EncryptionManager()
|
||||
|
||||
with open(config.img_dir / "00001.jpg_enc", "r+b") as f:
|
||||
f.seek(0, 2)
|
||||
size = f.tell()
|
||||
middle = size // 2
|
||||
f.seek(middle)
|
||||
byte = f.read(1)
|
||||
corrupted = bytes([byte[0] ^ 0b00000011])
|
||||
f.seek(middle)
|
||||
f.write(corrupted)
|
||||
|
||||
ImageRepository(config.img_dir).decode_all(config.private_key)
|
||||
with TemporaryDirectory() as temporary_directory:
|
||||
encrypted_file = Path(temporary_directory) / "malformed.enc"
|
||||
for ciphertext in malformed_ciphertexts:
|
||||
with self.subTest(ciphertext_length=len(ciphertext)):
|
||||
encrypted_file.write_bytes(ciphertext)
|
||||
with self.assertRaisesRegex(
|
||||
ValueError, "Invalid or truncated encrypted file"
|
||||
):
|
||||
manager.decrypt(
|
||||
encrypted_file, None, "pass:test passphrase"
|
||||
)
|
||||
|
||||
def test_passphrase_formats(self) -> None:
|
||||
"""Verify byte, literal, and passphrase-file inputs are read correctly."""
|
||||
|
||||
@@ -5,9 +5,13 @@ import unittest
|
||||
from collections import defaultdict
|
||||
from pathlib import Path
|
||||
from tempfile import TemporaryDirectory
|
||||
from unittest.mock import patch
|
||||
|
||||
from PIL import Image
|
||||
|
||||
from wallpaper_changer.argument_parser import parse_args
|
||||
from wallpaper_changer.config import Config
|
||||
from wallpaper_changer.encryption_manager import EncryptionManager
|
||||
from wallpaper_changer.image_repository import ImageRepository
|
||||
|
||||
|
||||
@@ -80,7 +84,8 @@ class ImageRepositoryTests(unittest.TestCase):
|
||||
all(image["file"].parent.name == "corrupt" for image in images)
|
||||
)
|
||||
|
||||
def test_convert_to_jpg(self) -> None:
|
||||
def test_convert_to_jpg_handles_collisions_and_transparency(self) -> None:
|
||||
"""Verify conversion avoids overwrites and composites transparent pixels."""
|
||||
with TemporaryDirectory() as temporary_directory:
|
||||
image_root = Path(temporary_directory)
|
||||
assets = Path(__file__).resolve().parents[1] / "assets"
|
||||
@@ -101,6 +106,10 @@ class ImageRepositoryTests(unittest.TestCase):
|
||||
self.assertTrue(
|
||||
all(image["file"].suffix == ".jpg" for image in images)
|
||||
)
|
||||
for num in range(1, 6):
|
||||
image_path = config.img_dir / f"Foto_Berg{num:02d}.jpg"
|
||||
with self.subTest(image=image_path.name):
|
||||
self.assertTrue(image_path.is_file())
|
||||
|
||||
def test_check_encryption_ignore_same_hash_shorter_name(self) -> None:
|
||||
with TemporaryDirectory() as temporary_directory:
|
||||
@@ -117,10 +126,9 @@ class ImageRepositoryTests(unittest.TestCase):
|
||||
|
||||
image_repository = ImageRepository(config.img_dir)
|
||||
image_repository.check_encryption(config.private_key)
|
||||
images = image_repository.scan(config.private_key)
|
||||
|
||||
self.assertEqual( sum(1 for image in images if image["file"].suffix == ".jpg"), 1)
|
||||
self.assertEqual( sum(1 for image in images if image["file"].suffix == ".jpg_enc"), 9)
|
||||
self.assertEqual(len(list(config.img_dir.rglob("*.jpg"))), 1)
|
||||
self.assertEqual(len(list(config.img_dir.rglob("*.jpg_enc"))), 9)
|
||||
|
||||
def test_check_encryption_ignore_same_hash_equal_length_name(self) -> None:
|
||||
with TemporaryDirectory() as temporary_directory:
|
||||
@@ -137,10 +145,9 @@ class ImageRepositoryTests(unittest.TestCase):
|
||||
|
||||
image_repository = ImageRepository(config.img_dir)
|
||||
image_repository.check_encryption(config.private_key)
|
||||
images = image_repository.scan(config.private_key)
|
||||
|
||||
self.assertEqual( sum(1 for image in images if image["file"].suffix == ".jpg"), 1)
|
||||
self.assertEqual( sum(1 for image in images if image["file"].suffix == ".jpg_enc"), 9)
|
||||
self.assertEqual(len(list(config.img_dir.rglob("*.jpg"))), 1)
|
||||
self.assertEqual(len(list(config.img_dir.rglob("*.jpg_enc"))), 9)
|
||||
|
||||
def test_check_encryption_replace_same_name(self) -> None:
|
||||
with TemporaryDirectory() as temporary_directory:
|
||||
@@ -167,8 +174,8 @@ class ImageRepositoryTests(unittest.TestCase):
|
||||
image_repository.check_encryption( config.private_key, replace=True)
|
||||
images = image_repository.scan(config.private_key)
|
||||
|
||||
self.assertEqual( sum(1 for image in images if image["file"].suffix == ".jpg"), 0)
|
||||
self.assertEqual( sum(1 for image in images if image["file"].suffix == ".jpg_enc"), 8)
|
||||
self.assertEqual(len(list(config.img_dir.rglob("*.jpg"))), 0)
|
||||
self.assertEqual(len(list(config.img_dir.rglob("*.jpg_enc"))), 8)
|
||||
image_hash = next(
|
||||
item["hash"] for item in images if item["name"] == new_image_name
|
||||
)
|
||||
@@ -197,8 +204,8 @@ class ImageRepositoryTests(unittest.TestCase):
|
||||
image_repository.check_encryption(config.private_key)
|
||||
images = image_repository.scan(config.private_key)
|
||||
|
||||
self.assertEqual( sum(1 for image in images if image["file"].suffix == ".jpg"), 1)
|
||||
self.assertEqual( sum(1 for image in images if image["file"].suffix == ".jpg_enc"), 8)
|
||||
self.assertEqual(len(list(config.img_dir.rglob("*.jpg"))), 1)
|
||||
self.assertEqual(len(list(config.img_dir.rglob("*.jpg_enc"))), 8)
|
||||
self.assertTrue([image["name"] for image in images if image["hash"] == new_image_hash] == [new_image_name])
|
||||
|
||||
def test_check_encryption_set_unique_name(self) -> None:
|
||||
@@ -218,8 +225,8 @@ class ImageRepositoryTests(unittest.TestCase):
|
||||
image_repository.check_encryption(config.private_key)
|
||||
images = image_repository.scan(config.private_key)
|
||||
|
||||
self.assertEqual( sum(1 for image in images if image["file"].suffix == ".jpg"), 0)
|
||||
self.assertEqual( sum(1 for image in images if image["file"].suffix == ".jpg_enc"), 9)
|
||||
self.assertEqual(len(list(config.img_dir.rglob("*.jpg"))), 0)
|
||||
self.assertEqual(len(list(config.img_dir.rglob("*.jpg_enc"))), 9)
|
||||
self.assertTrue( image["name"] == "Foto_Berg05.jpg"
|
||||
for image in images if image["file"].name == "00009.jpg_enc")
|
||||
|
||||
@@ -236,9 +243,8 @@ class ImageRepositoryTests(unittest.TestCase):
|
||||
|
||||
image_repository = ImageRepository(config.img_dir)
|
||||
image_repository.decode_all(config.private_key)
|
||||
images = image_repository.scan(config.private_key)
|
||||
self.assertEqual( sum(1 for image in images if image["file"].suffix == ".jpg"), 8)
|
||||
self.assertEqual( sum(1 for image in images if image["file"].suffix == ".jpg_enc"), 0)
|
||||
self.assertEqual(len(list(config.img_dir.rglob("*.jpg"))), 8)
|
||||
self.assertEqual(len(list(config.img_dir.rglob("*.jpg_enc"))), 0)
|
||||
|
||||
def test_decode_argument(self) -> None:
|
||||
with TemporaryDirectory() as temporary_directory:
|
||||
@@ -255,11 +261,8 @@ class ImageRepositoryTests(unittest.TestCase):
|
||||
image_repository.decode_images(pattern="Kirchberg",
|
||||
conf_dir=config.conf_dir,
|
||||
private_key=config.private_key)
|
||||
images = image_repository.scan(config.private_key)
|
||||
self.assertEqual( sum(1 for image in images if image["file"].suffix == ".jpg_enc"), 8)
|
||||
images = image_repository.scan(config.private_key,
|
||||
img_dir=image_root/"New")
|
||||
self.assertEqual( sum(1 for image in images if image["file"].suffix == ".jpg"), 2)
|
||||
self.assertEqual(len(list(config.img_dir.rglob("*.jpg_enc"))), 8)
|
||||
self.assertEqual(len(list((image_root/"New").rglob("*.jpg"))), 2)
|
||||
|
||||
def test_decode_argument_remove(self) -> None:
|
||||
with TemporaryDirectory() as temporary_directory:
|
||||
@@ -277,10 +280,8 @@ class ImageRepositoryTests(unittest.TestCase):
|
||||
conf_dir=config.conf_dir,
|
||||
private_key=config.private_key,
|
||||
remove=True)
|
||||
images = image_repository.scan(config.private_key)
|
||||
self.assertEqual( sum(1 for image in images if image["file"].suffix == ".jpg_enc"), 6)
|
||||
images = ImageRepository(image_root/"New").scan(config.private_key)
|
||||
self.assertEqual( sum(1 for image in images if image["file"].suffix == ".jpg"), 2)
|
||||
self.assertEqual(len(list(config.img_dir.rglob("*.jpg_enc"))), 6)
|
||||
self.assertEqual(len(list(image_root.rglob("*.jpg"))), 2)
|
||||
|
||||
def test_check_consecutive_filenames(self) -> None:
|
||||
with TemporaryDirectory() as temporary_directory:
|
||||
@@ -303,54 +304,235 @@ class ImageRepositoryTests(unittest.TestCase):
|
||||
stem, number = match.groups()
|
||||
groups[stem].append(int(number))
|
||||
|
||||
self.assertEqual( sum(1 for image in images if image["file"].suffix == ".jpg"), 8)
|
||||
self.assertEqual(len(list(config.img_dir.rglob("*.jpg"))), 8)
|
||||
self.assertEqual( [max(groups[key]) for key in groups],
|
||||
[len(groups[key]) for key in groups] )
|
||||
|
||||
class ImageRepositoryEdgeCaseTests(unittest.TestCase):
|
||||
def parse_args(self, *arguments: str):
|
||||
return parse_args(list(arguments))
|
||||
|
||||
def test_scan_skips_unsupported_and_corrupt_files(self) -> None:
|
||||
"""Verify scanning ignores unsupported files and handles corrupt image files."""
|
||||
self.skipTest("TODO: add supported, unsupported, and corrupt file fixtures")
|
||||
with TemporaryDirectory() as temporary_directory:
|
||||
image_root = Path(temporary_directory)
|
||||
assets = Path(__file__).resolve().parents[1] / "assets"
|
||||
args = self.parse_args("--conf-dir", str(image_root),
|
||||
"--folder", str(image_root / "Desktop1920x1080"),
|
||||
"--private-key", str(assets / "test_private_key.pem"))
|
||||
config = Config.load(args)
|
||||
config.img_dir.mkdir(exist_ok=True)
|
||||
shutil.copy(assets / "Desktop1920x1080" / "Foto_Berg01.jpg",
|
||||
config.img_dir,
|
||||
)
|
||||
shutil.copy(assets / "corrupt" / "00001.jpg_enc",
|
||||
config.img_dir,
|
||||
)
|
||||
shutil.copy(assets / "corrupt" / "00001.jpg_enc",
|
||||
config.img_dir / "corrupt.enc",
|
||||
)
|
||||
textfile = config.img_dir / "textfile.txt"
|
||||
textfile.write_text("text\n")
|
||||
|
||||
def test_scan_maps_nested_encrypted_images_from_naming_table(self) -> None:
|
||||
images = ImageRepository(config.img_dir).scan(config.private_key)
|
||||
self.assertEqual(len(images), 2)
|
||||
|
||||
def test_check_encryption_ignores_nested_directories(self) -> None:
|
||||
"""Verify nested encrypted files are matched to their naming-table entries."""
|
||||
self.skipTest("TODO: cover nested image paths and naming-table mapping")
|
||||
with TemporaryDirectory() as temporary_directory:
|
||||
image_root = Path(temporary_directory)
|
||||
assets = Path(__file__).resolve().parents[1] / "assets"
|
||||
args = self.parse_args("--conf-dir", str(image_root),
|
||||
"--folder", str(image_root / "corrupt"),
|
||||
"--private-key", str(assets / "test_private_key.pem"))
|
||||
config = Config.load(args)
|
||||
|
||||
shutil.copytree(assets / "Desktop1920x1080", config.img_dir / "folder1")
|
||||
|
||||
image_repository = ImageRepository(config.img_dir)
|
||||
image_repository.check_encryption(config.private_key)
|
||||
|
||||
self.assertEqual(len(list(config.img_dir.rglob("*.jpg"))), 8)
|
||||
self.assertEqual(len(list(config.img_dir.rglob("*.jpg_enc"))), 0)
|
||||
|
||||
def test_scan_with_encryption_disabled_includes_plain_jpeg_payloads_only(self) -> None:
|
||||
"""Verify plaintext JPEG payloads with an encrypted suffix are scanned safely."""
|
||||
self.skipTest("TODO: cover valid and encrypted .jpg_enc payloads")
|
||||
with TemporaryDirectory() as temporary_directory:
|
||||
image_root = Path(temporary_directory)
|
||||
assets = Path(__file__).resolve().parents[1] / "assets"
|
||||
args = self.parse_args("--conf-dir", str(image_root),
|
||||
"--folder", str(image_root / "Desktop1920x1080"),
|
||||
"--private-key", str(assets / "test_private_key.pem"))
|
||||
config = Config.load(args)
|
||||
config.img_dir.mkdir(exist_ok=True)
|
||||
shutil.copy(assets / "Desktop1920x1080" / "Foto_Berg01.jpg",
|
||||
config.img_dir,
|
||||
)
|
||||
shutil.copy(assets / "corrupt" / "00001.jpg_enc",
|
||||
config.img_dir,
|
||||
)
|
||||
|
||||
def test_convert_to_jpg_handles_collisions_and_transparency(self) -> None:
|
||||
"""Verify conversion avoids overwrites and composites transparent pixels."""
|
||||
self.skipTest("TODO: cover destination collisions and alpha handling")
|
||||
images = ImageRepository(config.img_dir).scan(config.private_key, disable_encryption=True)
|
||||
self.assertEqual(len(images), 1)
|
||||
|
||||
def test_convert_to_jpg_applies_exif_orientation(self) -> None:
|
||||
"""Verify converted images respect their EXIF orientation metadata."""
|
||||
self.skipTest("TODO: add an oriented image fixture and assert output dimensions")
|
||||
with TemporaryDirectory() as temporary_directory:
|
||||
image_root = Path(temporary_directory)
|
||||
source_path = image_root / "rotated-orientation.tiff"
|
||||
|
||||
image = Image.new("RGB", (200, 100), color="white")
|
||||
for x in range(50):
|
||||
for y in range(50):
|
||||
image.putpixel((x, y), (0, 0, 0))
|
||||
|
||||
exif = image.getexif()
|
||||
exif[274] = 6
|
||||
image.save(source_path, format="TIFF", exif=exif)
|
||||
|
||||
converted_paths = ImageRepository(image_root).convert_to_jpg(image_root)
|
||||
|
||||
self.assertEqual(len(converted_paths), 1)
|
||||
converted_path = converted_paths[0]
|
||||
self.assertTrue(converted_path.exists())
|
||||
self.assertFalse(source_path.exists())
|
||||
|
||||
with Image.open(converted_path) as converted_image:
|
||||
self.assertEqual(converted_image.size, (100, 200))
|
||||
self.assertEqual(converted_image.getpixel((50, 0)), (0, 0, 0))
|
||||
|
||||
def test_check_encryption_handles_missing_and_empty_new_folders(self) -> None:
|
||||
"""Verify encryption checking is a no-op for missing or empty input folders."""
|
||||
self.skipTest("TODO: cover missing and empty input folders")
|
||||
with TemporaryDirectory() as temporary_directory:
|
||||
image_root = Path(temporary_directory)
|
||||
assets = Path(__file__).resolve().parents[1] / "assets"
|
||||
args = self.parse_args("--conf-dir", str(image_root),
|
||||
"--folder", str(image_root / "corrupt"),
|
||||
"--private-key", str(assets / "test_private_key.pem"))
|
||||
config = Config.load(args)
|
||||
|
||||
with self.subTest("test_missing_folder"), self.assertRaises(ValueError):
|
||||
image_repository = ImageRepository(config.img_dir)
|
||||
image_repository.check_encryption(config.private_key)
|
||||
with self.subTest("test_empty_folder"):
|
||||
config.img_dir.mkdir(exist_ok=True)
|
||||
image_repository = ImageRepository(config.img_dir)
|
||||
image_repository.check_encryption(config.private_key)
|
||||
|
||||
def test_check_encryption_preserves_plaintext_on_encryption_failure(self) -> None:
|
||||
"""Verify failed encryption does not delete the original image."""
|
||||
self.skipTest("TODO: simulate encryption failure and assert source preservation")
|
||||
with TemporaryDirectory() as temporary_directory:
|
||||
image_root = Path(temporary_directory)
|
||||
assets = Path(__file__).resolve().parents[1] / "assets"
|
||||
args = self.parse_args("--conf-dir", str(image_root),
|
||||
"--folder", str(image_root / "corrupt"),
|
||||
"--private-key", str(assets / "test_private_key.pem"))
|
||||
config = Config.load(args)
|
||||
config.img_dir.mkdir(exist_ok=True)
|
||||
shutil.copy(assets / "Desktop1920x1080" / "Foto_Berg01.jpg", config.img_dir)
|
||||
image_repository = ImageRepository(config.img_dir)
|
||||
images_before_failed_enc = image_repository.scan(config.private_key)
|
||||
|
||||
def test_decode_image_rejects_hash_mismatch(self) -> None:
|
||||
with patch("wallpaper_changer.encryption_manager.EncryptionManager.encrypt",
|
||||
side_effect=RuntimeError("Encryption failed")), \
|
||||
self.assertRaises(RuntimeError):
|
||||
image_repository.check_encryption(config.private_key)
|
||||
images_after_failed_enc = image_repository.scan(config.private_key)
|
||||
self.assertEqual(images_before_failed_enc, images_after_failed_enc)
|
||||
|
||||
|
||||
def test_decode_all_image_rejects_hash_mismatch(self) -> None:
|
||||
"""Verify decrypted content with an unexpected hash is rejected."""
|
||||
self.skipTest("TODO: assert hash mismatch behavior")
|
||||
with TemporaryDirectory() as temporary_directory, \
|
||||
self.assertRaisesRegex(ValueError, "Hash mismatch for"):
|
||||
image_root = Path(temporary_directory)
|
||||
assets = Path(__file__).resolve().parents[1] / "assets"
|
||||
args = self.parse_args("--conf-dir", str(image_root),
|
||||
"--folder", str(image_root / "corrupt"),
|
||||
"--private-key", str(assets / "test_private_key.pem"))
|
||||
config = Config.load(args)
|
||||
shutil.copytree(assets / "corrupt" , config.img_dir)
|
||||
|
||||
with open(config.img_dir / "00001.jpg_enc", "r+b") as f:
|
||||
f.seek(0, 2)
|
||||
size = f.tell()
|
||||
middle = size // 2
|
||||
f.seek(middle)
|
||||
byte = f.read(1)
|
||||
corrupted = bytes([byte[0] ^ 0b00000011])
|
||||
f.seek(middle)
|
||||
f.write(corrupted)
|
||||
|
||||
ImageRepository(config.img_dir).decode_all(config.private_key)
|
||||
|
||||
def test_decode_all_handles_unmapped_encrypted_files(self) -> None:
|
||||
"""Verify decode-all behavior when an encrypted image has no table entry."""
|
||||
self.skipTest("TODO: cover missing naming-table entries")
|
||||
with TemporaryDirectory() as temporary_directory:
|
||||
image_root = Path(temporary_directory)
|
||||
assets = Path(__file__).resolve().parents[1] / "assets"
|
||||
args = self.parse_args("--conf-dir", str(image_root),
|
||||
"--folder", str(image_root / "corrupt"),
|
||||
"--private-key", str(assets / "test_private_key.pem"))
|
||||
config = Config.load(args)
|
||||
shutil.copytree(assets / "corrupt" , config.img_dir)
|
||||
shutil.copy(assets / "images" / "00011.jpg_enc", config.img_dir)
|
||||
ImageRepository(config.img_dir).decode_all(config.private_key)
|
||||
self.assertEqual(len(list(config.img_dir.glob("*.jpg"))), 9)
|
||||
self.assertEqual(len(list(config.img_dir.glob("MissingImage01.jpg"))), 1)
|
||||
|
||||
def test_decode_operations_avoid_existing_destination_names(self) -> None:
|
||||
"""Verify decoded images do not overwrite existing files with the same name."""
|
||||
self.skipTest("TODO: cover destination name collisions")
|
||||
with TemporaryDirectory() as temporary_directory:
|
||||
image_root = Path(temporary_directory)
|
||||
assets = Path(__file__).resolve().parents[1] / "assets"
|
||||
args = self.parse_args("--conf-dir", str(image_root),
|
||||
"--folder", str(image_root / "corrupt"),
|
||||
"--private-key", str(assets / "test_private_key.pem"))
|
||||
config = Config.load(args)
|
||||
shutil.copytree(assets / "corrupt" , config.img_dir)
|
||||
shutil.copy(assets / "Desktop1920x1080" / "Foto_Berg01.jpg" , config.img_dir)
|
||||
|
||||
naming_table = EncryptionManager().load_naming_table(
|
||||
config.img_dir/"naming_table.enc", config.private_key
|
||||
)
|
||||
naming_table_element_hash = [item.image_hash for item in naming_table
|
||||
if item.image_name == "Foto_Berg01.jpg"][0]
|
||||
ImageRepository(config.img_dir).decode_all(config.private_key)
|
||||
|
||||
images = ImageRepository(config.img_dir).scan(config.private_key,calc_hash=True)
|
||||
image = [image for image in images if image["hash"] == naming_table_element_hash]
|
||||
self.assertEqual(len(list(config.img_dir.rglob("*.jpg"))), 9)
|
||||
self.assertEqual(len(image), 2)
|
||||
|
||||
def test_decode_all_preserves_inputs_when_decryption_fails(self) -> None:
|
||||
"""Verify failed decode-all leaves encrypted sources and the naming table intact."""
|
||||
self.skipTest("TODO: simulate decryption failure and assert source preservation")
|
||||
with TemporaryDirectory() as temporary_directory, \
|
||||
self.assertRaisesRegex(ValueError, "Hash mismatch for"):
|
||||
image_root = Path(temporary_directory)
|
||||
assets = Path(__file__).resolve().parents[1] / "assets"
|
||||
args = self.parse_args("--conf-dir", str(image_root),
|
||||
"--folder", str(image_root / "corrupt"),
|
||||
"--private-key", str(assets / "test_private_key.pem"))
|
||||
config = Config.load(args)
|
||||
shutil.copytree(assets / "corrupt" , config.img_dir)
|
||||
|
||||
with open(config.img_dir / "00001.jpg_enc", "r+b") as f:
|
||||
f.seek(0, 2)
|
||||
size = f.tell()
|
||||
middle = size // 2
|
||||
f.seek(middle)
|
||||
byte = f.read(1)
|
||||
corrupted = bytes([byte[0] ^ 0b00000011])
|
||||
f.seek(middle)
|
||||
f.write(corrupted)
|
||||
|
||||
ImageRepository(config.img_dir).decode_all(config.private_key)
|
||||
|
||||
shutil.copy(assets / "corrupt" / "00001.jpg_enc" , config.img_dir)
|
||||
ImageRepository(config.img_dir).decode_all(config.private_key)
|
||||
self.assertEqual(len(list(config.img_dir.rglob("*.jpg_enc"))), 0)
|
||||
self.assertEqual(len(list(config.img_dir.rglob("*.jpg"))), 8)
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
@@ -46,7 +46,7 @@ class ImageRepositoryTests(unittest.TestCase):
|
||||
monitors = ScreenLayout((Monitor(1920, 1080,0,set("TestMon1")),))
|
||||
WallpaperBuilder().build(images, monitors, config.private_key, config.wallpaper_dir)
|
||||
|
||||
self.assertEqual( sum(1 for image in images if image["file"].suffix == ".jpg_enc"), 8)
|
||||
self.assertEqual(len(list(config.img_dir.rglob("*.jpg_enc"))), 8)
|
||||
self.assertTrue((config.wallpaper_dir/"wallpaper.jpg").exists())
|
||||
|
||||
def test_build_wallpaper_search(self) -> None:
|
||||
@@ -87,8 +87,8 @@ class ImageRepositoryTests(unittest.TestCase):
|
||||
|
||||
images = ImageRepository(config.img_dir).scan(config.private_key)
|
||||
|
||||
self.assertEqual( sum(1 for image in images if image["file"].suffix == ".jpg"), 1)
|
||||
self.assertEqual( sum(1 for image in images if image["file"].suffix == ".jpg_enc"), 8)
|
||||
self.assertEqual(len(list(config.img_dir.rglob("*.jpg"))), 1)
|
||||
self.assertEqual(len(list(config.img_dir.rglob("*.jpg_enc"))), 8)
|
||||
|
||||
def test_build_wallpaper_left(self) -> None:
|
||||
with TemporaryDirectory() as temporary_directory:
|
||||
|
||||
Reference in new issue
Block a user