mirror of
https://gitlab.gnome.org/GNOME/gimp.git
synced 2025-07-03 09:23:24 +00:00
libgimp/tests: Port libgimp-run-python-test.sh to Python
This commit is contained in:
parent
54697c1d3c
commit
f158cc2b6e
4 changed files with 35 additions and 29 deletions
|
@ -16,4 +16,4 @@ cmd = (
|
|||
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)
|
||||
subprocess.run([sys.executable, GIMP_EXE, "-nis", "--batch-interpreter", "python-fu-eval", "-b", cmd, "--quit"], check=True)
|
||||
|
|
33
libgimp/tests/libgimp-run-python-test.py
Normal file
33
libgimp/tests/libgimp-run-python-test.py
Normal file
|
@ -0,0 +1,33 @@
|
|||
#!/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()
|
||||
|
||||
if not os.path.isfile(TEST_FILE):
|
||||
print(f"ERROR: file '{TEST_FILE}' does not exist!")
|
||||
sys.exit(1)
|
||||
|
||||
with open(TEST_FILE, 'r') as f:
|
||||
first_char = f.read(1)
|
||||
|
||||
if first_char != '#':
|
||||
# Note: I don't actually care that it's a shebang, just that it's a comment,
|
||||
# hence a useless line, because I'm going to remove it and replace it with
|
||||
# gimp_assert() import line.
|
||||
# This will make much easier to debug tests with meaningful line numbers.
|
||||
print(f"ERROR: file '{TEST_FILE}' should start with a shebang: #!/usr/bin/env python3")
|
||||
sys.exit(1)
|
||||
|
||||
header = f"""import os; import sys; sys.path.insert(0, '{SRC_DIR}'); from pygimp.utils import gimp_assert;
|
||||
import pygimp.utils; pygimp.utils.gimp_test_filename = '{TEST_FILE}'"""
|
||||
|
||||
with open(TEST_FILE, 'r') as f:
|
||||
content = f.readlines()
|
||||
cmd = header + ''.join(content[1:])
|
||||
subprocess.run([sys.executable, GIMP_EXE, "-nis", "--batch-interpreter", "python-fu-eval", "-b", cmd, "--quit"], check=True)
|
|
@ -1,27 +0,0 @@
|
|||
#!/bin/sh
|
||||
|
||||
GIMP_EXE=$1
|
||||
TEST_FILE=$2
|
||||
SRC_DIR=`dirname $TEST_FILE`
|
||||
SRC_DIR=`realpath $SRC_DIR`
|
||||
|
||||
if [ ! -f "$TEST_FILE" ]; then
|
||||
echo "ERROR: file '$TEST_FILE' does not exist!"
|
||||
return 1;
|
||||
fi
|
||||
|
||||
first_char=`head -c1 "$TEST_FILE"`
|
||||
|
||||
if [ $first_char != '#' ]; then
|
||||
# Note: I don't actually care that it's a shebang, just that it's a comment,
|
||||
# hence a useless line, because I'm going to remove it and replace it with
|
||||
# gimp_assert() import line.
|
||||
# This will make much easier to debug tests with meaningful line numbers.
|
||||
echo "ERROR: file '$TEST_FILE' should start with a shebang: #!/usr/bin/env python3"
|
||||
return 1;
|
||||
fi
|
||||
|
||||
header="import os; import sys; sys.path.insert(0, '$SRC_DIR'); from pygimp.utils import gimp_assert;"
|
||||
header="$header import pygimp.utils; pygimp.utils.gimp_test_filename = '$TEST_FILE'"
|
||||
|
||||
(echo "$header" && tail -n +2 "$TEST_FILE") | python3 "$GIMP_EXE" -nis --batch-interpreter "python-fu-eval" -b - --quit
|
|
@ -23,7 +23,7 @@ test_env=gimp_run_env
|
|||
test_env.append('GIMP_TESTING_PLUGINDIRS', meson.project_build_root() / 'libgimp/tests/c-tests/')
|
||||
test_env.set('GIMP_TESTING_ABS_TOP_SRCDIR', meson.project_source_root())
|
||||
|
||||
run_python_test = find_program('./libgimp-run-python-test.sh')
|
||||
run_python_test = find_program('./libgimp-run-python-test.py')
|
||||
run_c_test = find_program('./libgimp-run-c-test.py')
|
||||
foreach test_name : tests
|
||||
basename = 'test-' + test_name
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue