From 5447f7adf8b0703988e4e73a785732e4add5ed8b Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Thu, 11 Jul 2024 05:28:50 +0200 Subject: [PATCH] test: add more tests, check some output, improve readability --- test/test.py | 156 ++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 123 insertions(+), 33 deletions(-) diff --git a/test/test.py b/test/test.py index 721db6a1..7ecaad98 100755 --- a/test/test.py +++ b/test/test.py @@ -1,24 +1,50 @@ #! /usr/bin/env python3 +import hashlib import os import subprocess import sys +from colorama import Fore, Style -def print_command(command_list): - print("running: " + " ".join(command_list), file=sys.stderr) +def print_status(message): + print("{}{}{}".format(Fore.CYAN, message, Style.RESET_ALL), file=sys.stderr) + +def print_success(message): + print("{}{}{}".format(Fore.GREEN, message, Style.RESET_ALL), file=sys.stderr) + +def print_error(message): + print("{}{}{}".format(Fore.RED, message, Style.RESET_ALL), file=sys.stderr) + exit(1) + +def print_command_run(command_list): + print_status("Running command: {}".format(" ".join(command_list))) + +def print_command_success(command_list): + print_success("Command succeeded: {}".format(" ".join(command_list))) def convert_path(path): return path.replace("/", os.path.sep) +def check_file(file_path, known_sum): + print_status("Checking file: {}".format(file_path)) + check_sum = hashlib.blake2b(open(file_path, "rb").read()).hexdigest() + if check_sum != known_sum: + print_error("Error: {}'s checksum {} doesn't match known {}".format(file_path, check_sum, known_sum)) + print_success("File check succeeded: {}".format(file_path)) + def run(command_list): - print_command(command_list) + print_command_run(command_list) returncode = subprocess.run(command_list).returncode if returncode: + print_error("Command failed: {}".format(" ".join(command_list))) exit(returncode) + print_command_success(command_list) def mkdir(path): - print_command(["mkdir", path]) + command_list = ["mkdir", path] + print_command_run(command_list) os.makedirs(path, exist_ok=True) + print_command_success(command_list) def crunch(input_path, output_path, options=[]): executable_extension = ["", ".exe"][sys.platform == 'win32'] @@ -35,57 +61,118 @@ def crunch(input_path, output_path, options=[]): if input_path: input_path = convert_path(input_path) output_path = convert_path(output_path) - command_list += ["-noTitle", "-file", input_path, "-out", output_path] + command_list += ["-noTitle", "-nostats", "-noprogress", "-file", input_path, "-out", output_path] run(command_list) +def crunch_check(input_path, output_path, known_sum): + crunch(input_path, output_path) + check_file(output_path, known_sum) + crunch(None, None, ["--help"]) +tga_sum="34434170b06843b2d4fb5964a4b8751ec3a151a7d03e351e45a5967508f6a21f6e40ffc214bb46640105c4058bc35e196ecb5dd3261528a64acfeff52034fb40" +bmp_sum="1c5f28be8151a8125346e9cf17b1bf6e3f9fe27f6947b164b7eefa8fd3732a2e4dff173c354a0cd4ed599cd604d4b8f916c0575b0a4b4b508acc68dc9b4067ae" +png_sum="71bb28da97cd778b99f131acaeb1c28ea37bae295a9e9934bed339508d8428587120c0da8f5bbc7963cdb77741ef789414f9d0d2c1e0da46026336efde147cc5" +crn_sum="a3b526e95f44b6a4c919bc8eb79f4debf592f0bccc163c900cd1b6f9add0ce58c3db9fc8dac1828d350bbcd915823d7743a0c114a533fbc08c163fcb4846d2f5" +dds_sum="ce98b21c574b4883e4aff4a0b92fd0f533f22e00ab753686f353111fa7503287c2c4dba25f2c2670508630d79b59464578e094461bad81ad803e1d58ed5e69f8" +ktx_sum="d82eab591163d802231722ef325571735971b6a9b0703ed8ea59b4a4144189825d96d3455605426453fb3ad8d7cc61f931c52b3e73df2bb6787f7408baeb4ac7" +jpg_sum="6cd22de7e2e5baced5ef16e84f816dde3049f822459d552ced4dcd4e3f9a16be82ee0747ed1479fe8339991176004b4ccc90380b7ef51292c7d9b518503a348d" + mkdir("build/test/png-to-all") -crunch("test/unvanquished_64.png", "build/test/png-to-all/unvanquished_64.crn") -crunch("test/unvanquished_64.png", "build/test/png-to-all/unvanquished_64.dds") -crunch("test/unvanquished_64.png", "build/test/png-to-all/unvanquished_64.ktx") -crunch("test/unvanquished_64.png", "build/test/png-to-all/unvanquished_64.tga") -crunch("test/unvanquished_64.png", "build/test/png-to-all/unvanquished_64.bmp") -crunch("test/unvanquished_64.png", "build/test/png-to-all/unvanquished_64.png") -crunch("test/unvanquished_64.png", "build/test/png-to-all/unvanquished_64.jpg") +crunch_check("test/unvanquished_64.png", "build/test/png-to-all/unvanquished_64.tga", tga_sum) +crunch_check("test/unvanquished_64.png", "build/test/png-to-all/unvanquished_64.bmp", bmp_sum) +crunch_check("test/unvanquished_64.png", "build/test/png-to-all/unvanquished_64.png", png_sum) +crunch_check("test/unvanquished_64.png", "build/test/png-to-all/unvanquished_64.crn", crn_sum) +crunch_check("test/unvanquished_64.png", "build/test/png-to-all/unvanquished_64.dds", dds_sum) +crunch_check("test/unvanquished_64.png", "build/test/png-to-all/unvanquished_64.ktx", ktx_sum) +crunch_check("test/unvanquished_64.png", "build/test/png-to-all/unvanquished_64.jpg", jpg_sum) + +mkdir("build/test/tga-to-all") +crunch_check("build/test/png-to-all/unvanquished_64.tga", "build/test/tga-to-all/unvanquished_64.tga", tga_sum) +crunch_check("build/test/png-to-all/unvanquished_64.tga", "build/test/tga-to-all/unvanquished_64.bmp", bmp_sum) +crunch_check("build/test/png-to-all/unvanquished_64.tga", "build/test/tga-to-all/unvanquished_64.png", png_sum) +crunch_check("build/test/png-to-all/unvanquished_64.tga", "build/test/tga-to-all/unvanquished_64.crn", crn_sum) +crunch_check("build/test/png-to-all/unvanquished_64.tga", "build/test/tga-to-all/unvanquished_64.dds", dds_sum) +crunch_check("build/test/png-to-all/unvanquished_64.tga", "build/test/tga-to-all/unvanquished_64.ktx", ktx_sum) +crunch_check("build/test/png-to-all/unvanquished_64.tga", "build/test/tga-to-all/unvanquished_64.jpg", jpg_sum) + +mkdir("build/test/bmp-to-all") +crunch_check("build/test/png-to-all/unvanquished_64.bmp", "build/test/bmp-to-all/unvanquished_64.tga", tga_sum) +crunch_check("build/test/png-to-all/unvanquished_64.bmp", "build/test/bmp-to-all/unvanquished_64.bmp", bmp_sum) +crunch_check("build/test/png-to-all/unvanquished_64.bmp", "build/test/bmp-to-all/unvanquished_64.png", png_sum) +crunch_check("build/test/png-to-all/unvanquished_64.bmp", "build/test/bmp-to-all/unvanquished_64.crn", crn_sum) +crunch_check("build/test/png-to-all/unvanquished_64.bmp", "build/test/bmp-to-all/unvanquished_64.dds", dds_sum) +crunch_check("build/test/png-to-all/unvanquished_64.bmp", "build/test/bmp-to-all/unvanquished_64.ktx", ktx_sum) +crunch_check("build/test/png-to-all/unvanquished_64.bmp", "build/test/bmp-to-all/unvanquished_64.jpg", jpg_sum) mkdir("build/test/crn-to-all") -crunch("build/test/png-to-all/unvanquished_64.crn", "build/test/crn-to-all/unvanquished_64.crn") -crunch("build/test/png-to-all/unvanquished_64.crn", "build/test/crn-to-all/unvanquished_64.dds") -crunch("build/test/png-to-all/unvanquished_64.crn", "build/test/crn-to-all/unvanquished_64.ktx") crunch("build/test/png-to-all/unvanquished_64.crn", "build/test/crn-to-all/unvanquished_64.tga") crunch("build/test/png-to-all/unvanquished_64.crn", "build/test/crn-to-all/unvanquished_64.bmp") crunch("build/test/png-to-all/unvanquished_64.crn", "build/test/crn-to-all/unvanquished_64.png") +crunch("build/test/png-to-all/unvanquished_64.crn", "build/test/crn-to-all/unvanquished_64.crn") +crunch("build/test/png-to-all/unvanquished_64.crn", "build/test/crn-to-all/unvanquished_64.dds") +crunch("build/test/png-to-all/unvanquished_64.crn", "build/test/crn-to-all/unvanquished_64.ktx") crunch("build/test/png-to-all/unvanquished_64.crn", "build/test/crn-to-all/unvanquished_64.jpg") mkdir("build/test/dds-to-all") -crunch("build/test/png-to-all/unvanquished_64.dds", "build/test/dds-to-all/unvanquished_64.crn") -crunch("build/test/png-to-all/unvanquished_64.dds", "build/test/dds-to-all/unvanquished_64.dds") -crunch("build/test/png-to-all/unvanquished_64.dds", "build/test/dds-to-all/unvanquished_64.ktx") crunch("build/test/png-to-all/unvanquished_64.dds", "build/test/dds-to-all/unvanquished_64.tga") crunch("build/test/png-to-all/unvanquished_64.dds", "build/test/dds-to-all/unvanquished_64.bmp") crunch("build/test/png-to-all/unvanquished_64.dds", "build/test/dds-to-all/unvanquished_64.png") +crunch("build/test/png-to-all/unvanquished_64.dds", "build/test/dds-to-all/unvanquished_64.crn") +crunch_check("build/test/png-to-all/unvanquished_64.dds", "build/test/dds-to-all/unvanquished_64.dds", dds_sum) +crunch("build/test/png-to-all/unvanquished_64.dds", "build/test/dds-to-all/unvanquished_64.ktx") crunch("build/test/png-to-all/unvanquished_64.dds", "build/test/dds-to-all/unvanquished_64.jpg") mkdir("build/test/ktx-to-all") -crunch("build/test/png-to-all/unvanquished_64.ktx", "build/test/ktx-to-all/unvanquished_64.crn") -crunch("build/test/png-to-all/unvanquished_64.ktx", "build/test/ktx-to-all/unvanquished_64.dds") -crunch("build/test/png-to-all/unvanquished_64.ktx", "build/test/ktx-to-all/unvanquished_64.ktx") crunch("build/test/png-to-all/unvanquished_64.ktx", "build/test/ktx-to-all/unvanquished_64.tga") crunch("build/test/png-to-all/unvanquished_64.ktx", "build/test/ktx-to-all/unvanquished_64.bmp") crunch("build/test/png-to-all/unvanquished_64.ktx", "build/test/ktx-to-all/unvanquished_64.png") +crunch("build/test/png-to-all/unvanquished_64.ktx", "build/test/ktx-to-all/unvanquished_64.crn") +crunch("build/test/png-to-all/unvanquished_64.ktx", "build/test/ktx-to-all/unvanquished_64.dds") +crunch("build/test/png-to-all/unvanquished_64.ktx", "build/test/ktx-to-all/unvanquished_64.ktx") crunch("build/test/png-to-all/unvanquished_64.ktx", "build/test/ktx-to-all/unvanquished_64.jpg") +mkdir("build/test/jpg-to-all") +crunch("build/test/png-to-all/unvanquished_64.jpg", "build/test/jpg-to-all/unvanquished_64.tga") +crunch("build/test/png-to-all/unvanquished_64.jpg", "build/test/jpg-to-all/unvanquished_64.bmp") +crunch("build/test/png-to-all/unvanquished_64.jpg", "build/test/jpg-to-all/unvanquished_64.png") +crunch("build/test/png-to-all/unvanquished_64.jpg", "build/test/jpg-to-all/unvanquished_64.crn") +crunch("build/test/png-to-all/unvanquished_64.jpg", "build/test/jpg-to-all/unvanquished_64.dds") +crunch("build/test/png-to-all/unvanquished_64.jpg", "build/test/jpg-to-all/unvanquished_64.ktx") +crunch("build/test/png-to-all/unvanquished_64.jpg", "build/test/jpg-to-all/unvanquished_64.jpg") + +mkdir("build/test/tga-to-png") +tga_png_sum="6238f9678cd9fa774e6d50ee6638f316d0b1148ade344c06b4ddebac4738ea90e93c19d5cca405fccdabfdb37898bc7f9bccce1f0d974f9cbd18ab54b66adaa3" +crunch_check("test/raw-bottom-left.tga", "build/test/tga-to-png/raw-bottom-left.png", tga_png_sum) +crunch_check("test/raw-bottom-right.tga", "build/test/tga-to-png/raw-bottom-right.png", tga_png_sum) +crunch_check("test/raw-top-left.tga", "build/test/tga-to-png/raw-top-left.png", tga_png_sum) +crunch_check("test/raw-top-right.tga", "build/test/tga-to-png/raw-top-right.png", tga_png_sum) +crunch_check("test/rle-bottom-left.tga", "build/test/tga-to-png/rle-bottom-left.png", tga_png_sum) +crunch_check("test/rle-bottom-right.tga", "build/test/tga-to-png/rle-bottom-right.png", tga_png_sum) +crunch_check("test/rle-top-left.tga", "build/test/tga-to-png/rle-top-left.png", tga_png_sum) +crunch_check("test/rle-top-right.tga", "build/test/tga-to-png/rle-top-right.png", tga_png_sum) + mkdir("build/test/tga-to-crn") -crunch("test/raw-bottom-left.tga", "build/test/tga-to-crn/raw-bottom-left.crn") -crunch("test/raw-bottom-right.tga", "build/test/tga-to-crn/raw-bottom-right.crn") -crunch("test/raw-top-left.tga", "build/test/tga-to-crn/raw-top-left.crn") -crunch("test/raw-top-right.tga", "build/test/tga-to-crn/raw-top-right.crn") -crunch("test/rle-bottom-left.tga", "build/test/tga-to-crn/rle-bottom-left.crn") -crunch("test/rle-bottom-right.tga", "build/test/tga-to-crn/rle-bottom-right.crn") -crunch("test/rle-top-left.tga", "build/test/tga-to-crn/rle-top-left.crn") -crunch("test/rle-top-right.tga", "build/test/tga-to-crn/rle-top-right.crn") +tga_crn_sum="fcf1da3fc69f6b05935deafacb1c637f44983b9992a7452f8f26a7787d5577c6548986366fae5fd6d300366de4acade853464e7656224b04673a7d129e006854" +crunch_check("test/raw-bottom-left.tga", "build/test/tga-to-crn/raw-bottom-left.crn", tga_crn_sum) +crunch_check("test/raw-bottom-right.tga", "build/test/tga-to-crn/raw-bottom-right.crn", tga_crn_sum) +crunch_check("test/raw-top-left.tga", "build/test/tga-to-crn/raw-top-left.crn", tga_crn_sum) +crunch_check("test/raw-top-right.tga", "build/test/tga-to-crn/raw-top-right.crn", tga_crn_sum) +crunch_check("test/rle-bottom-left.tga", "build/test/tga-to-crn/rle-bottom-left.crn", tga_crn_sum) +crunch_check("test/rle-bottom-right.tga", "build/test/tga-to-crn/rle-bottom-right.crn", tga_crn_sum) +crunch_check("test/rle-top-left.tga", "build/test/tga-to-crn/rle-top-left.crn", tga_crn_sum) +crunch_check("test/rle-top-right.tga", "build/test/tga-to-crn/rle-top-right.crn", tga_crn_sum) + +mkdir("build/test/png-to-png") +crunch_check("test/test-colormap1-alpha1.png", "build/test/png-to-png/test-colormap1-alpha1.png", "f596534970da37597230ae60112a4fe4d08d950e03b99754a633d9d285f4683624b1f710727d6b3e556b80b9d44428bfa297dc898beaf6fecad29fe98bbc98cb") +crunch_check("test/test-colormap2-alpha1.png", "build/test/png-to-png/test-colormap2-alpha1.png", "2ffd5907e77157dfaac01c786b5150dcf822699254bebdd51ef1797568208ae924a572d90bc3ed3a06cc5e524c4c0d5a3de7aa75ae99febc4638533e41a6dda0") +crunch_check("test/test-colormap4-alpha1.png", "build/test/png-to-png/test-colormap4-alpha1.png", "f8cd5a9b1ae040baee41a7f378e18bba426f79532555e22fe2f8c605a8347d79e7b98bb8284130536512b187f9d8435d58665eddb8d36596296f84f05ee904ae") +crunch_check("test/test-colormap8-alpha1.png", "build/test/png-to-png/test-colormap8-alpha1.png", "3561be7b7958d37913708664413c149942f302907bf5f928782c7cf6cc4b312082f51fea6d8a3271b93bd37ace03ec22af65c224d6e7617ed8644fbe2f95dc35") +crunch_check("test/test-grayscale1-alpha1.png", "build/test/png-to-png/test-grayscale1-alpha1.png", "57876e1d84ada2604c5e2dbbfd08c19286c87c8f1843cf47a9b77b4f6561c3b414a269f924c2be74bba4662503ede0fd9d94cb0a084c35a9f63a3cce07dcb876") +crunch_check("test/test-grayscale1-alpha8.png", "build/test/png-to-png/test-grayscale1-alpha8.png", "62ba2ca3669febcb88959224732c295d891f10942dcddf2494c052886c4f502b0e30c1238d05196ce8113c2c150fa4d96fc81436af5ad6a28f7b8a64a77bbe7f") +crunch_check("test/test-grayscale8-alpha1.png", "build/test/png-to-png/test-grayscale8-alpha1.png", "62ba2ca3669febcb88959224732c295d891f10942dcddf2494c052886c4f502b0e30c1238d05196ce8113c2c150fa4d96fc81436af5ad6a28f7b8a64a77bbe7f") +crunch_check("test/test-rgb8-alpha8.png", "build/test/png-to-png/test-rgb8-alpha8.png", "21630317b2ed9957241f4982c4e8207f7a00af23e0dd5df863965dbca9dcefd9a3c4f77b15ea91141c6c35181e44801ff1b5d0a7ed62f0c11eddfdaf7122b1a9") mkdir("build/test/png-to-crn") crunch("test/test-colormap1-alpha1.png", "build/test/png-to-crn/test-colormap1-alpha1.crn") @@ -95,11 +182,14 @@ def crunch(input_path, output_path, options=[]): crunch("test/test-grayscale1-alpha1.png", "build/test/png-to-crn/test-grayscale1-alpha1.crn") crunch("test/test-grayscale1-alpha8.png", "build/test/png-to-crn/test-grayscale1-alpha8.crn") crunch("test/test-grayscale8-alpha1.png", "build/test/png-to-crn/test-grayscale8-alpha1.crn") -crunch("test/test-rgb8-alpha8.png", "build/test/png-to-crn/test-rgb8-alpha8.crn") +crunch_check("test/test-rgb8-alpha8.png", "build/test/png-to-crn/test-rgb8-alpha8.crn", "87dcb6922f2f8ee8cab69d5f9a36e8e3b94ae0603fddd8e04c588128a006507af9475fa469cf1483b49a40a1a9cfb5cc9338de5b3085f6366b5b237d40c47fc1") mkdir("build/test/bmp-to-crn") -crunch("test/sample-default.bmp", "build/test/bmp-to-crn/sample-default.crn") -crunch("test/sample-vertical-flip.bmp", "build/test/bmp-to-crn/sample-vertical-flip.crn") +bmp_crn_sum="119f0f756811e56ba688c402ea317923d9665017aed19022ad19fc8396e45d3ca3bb7b5383f3edc00e859e31558a0865de88af71110529b16b89ded731070925" +crunch_check("test/sample-default.bmp", "build/test/bmp-to-crn/sample-default.crn", bmp_crn_sum) +crunch_check("test/sample-vertical-flip.bmp", "build/test/bmp-to-crn/sample-vertical-flip.crn", bmp_crn_sum) mkdir("build/test/jpg-to-crn") -crunch("test/black.jpg", "build/test/jpg-to-crn/black.crn") +crunch_check("test/black.jpg", "build/test/jpg-to-crn/black.crn", "19fb840c8dbb7da96400af5af1c45fe48c7c7e19340d03fbe5a2af28ceecfb9efba26fe6c1bf46bd76164ecb0efe91cc9237917e8e431cd8365f80e9ffacc906") + +print_success("All tests succeeded")