From c230488b2e7771f154c4e0fa1b28552e62d6062d Mon Sep 17 00:00:00 2001 From: Jonas Rembser Date: Sun, 8 Nov 2026 14:42:57 +0000 Subject: [PATCH 1/2] [tpython] Move the TPython tests from roottest to bindings/tpython/test Like this, they are only defined if `tpython=ON`. The macro and notebook tests keep using the roottest machinery, like in tmva/sofie/test. --- bindings/tpython/test/CMakeLists.txt | 35 +++++++++++++++++++ .../tpython/test}/MyModule.py | 0 .../tpython/test}/MyOtherPyClass.py | 0 .../tpython/test}/MyPyClass.py | 0 .../tpython/test}/PyAPITest.ref | 0 .../tpython/test}/PyClassTest.ref | 0 .../tpython/test}/PyClassTest1.C | 0 .../tpython/test}/PyClassTest2.C | 0 .../tpython/test}/PyClassTest3.C | 0 .../tpython/test}/PyClassTest4.C | 0 .../tpython/test}/execscript.C | 0 .../tpython/test}/execscript.py | 0 .../tpython/test}/runPyAPITestCppyy.C | 0 .../tpython/test}/runPyClassTest.C | 0 .../tpython/test}/tpython.ipynb | 0 roottest/python/JupyROOT/CMakeLists.txt | 3 +- roottest/python/cling/CMakeLists.txt | 24 ------------- roottest/python/tpython/CMakeLists.txt | 5 --- 18 files changed, 36 insertions(+), 31 deletions(-) rename {roottest/python/cling => bindings/tpython/test}/MyModule.py (100%) rename {roottest/python/cling => bindings/tpython/test}/MyOtherPyClass.py (100%) rename {roottest/python/cling => bindings/tpython/test}/MyPyClass.py (100%) rename {roottest/python/cling => bindings/tpython/test}/PyAPITest.ref (100%) rename {roottest/python/cling => bindings/tpython/test}/PyClassTest.ref (100%) rename {roottest/python/cling => bindings/tpython/test}/PyClassTest1.C (100%) rename {roottest/python/cling => bindings/tpython/test}/PyClassTest2.C (100%) rename {roottest/python/cling => bindings/tpython/test}/PyClassTest3.C (100%) rename {roottest/python/cling => bindings/tpython/test}/PyClassTest4.C (100%) rename {roottest/python/tpython => bindings/tpython/test}/execscript.C (100%) rename {roottest/python/tpython => bindings/tpython/test}/execscript.py (100%) rename {roottest/python/cling => bindings/tpython/test}/runPyAPITestCppyy.C (100%) rename {roottest/python/cling => bindings/tpython/test}/runPyClassTest.C (100%) rename {roottest/python/JupyROOT => bindings/tpython/test}/tpython.ipynb (100%) delete mode 100644 roottest/python/tpython/CMakeLists.txt diff --git a/bindings/tpython/test/CMakeLists.txt b/bindings/tpython/test/CMakeLists.txt index f56b36306cfa5..4b2f15bd2180f 100644 --- a/bindings/tpython/test/CMakeLists.txt +++ b/bindings/tpython/test/CMakeLists.txt @@ -24,3 +24,38 @@ if(NOT MSVC) ROOT_ADD_GTEST(testTPython testTPython.cxx LIBRARIES ROOTTPython ENVIRONMENT ${tpython_gtest_env}) ROOT_ADD_PYUNITTEST(test_tpython test_tpython.py) endif() + +# Tests using TPython from ROOT macros and from the C++ Jupyter kernel +set(ROOT_root_CMD $) + +# A test for issue #9058 +ROOTTEST_ADD_TEST(execscript + MACRO execscript.C + COPY_TO_BUILDDIR execscript.py + FAILREGEX "FAILURE") + +# On Windows, code JIT-compiled in the interpreter cannot resolve the +# CppInternal::DispatchRaw::MakeFunctionCallable_interp dispatch slot: it +# is a data symbol (a function-pointer variable), which the bindexplib +# generated export tables do not cover. Exporting writable data across a +# DLL boundary needs a considered fix (or an upstream CppInterOp change +# to register the dispatch slots by value instead of by symbol lookup). +if(NOT MSVC OR win_broken_tests) + ROOTTEST_ADD_TEST(api + MACRO runPyAPITestCppyy.C + WORKING_DIR ${CMAKE_CURRENT_SOURCE_DIR} + OUTREF PyAPITest.ref) +endif() + +if(NOT MSVC OR win_broken_tests) + ROOTTEST_ADD_TEST(class + MACRO runPyClassTest.C + WORKING_DIR ${CMAKE_CURRENT_SOURCE_DIR} + OUTREF PyClassTest.ref) +endif() + +ROOTTEST_ADD_TEST(notebook + COPY_TO_BUILDDIR tpython.ipynb + COMMAND ${Python3_EXECUTABLE} ${CMAKE_SOURCE_DIR}/roottest/python/JupyROOT/nbdiff.py tpython.ipynb + RUN_SERIAL + PYTHON_DEPS jupyter) diff --git a/roottest/python/cling/MyModule.py b/bindings/tpython/test/MyModule.py similarity index 100% rename from roottest/python/cling/MyModule.py rename to bindings/tpython/test/MyModule.py diff --git a/roottest/python/cling/MyOtherPyClass.py b/bindings/tpython/test/MyOtherPyClass.py similarity index 100% rename from roottest/python/cling/MyOtherPyClass.py rename to bindings/tpython/test/MyOtherPyClass.py diff --git a/roottest/python/cling/MyPyClass.py b/bindings/tpython/test/MyPyClass.py similarity index 100% rename from roottest/python/cling/MyPyClass.py rename to bindings/tpython/test/MyPyClass.py diff --git a/roottest/python/cling/PyAPITest.ref b/bindings/tpython/test/PyAPITest.ref similarity index 100% rename from roottest/python/cling/PyAPITest.ref rename to bindings/tpython/test/PyAPITest.ref diff --git a/roottest/python/cling/PyClassTest.ref b/bindings/tpython/test/PyClassTest.ref similarity index 100% rename from roottest/python/cling/PyClassTest.ref rename to bindings/tpython/test/PyClassTest.ref diff --git a/roottest/python/cling/PyClassTest1.C b/bindings/tpython/test/PyClassTest1.C similarity index 100% rename from roottest/python/cling/PyClassTest1.C rename to bindings/tpython/test/PyClassTest1.C diff --git a/roottest/python/cling/PyClassTest2.C b/bindings/tpython/test/PyClassTest2.C similarity index 100% rename from roottest/python/cling/PyClassTest2.C rename to bindings/tpython/test/PyClassTest2.C diff --git a/roottest/python/cling/PyClassTest3.C b/bindings/tpython/test/PyClassTest3.C similarity index 100% rename from roottest/python/cling/PyClassTest3.C rename to bindings/tpython/test/PyClassTest3.C diff --git a/roottest/python/cling/PyClassTest4.C b/bindings/tpython/test/PyClassTest4.C similarity index 100% rename from roottest/python/cling/PyClassTest4.C rename to bindings/tpython/test/PyClassTest4.C diff --git a/roottest/python/tpython/execscript.C b/bindings/tpython/test/execscript.C similarity index 100% rename from roottest/python/tpython/execscript.C rename to bindings/tpython/test/execscript.C diff --git a/roottest/python/tpython/execscript.py b/bindings/tpython/test/execscript.py similarity index 100% rename from roottest/python/tpython/execscript.py rename to bindings/tpython/test/execscript.py diff --git a/roottest/python/cling/runPyAPITestCppyy.C b/bindings/tpython/test/runPyAPITestCppyy.C similarity index 100% rename from roottest/python/cling/runPyAPITestCppyy.C rename to bindings/tpython/test/runPyAPITestCppyy.C diff --git a/roottest/python/cling/runPyClassTest.C b/bindings/tpython/test/runPyClassTest.C similarity index 100% rename from roottest/python/cling/runPyClassTest.C rename to bindings/tpython/test/runPyClassTest.C diff --git a/roottest/python/JupyROOT/tpython.ipynb b/bindings/tpython/test/tpython.ipynb similarity index 100% rename from roottest/python/JupyROOT/tpython.ipynb rename to bindings/tpython/test/tpython.ipynb diff --git a/roottest/python/JupyROOT/CMakeLists.txt b/roottest/python/JupyROOT/CMakeLists.txt index e817d1c4577c9..4850e05e1ef6e 100644 --- a/roottest/python/JupyROOT/CMakeLists.txt +++ b/roottest/python/JupyROOT/CMakeLists.txt @@ -11,8 +11,7 @@ set(DOCTEST_LAUNCHER ${CMAKE_CURRENT_SOURCE_DIR}/doctest_launcher.py) set(NOTEBOOKS importROOT.ipynb simpleCppMagic.ipynb thread_local.ipynb - ROOT_kernel.ipynb - tpython.ipynb) + ROOT_kernel.ipynb) # Test all modules with doctest. All new tests will be automatically picked up file(GLOB pyfiles ${MODULES_LOCATION}/*.py) diff --git a/roottest/python/cling/CMakeLists.txt b/roottest/python/cling/CMakeLists.txt index 483b6e82d5006..fcadcc4915f82 100644 --- a/roottest/python/cling/CMakeLists.txt +++ b/roottest/python/cling/CMakeLists.txt @@ -1,28 +1,4 @@ if(pyroot) - # On Windows, code JIT-compiled in the interpreter cannot resolve the - # CppInternal::DispatchRaw::MakeFunctionCallable_interp dispatch slot: it - # is a data symbol (a function-pointer variable), which the bindexplib - # generated export tables do not cover. Exporting writable data across a - # DLL boundary needs a considered fix (or an upstream CppInterOp change - # to register the dispatch slots by value instead of by symbol lookup). - if(NOT MSVC OR win_broken_tests) - set(api_macro_file runPyAPITestCppyy.C) # Uses new Cppyy API - ROOTTEST_ADD_TEST(api - MACRO ${api_macro_file} - WORKING_DIR ${CMAKE_CURRENT_SOURCE_DIR} - OUTREF PyAPITest.ref) - endif() - - # TPython::LoadMacro and TPython::Import are broken in the new Cppyy - # https://bitbucket.org/wlav/cppyy/issues/65 - # For now, we rely on our own implementation of TPython - if(NOT MSVC OR win_broken_tests) - ROOTTEST_ADD_TEST(class MACRO - runPyClassTest.C - WORKING_DIR ${CMAKE_CURRENT_SOURCE_DIR} - OUTREF PyClassTest.ref) - endif() - ROOTTEST_ADD_TEST(cling MACRO PyROOT_clingtests.py WORKING_DIR ${CMAKE_CURRENT_SOURCE_DIR} diff --git a/roottest/python/tpython/CMakeLists.txt b/roottest/python/tpython/CMakeLists.txt deleted file mode 100644 index 00006badde2ac..0000000000000 --- a/roottest/python/tpython/CMakeLists.txt +++ /dev/null @@ -1,5 +0,0 @@ -# A test for issue #9058 -configure_file(execscript.py . COPYONLY) -ROOTTEST_ADD_TEST(execscript - MACRO execscript.C - FAILREGEX "FAILURE") From c63d0adbb8d0d3c7de44a4dfc3b98f560343756d Mon Sep 17 00:00:00 2001 From: Jonas Rembser Date: Sun, 8 Nov 2026 15:02:15 +0000 Subject: [PATCH 2/2] [PyROOT] JIT-compile the PyException regression test The test compiled a macro with ACLiC in root.exe, which needed libROOTTPython to provide the Python library. Declaring the code to the interpreter from Python instead makes the PyROOT regression tests independent of TPython. --- roottest/python/regression/CMakeLists.txt | 8 +--- .../regression/PyROOT_regressiontests.py | 39 +++++++++++++++++-- roottest/python/regression/ScottCppyy.C | 29 -------------- 3 files changed, 37 insertions(+), 39 deletions(-) delete mode 100644 roottest/python/regression/ScottCppyy.C diff --git a/roottest/python/regression/CMakeLists.txt b/roottest/python/regression/CMakeLists.txt index 39676081a265c..38fa998332b83 100644 --- a/roottest/python/regression/CMakeLists.txt +++ b/roottest/python/regression/CMakeLists.txt @@ -1,15 +1,11 @@ if(pyroot) - set(scott_file ScottCppyy.C) # Uses Cppyy header - if(NOT MSVC OR win_broken_tests) ROOTTEST_ADD_TEST(regression MACRO PyROOT_regressiontests.py OPTS -b LABELS longtest - COPY_TO_BUILDDIR ${scott_file} Scott3.C MuonTileID.C + COPY_TO_BUILDDIR Scott3.C MuonTileID.C CoralAttributeList.C Marco.C - PRECMD ${ROOT_root_CMD} -b -q -e gSystem->Load\(\"libROOTTPython\"\) - -e .L\ ${scott_file}+ - -e .L\ Scott3.C+ + PRECMD ${ROOT_root_CMD} -b -q -e .L\ Scott3.C+ -e .L\ MuonTileID.C+ -e .L\ CoralAttributeList.C+) endif() diff --git a/roottest/python/regression/PyROOT_regressiontests.py b/roottest/python/regression/PyROOT_regressiontests.py index 8ebf8eccccae2..7de99f55b8318 100644 --- a/roottest/python/regression/PyROOT_regressiontests.py +++ b/roottest/python/regression/PyROOT_regressiontests.py @@ -17,7 +17,7 @@ import sys, os, unittest sys.path.append(os.path.dirname(os.path.dirname(__file__))) -if not os.path.exists('ScottCppyy.C'): +if not os.path.exists('Scott3.C'): os.chdir(os.path.dirname(__file__)) try: @@ -65,11 +65,42 @@ def test1FromROOTImportStarInModule( self ): x = TestTChain() # TestTChain defined in Amir.py -# TPyException thrown from C++ code ======================================== +# PyException thrown from C++ code ========================================== class Regression02PyException(MyTestCase): def test1RaiseAndTrapPyException(self): - """Test thrown TPyException object processing""" - gROOT.LoadMacro("ScottCppyy.C+") + """Test thrown PyException object processing""" + # JIT-compiled, so the Python symbols resolve to the running interpreter + gInterpreter.Declare(r""" + #include "cpyrt/PyException.h" + #include "DllImport.h" + + extern "C" { + struct _object; + void PyErr_SetString(_object *, const char *); + R__EXTERN _object *PyExc_SyntaxError; + } + + void ThrowPyException() + { + PyErr_SetString(PyExc_SyntaxError, "test error message"); + throw cppjit::cpyrt::PyException(); + } + + class MyThrowingClass { + public: + static void ThrowPyException(int) + { + PyErr_SetString(PyExc_SyntaxError, "overloaded int test error message"); + throw cppjit::cpyrt::PyException(); + } + + static void ThrowPyException(double) + { + PyErr_SetString(PyExc_SyntaxError, "overloaded double test error message"); + throw cppjit::cpyrt::PyException(); + } + }; + """) # test of not overloaded global function with self.assertRaisesRegex(SyntaxError, "test error message"): diff --git a/roottest/python/regression/ScottCppyy.C b/roottest/python/regression/ScottCppyy.C deleted file mode 100644 index c99771360f5d6..0000000000000 --- a/roottest/python/regression/ScottCppyy.C +++ /dev/null @@ -1,29 +0,0 @@ -#include "TPython.h" -#include "cpyrt/PyException.h" -#include "DllImport.h" - -extern "C" { - struct _object; - void PyErr_SetString( _object*, const char* ); - R__EXTERN _object* PyExc_SyntaxError; -} - -void ThrowPyException() { - PyErr_SetString( PyExc_SyntaxError, "test error message" ); - throw cppjit::cpyrt::PyException(); -} - - -class MyThrowingClass { -public: - static void ThrowPyException( int ) { - PyErr_SetString( PyExc_SyntaxError, "overloaded int test error message" ); - throw cppjit::cpyrt::PyException(); - } - - static void ThrowPyException( double ) { - PyErr_SetString( PyExc_SyntaxError, "overloaded double test error message" ); - throw cppjit::cpyrt::PyException(); - } - -};