@@ -82,6 +82,13 @@ def make_relpath (path: str, start: str=os.curdir) -> str:
8282test_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+
8592def 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
102109command = ""
103110outputs = [ "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#
483494with 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.
489529if (os .getenv ('CI' ) or os .getenv ('DEBUG' )) :
0 commit comments