libgimp: Port libgimp-run-c-test.sh to Python

This commit is contained in:
Bruno Lopes 2025-04-18 21:47:25 -03:00
parent 8ef7bf3553
commit 23b8867115
No known key found for this signature in database
3 changed files with 20 additions and 14 deletions

View file

@ -0,0 +1,19 @@
#!/usr/bin/env python3
import os
import sys
import subprocess
from pathlib import Path
GIMP_EXE = sys.argv[1]
TEST_FILE = sys.argv[2]
SRC_DIR = os.path.dirname(TEST_FILE)
SRC_DIR = Path(os.path.realpath(SRC_DIR)).resolve().as_posix()
TEST_NAME = sys.argv[3]
cmd = (
f"import os; import sys; sys.path.insert(0, '{SRC_DIR}'); from pygimp.utils import gimp_c_assert; "
f"proc = Gimp.get_pdb().lookup_procedure('{TEST_NAME}'); gimp_c_assert('{TEST_FILE}', 'Test PDB procedure does not exist: {{}}'.format('{TEST_NAME}'), proc is not None); "
f"result = proc.run(None); "
f"print('SUCCESS') if result.index(0) == Gimp.PDBStatusType.SUCCESS else gimp_c_assert('{TEST_FILE}', result.index(1), False);"
)
subprocess.run(['python3', GIMP_EXE, "-nis", "--batch-interpreter", "python-fu-eval", "-b", cmd, "--quit"], check=True)

View file

@ -1,13 +0,0 @@
#!/bin/sh
GIMP_EXE=$1
TEST_FILE=$2
SRC_DIR=`dirname $TEST_FILE`
SRC_DIR=`realpath $SRC_DIR`
TEST_NAME=$3
cmd="import os; import sys; sys.path.insert(0, '$SRC_DIR'); from pygimp.utils import gimp_c_assert;"
cmd="$cmd proc = Gimp.get_pdb().lookup_procedure('$TEST_NAME'); gimp_c_assert('$TEST_FILE', 'Test PDB procedure does not exist: {}'.format('$TEST_NAME'), proc is not None);"
cmd="$cmd result = proc.run(None);"
cmd="$cmd print('SUCCESS') if result.index(0) == Gimp.PDBStatusType.SUCCESS else gimp_c_assert('$TEST_FILE', result.index(1), False);"
echo "$cmd" | python3 "$GIMP_EXE" -nis --batch-interpreter "python-fu-eval" -b - --quit

View file

@ -24,7 +24,7 @@ test_env.append('GIMP_TESTING_PLUGINDIRS', meson.project_build_root() / 'libgimp
test_env.set('GIMP_TESTING_ABS_TOP_SRCDIR', meson.project_source_root())
run_python_test = find_program('./libgimp-run-python-test.sh')
run_c_test = find_program('./libgimp-run-c-test.sh')
run_c_test = find_program('./libgimp-run-c-test.py')
foreach test_name : tests
basename = 'test-' + test_name