Skip to content

Commit 3574dd7

Browse files
committed
Remove extra test folder need entirely. nanobind version is tested automatically when needed.
Signed-off-by: Aleksandr Motsjonov <soswow@gmail.com>
1 parent 1585183 commit 3574dd7

File tree

8 files changed

+114
-93
lines changed

8 files changed

+114
-93
lines changed

src/cmake/testing.cmake

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -233,9 +233,6 @@ macro (oiio_add_all_tests)
233233
python-imageinput python-imagebufalgo
234234
IMAGEDIR oiio-images
235235
)
236-
if (OIIO_BUILD_PYTHON_NANOBIND)
237-
oiio_add_tests (python-roi-nanobind python-typedesc-nanobind)
238-
endif ()
239236
endif ()
240237

241238
oiio_add_tests (oiiotool-color

testsuite/common/pythonbinding_loaders.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from __future__ import annotations
88

99
import importlib
10+
import importlib.util
1011
import pathlib
1112
import sys
1213

@@ -25,3 +26,37 @@ def load_nanobind_oiio_package(build_root: pathlib.Path):
2526

2627
sys.path.insert(0, str(package_root))
2728
return importlib.import_module("OpenImageIO")
29+
30+
31+
def load_python_test_run(test_name: str, script_path: pathlib.Path):
32+
"""Load ``run(oiio)`` from a canonical Python testsuite module by path.
33+
34+
The nanobind migration runners are executed as standalone scripts by
35+
``runtest.py``, so they cannot rely on package-relative imports. This
36+
helper locates the original pybind11 test module under ``testsuite`` and
37+
returns its exported ``run`` function.
38+
"""
39+
testsuite_root = None
40+
for parent in [script_path.resolve().parent] + list(script_path.resolve().parents):
41+
if parent.name == "testsuite":
42+
testsuite_root = parent
43+
break
44+
if testsuite_root is None:
45+
raise RuntimeError(f"Could not determine testsuite root from {script_path}")
46+
47+
test_src_dir = testsuite_root / test_name / "src"
48+
test_modules = sorted(test_src_dir.glob("*.py"))
49+
if len(test_modules) != 1:
50+
raise RuntimeError(
51+
f"Expected exactly one Python test module in {test_src_dir}, "
52+
f"found {len(test_modules)}"
53+
)
54+
test_module = test_modules[0]
55+
spec = importlib.util.spec_from_file_location(f"oiio_{test_name}_module",
56+
test_module)
57+
if spec is None or spec.loader is None:
58+
raise RuntimeError(f"Could not load Python test module from {test_module}")
59+
60+
module = importlib.util.module_from_spec(spec)
61+
spec.loader.exec_module(module)
62+
return module.run
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/usr/bin/env python
2+
3+
# Copyright Contributors to the OpenImageIO project.
4+
# SPDX-License-Identifier: Apache-2.0
5+
# https://github.com/AcademySoftwareFoundation/OpenImageIO
6+
7+
from __future__ import annotations
8+
9+
import pathlib
10+
import sys
11+
12+
from pythonbinding_loaders import load_nanobind_oiio_package, load_python_test_run
13+
14+
15+
def main() -> int:
16+
if len(sys.argv) != 3:
17+
raise SystemExit(
18+
"Usage: run_nanobind_python_test.py <canonical-test-name> <build-root>"
19+
)
20+
21+
test_name = sys.argv[1]
22+
build_root = pathlib.Path(sys.argv[2]).resolve()
23+
run = load_python_test_run(test_name, pathlib.Path(__file__))
24+
oiio = load_nanobind_oiio_package(build_root)
25+
26+
try:
27+
run(oiio)
28+
except Exception as detail:
29+
print("Unknown exception:", detail)
30+
return 0
31+
32+
33+
if __name__ == "__main__":
34+
raise SystemExit(main())

testsuite/python-roi-nanobind/run.py

Lines changed: 0 additions & 8 deletions
This file was deleted.

testsuite/python-roi-nanobind/src/test_roi_nanobind.py

Lines changed: 0 additions & 34 deletions
This file was deleted.

testsuite/python-typedesc-nanobind/run.py

Lines changed: 0 additions & 8 deletions
This file was deleted.

testsuite/python-typedesc-nanobind/src/test_typedesc_nanobind.py

Lines changed: 0 additions & 35 deletions
This file was deleted.

testsuite/runtest.py

Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,13 @@ def make_relpath (path: str, start: str=os.curdir) -> str:
8282
test_source_dir = os.getenv('OIIO_TESTSUITE_SRC',
8383
os.path.join(OIIO_TESTSUITE_ROOT, mytest))
8484

85+
# Python tests listed here also run against the staged nanobind package when
86+
# it exists in the current build tree.
87+
nanobind_python_tests = {
88+
"python-roi",
89+
"python-typedesc",
90+
}
91+
8592
def oiio_app (app: str) -> str:
8693
if (platform.system () != 'Windows' or options.devenv_config == ""):
8794
cmd = os.path.join(OIIO_BUILD_ROOT, "bin", app) + " "
@@ -101,6 +108,7 @@ def oiio_app (app: str) -> str:
101108

102109
command = ""
103110
outputs = [ "out.txt" ] # default
111+
ref_name_overrides = {}
104112

105113
# The image comparison thresholds are tricky to remember. Here's the key:
106114
# A test fails if more than `failpercent` of pixel values differ by more
@@ -354,16 +362,18 @@ def oiiotool (args: str, silent: bool=False, concat: bool=True, failureok: bool=
354362
# the identical name, and if that fails, it will look for alternatives of
355363
# the form "basename-*.ext" (or ANY match in the ref directory, if anymatch
356364
# is True).
357-
def checkref (name: str, refdirlist: list[str]) -> tuple[bool, str]:
365+
def checkref (name: str, refdirlist: list[str], refname: str|None=None) -> tuple[bool, str]:
358366
# Break the output into prefix+extension
359-
(prefix, extension) = os.path.splitext(name)
367+
if refname is None:
368+
refname = name
369+
(prefix, extension) = os.path.splitext(refname)
360370
ok = 0
361371
for ref in refdirlist :
362372
# We will first compare name to ref/name, and if that fails, we will
363373
# compare it to everything else that matches ref/prefix-*.extension.
364374
# That allows us to have multiple matching variants for different
365375
# platforms, etc.
366-
defaulttest = os.path.join(ref,name)
376+
defaulttest = os.path.join(ref,refname)
367377
if anymatch :
368378
pattern = "*.*"
369379
else :
@@ -437,7 +447,8 @@ def runtest (command: str, outputs: list[str], failureok: int=0) -> int :
437447
if os.path.exists('crlf.txt') :
438448
os.remove('crlf.txt')
439449

440-
(ok, testfile) = checkref (out, refdirlist)
450+
refname = ref_name_overrides.get(out, out)
451+
(ok, testfile) = checkref (out, refdirlist, refname=refname)
441452

442453
if ok :
443454
if extension in image_extensions :
@@ -477,13 +488,42 @@ def runtest (command: str, outputs: list[str], failureok: int=0) -> int :
477488

478489

479490
#
480-
# Read the individual run.py file for this test, which will define
491+
# Read the individual run.py file for this test, which will define
481492
# command and outputs.
482493
#
483494
with open(os.path.join(test_source_dir,"run.py")) as f:
484495
code = compile(f.read(), "run.py", 'exec')
485496
exec (code)
486497

498+
# For tests that have a nanobind port, run the same canonical Python test
499+
# body a second time against the staged nanobind package from the current
500+
# build tree. Keep the output separate so failures still indicate which
501+
# backend mismatched the shared reference output.
502+
nanobind_package = os.path.join(
503+
OIIO_BUILD_ROOT, "lib", "python", "nanobind", "OpenImageIO", "__init__.py"
504+
)
505+
if mytest in nanobind_python_tests and os.path.exists(nanobind_package):
506+
nanobind_runner = make_relpath(
507+
os.path.join(OIIO_TESTSUITE_ROOT, "common", "run_nanobind_python_test.py"),
508+
tmpdir,
509+
)
510+
command += " ; " + (
511+
pythonbin
512+
+ " "
513+
+ nanobind_runner
514+
+ " "
515+
+ mytest
516+
+ " "
517+
+ OIIO_BUILD_ROOT
518+
+ " > out-nanobind.txt"
519+
)
520+
# Example of final command for `python-roi` would be:
521+
# python src/test_roi.py > out.txt ; \
522+
# python ../../../testsuite/common/run_nanobind_python_test.py \
523+
# python-roi ../.. > out-nanobind.txt
524+
outputs.append("out-nanobind.txt")
525+
ref_name_overrides["out-nanobind.txt"] = "out.txt"
526+
487527
# Allow a little more slop for slight pixel differences when in DEBUG
488528
# mode or when running on remote CI machines.
489529
if (os.getenv('CI') or os.getenv('DEBUG')) :

0 commit comments

Comments
 (0)