implement custom output path flag and integration tests

This commit is contained in:
2026-08-08 12:22:44 +03:00
parent f42059fc61
commit 4c48af7679
2 changed files with 47 additions and 5 deletions
+30
View File
@@ -126,6 +126,34 @@ def test_invalid_format(binary, workdir):
"missing unknown-image-format message")
def test_custom_output(binary, workdir):
img = os.path.join(workdir, "solid.png")
make_png(img, 40, 40, (100, 150, 200))
custom_json = os.path.join(workdir, "custom_palette.json")
rc, out = run(binary, img, "-o", custom_json, cwd=workdir)
assert_(rc == 0, "custom-output: expected exit 0, got %d" % rc)
assert_(os.path.exists(custom_json), "custom JSON file was not written at: %s" % custom_json)
# Default palette.json must NOT be written when -o is given with a different path.
default_json = os.path.join(workdir, "palette.json")
assert_(not os.path.exists(default_json), "default palette.json should not be written when -o is used")
with open(custom_json) as f:
data = json.load(f)
assert_(data["image"] == img, "custom palette.json image field mismatch")
palette = data["palette"]
assert_(isinstance(palette, list) and 1 <= len(palette) <= 5,
"palette must be a non-empty list of at most 5 entries")
def test_custom_output_bad_path(binary, workdir):
img = os.path.join(workdir, "solid.png")
make_png(img, 40, 40, (100, 150, 200))
bad_path = os.path.join(workdir, "nonexistent_dir", "out.json")
rc, out = run(binary, img, "-o", bad_path, cwd=workdir)
assert_(rc != 0, "bad-output-path: expected non-zero exit, got 0")
assert_(b"Cannot open output file" in out,
"missing 'Cannot open output file' error message")
def main():
if len(sys.argv) < 2:
print("usage: %s <path-to-ccolors-binary>" % sys.argv[0], file=sys.stderr)
@@ -141,6 +169,8 @@ def main():
("happy_path_jpeg", lambda d: test_happy_path_jpeg(binary, d)),
("file_not_found", lambda d: test_file_not_found(binary, d)),
("invalid_format", lambda d: test_invalid_format(binary, d)),
("custom_output", lambda d: test_custom_output(binary, d)),
("custom_output_bad_path", lambda d: test_custom_output_bad_path(binary, d)),
]
failures = []
for name, fn in tests: