T-566 封面历史归档数据层
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import os
|
||||
import sys
|
||||
import tempfile
|
||||
import unittest
|
||||
from types import SimpleNamespace
|
||||
|
||||
@@ -33,6 +34,46 @@ class ImagePathTests(unittest.TestCase):
|
||||
path,
|
||||
)
|
||||
|
||||
def test_list_task_cover_candidates_filters_and_sorts_generated_covers(self):
|
||||
with tempfile.TemporaryDirectory() as temp_dir:
|
||||
task = SimpleNamespace(id=42, batch_id="batch-a", item_id="51100639510", alias="alias-a")
|
||||
canonical = image_paths.task_image_path(temp_dir, task, suffix="new")
|
||||
directory = os.path.dirname(canonical)
|
||||
prefix = os.path.splitext(os.path.basename(canonical))[0]
|
||||
os.makedirs(directory, exist_ok=True)
|
||||
filenames = [
|
||||
f"{prefix}_20260709094800.jpg",
|
||||
f"{prefix}_20260709094800_2.jpg",
|
||||
f"{prefix}_20260709094900.jpg",
|
||||
f"{prefix}.jpg",
|
||||
f"{prefix}_bad.jpg",
|
||||
f"{prefix.replace('_new', '_old')}.jpg",
|
||||
f"{prefix}.png",
|
||||
"99_51100639510_new.jpg",
|
||||
]
|
||||
for filename in filenames:
|
||||
with open(os.path.join(directory, filename), "wb") as fh:
|
||||
fh.write(b"jpeg")
|
||||
|
||||
paths = image_paths.list_task_cover_candidates(temp_dir, task)
|
||||
|
||||
self.assertEqual(
|
||||
[
|
||||
canonical,
|
||||
os.path.join(directory, f"{prefix}_20260709094900.jpg"),
|
||||
os.path.join(directory, f"{prefix}_20260709094800_2.jpg"),
|
||||
os.path.join(directory, f"{prefix}_20260709094800.jpg"),
|
||||
os.path.join(directory, f"{prefix}_bad.jpg"),
|
||||
],
|
||||
paths,
|
||||
)
|
||||
|
||||
def test_list_task_cover_candidates_returns_empty_for_missing_directory(self):
|
||||
with tempfile.TemporaryDirectory() as temp_dir:
|
||||
task = SimpleNamespace(id=42, batch_id="batch-a", item_id="51100639510", alias="alias-a")
|
||||
|
||||
self.assertEqual([], image_paths.list_task_cover_candidates(temp_dir, task))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user