Add the local-only DuckDuckGo reference collector
This commit is contained in:
1 parent
03f4d4bc49
commit
43c17ce3c0
4 files changed
+237
-4
No files matched your search
@@ -0,0 +1,51 @@
|
||||
"""Tests for the local-only reference collector (no network)."""
|
||||
|
||||
import json
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
from tempfile import TemporaryDirectory
|
||||
from unittest import mock
|
||||
|
||||
import refcollect as rc
|
||||
|
||||
|
||||
class SlugTests(unittest.TestCase):
|
||||
def test_slug_folds_and_strips(self):
|
||||
self.assertEqual(rc._slug("El Capitan Entertainment Centre"),
|
||||
"el-capitan-entertainment-centre")
|
||||
self.assertEqual(rc._slug(" !!! "), "block")
|
||||
|
||||
|
||||
class ManifestTests(unittest.TestCase):
|
||||
def test_manifest_rows_are_marked_local_only_and_never_licenced(self):
|
||||
rows = [{"title": "t", "image": "https://x/i.jpg", "thumbnail": "",
|
||||
"source": "https://x/", "width": 640, "height": 480}]
|
||||
out = rc._manifest_rows(rows)
|
||||
self.assertTrue(out[0]["local_only"])
|
||||
self.assertEqual(out[0]["licence"], "unchecked-local")
|
||||
|
||||
|
||||
class SheetTests(unittest.TestCase):
|
||||
def test_sheet_requires_a_manifest(self):
|
||||
with TemporaryDirectory() as tmp:
|
||||
with mock.patch.object(rc, "RESEARCH_DIR", Path(tmp)):
|
||||
with self.assertRaises(SystemExit):
|
||||
rc.cmd_sheet(mock.Mock(slug="nope"))
|
||||
|
||||
def test_sheet_composes_from_downloaded_frames(self):
|
||||
from PIL import Image
|
||||
with TemporaryDirectory() as tmp:
|
||||
root = Path(tmp)
|
||||
slug_dir = root / "block"
|
||||
slug_dir.mkdir()
|
||||
for i in range(3):
|
||||
Image.new("RGB", (640, 400), (i * 60, 0, 0)).save(slug_dir / f"{i:02d}.jpg")
|
||||
(slug_dir / "manifest.json").write_text(json.dumps([
|
||||
{"file": "00.jpg"}, {"file": "01.jpg"}, {"file": "02.jpg"}]))
|
||||
with mock.patch.object(rc, "RESEARCH_DIR", root):
|
||||
rc.cmd_sheet(mock.Mock(slug="block"))
|
||||
self.assertTrue((slug_dir / "sheet.jpg").is_file())
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user