v0.49.0: a web mix can carry several images, one after another under the description

This commit is contained in:
2026-10-10 23:39:06 -07:00
parent 9f390b6102
commit 660740992a
7 changed files with 145 additions and 41 deletions
+2 -1
View File
@@ -311,7 +311,8 @@ class TestWebExport:
image = tmp_path / "friend.png"
image.write_bytes(b"\x89PNG\r\n\x1a\n" + b"fake")
dest, _ = self._export(
tmp_path, [_track(1, "S", "A", _audio(tmp_path, "a.mp3"))], image=image)
tmp_path, [_track(1, "S", "A", _audio(tmp_path, "a.mp3"))],
images=[image])
assert (dest / "friend.png").read_bytes() == image.read_bytes()
assert 'src="friend.png"' in (dest / "index.html").read_text()
+53 -1
View File
@@ -379,7 +379,7 @@ def window(qapp, tmp_path, monkeypatch):
class Web(Kind):
def values(self):
return {"title": "My Mix", "description": "", "image": None,
return {"title": "My Mix", "description": "", "images": [],
"accent": exporter.DEFAULT_ACCENT, "upload": True,
"slug": "my-mix"}
@@ -483,3 +483,55 @@ def test_finished_window_hides_stop(qapp):
win.finish("done")
assert win._stop.isHidden() and win._hide.text() == "Close"
win.close()
# ---- several images ----
def test_choosing_an_image_adds_another_row(qapp, tmp_path):
from lintunes.gui.export_dialog import WebMixDialog
dialog = WebMixDialog("Mix", None, {})
assert len(dialog._images) == 1 and dialog.values()["images"] == []
dialog._set_image(dialog._images[0], str(tmp_path / "a.png"))
assert len(dialog._images) == 2 and not dialog._images[1].text()
dialog._set_image(dialog._images[1], str(tmp_path / "b.png"))
assert len(dialog._images) == 3
# Re-choosing an earlier row doesn't add one.
dialog._set_image(dialog._images[0], str(tmp_path / "c.png"))
assert len(dialog._images) == 3
assert dialog.values()["images"] == [tmp_path / "c.png",
tmp_path / "b.png"]
def test_clearing_a_row_removes_it_but_keeps_an_empty_one(qapp, tmp_path):
from lintunes.gui.export_dialog import WebMixDialog
dialog = WebMixDialog("Mix", None, {})
dialog._set_image(dialog._images[0], str(tmp_path / "a.png"))
dialog._set_image(dialog._images[1], str(tmp_path / "b.png"))
dialog._clear_image(dialog._images[0])
assert dialog.values()["images"] == [tmp_path / "b.png"]
assert len(dialog._images) == 2 and not dialog._images[-1].text()
dialog._clear_image(dialog._images[-1]) # the empty one stays
assert len(dialog._images) == 2
def test_several_images_land_in_order_with_a_gap(tmp_path):
a = tmp_path / "pics" / "cover.png"
b = tmp_path / "pics2" / "cover.png" # same name, other folder
c = tmp_path / "pics" / "band.jpg"
for path, data in ((a, b"A"), (b, b"B"), (c, b"C")):
path.parent.mkdir(parents=True, exist_ok=True)
path.write_bytes(data)
plan = exporter.plan_export(
"Mix", [_track(1, _audio(tmp_path, "a.mp3"))], tmp_path / "out",
exporter.WEB)
plan.images = [a, b, c]
worker = exporter.ExportWorker(plan)
worker._run()
dest = tmp_path / "out" / "Mix"
page = (dest / "index.html").read_text()
names = ["cover.png", "cover 2.png", "band.jpg"]
spots = [page.index(f'src="{n}"') for n in names]
assert spots == sorted(spots)
assert page[spots[0]:spots[1]].count("<br><br>") == 1
assert (dest / "cover 2.png").read_bytes() == b"B"
assert not (dest / "placeholder.png").exists()