aboutsummaryrefslogtreecommitdiffstats
path: root/desktop/assistant/test_fileops.py
diff options
context:
space:
mode:
Diffstat (limited to 'desktop/assistant/test_fileops.py')
-rwxr-xr-xdesktop/assistant/test_fileops.py41
1 files changed, 41 insertions, 0 deletions
diff --git a/desktop/assistant/test_fileops.py b/desktop/assistant/test_fileops.py
index 850d1d7..8fd8449 100755
--- a/desktop/assistant/test_fileops.py
+++ b/desktop/assistant/test_fileops.py
@@ -122,6 +122,47 @@ with tempfile.TemporaryDirectory() as src, tempfile.TemporaryDirectory() as out:
r, _ = fileops("audio", out, g)
assert not r["ok"] and "audio" in r["error"], r # a GIF has no audio track
+ # From review: each of these failed or misbehaved once.
+ anim = os.path.join(src, "anim.gif")
+ sh("magick", "-size", "8x8", "xc:red", "xc:blue", "-loop", "0", anim)
+ [ap] = one("png", anim) # first frame, no stray frame files
+ assert mime(ap) == "image/png" and not [n for n in os.listdir(out) if n.startswith(".")]
+ clear = os.path.join(src, "clear.png")
+ sh("magick", "-size", "8x8", "xc:none", clear)
+ [cj] = one("jpeg", clear) # transparency flattened onto white
+ assert subprocess.run(["magick", cj, "-format", "%[fx:int(255*p{0,0}.r)]", "info:"],
+ capture_output=True, text=True).stdout == "255"
+ dotted = os.path.join(src, "v1.2 notes.pdf")
+ sh("magick", "-size", "50x50", "xc:white", dotted)
+ names = [os.path.basename(one("pdf-images", dotted)[0]) for _ in range(2)]
+ assert names == ["v1.2 notes (pages)", "v1.2 notes (pages) (1)"], names
+ gz = os.path.join(src, "note.txt.gz")
+ sh("sh", "-c", f"gzip -c {os.path.join(src, 'note.txt')} > '{gz}'")
+ [gx] = one("extract", gz) # a single compressed file
+ assert os.path.basename(gx) == "note.txt" and open(gx).read() == "hello\n"
+ pgz = os.path.join(src, "pic.png.gz")
+ sh("sh", "-c", f"gzip -c '{png}' > '{pgz}'")
+ [px] = one("extract", pgz) # binary content survives
+ assert open(px, "rb").read() == open(png, "rb").read()
+ with open(os.path.join(src, ".bashrc"), "w") as fh:
+ fh.write("x\n")
+ [dz] = one("zip", os.path.join(src, ".bashrc"))
+ assert os.path.basename(dz) == "bashrc.zip"
+ with tempfile.TemporaryDirectory() as tree: # the output folder inside the input
+ inner = os.path.join(tree, "Assistant")
+ with open(os.path.join(tree, "a.txt"), "w") as fh:
+ fh.write("a\n")
+ os.mkfifo(os.path.join(tree, "pipe"))
+ os.symlink("/nonexistent", os.path.join(tree, "dangling"))
+ r, rc = fileops("zip", inner, tree)
+ assert r["ok"], r
+ import zipfile
+ assert sorted(zipfile.ZipFile(r["out"][0]).namelist()) == [os.path.basename(tree) + "/a.txt"]
+ stale = os.path.join(out, ".fileops-999999-0.png")
+ open(stale, "w").close()
+ one("png", png) # a dead run's leftovers are swept
+ assert not os.path.exists(stale)
+
# SIGTERM mid-encode (the canvas's Stop): no ffmpeg left, no partial file.
long_clip = os.path.join(src, "long.mp4")
sh("ffmpeg", "-v", "error", "-f", "lavfi", "-i", "testsrc=duration=20:size=1280x720:rate=30",