From 298c9e770b2ecd686ce2c9c52c5857a4fe7f19e6 Mon Sep 17 00:00:00 2001 From: Duncan Tourolle Date: Sat, 4 Jul 2026 14:44:30 +0200 Subject: [PATCH] examples: run Python examples 07 and 08 as CTest smoke tests Neither Python example was registered as a test, so `ctest -L examples` in CI skipped them entirely -- which is how 08's missing Python node went unnoticed. Add a kpn_python_example() helper (gated on KPN_BUILD_PYTHON) that runs each script with PYTHONPATH pointed at the freshly-built module, so it does not depend on cwd or a hard-coded build/python path, and register 07 and 08. Also del the network in 07 for deterministic teardown. --- examples/07_python_network/example.py | 5 +++++ examples/CMakeLists.txt | 23 ++++++++++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/examples/07_python_network/example.py b/examples/07_python_network/example.py index 0eee84e..a10ec41 100644 --- a/examples/07_python_network/example.py +++ b/examples/07_python_network/example.py @@ -30,3 +30,8 @@ net.build() net.start() time.sleep(0.1) net.stop() + +# Drop the network deterministically: it holds the Python callable, which forms +# a reference cycle via globals(). Deleting the global breaks it so the network +# is reclaimed now rather than lingering to interpreter shutdown. +del net diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 261f5dd..3a59c1d 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -13,6 +13,25 @@ function(kpn_example name) ) endfunction() +# Register a Python example script as a CTest smoke test. Runs the script with +# PYTHONPATH pointing at the freshly-built kpn_python module, so it does not +# depend on the caller's working directory or a hard-coded "build/python" path. +function(kpn_python_example name) + if(NOT KPN_BUILD_PYTHON) + return() + endif() + add_test( + NAME example_${name} + COMMAND ${CMAKE_COMMAND} -E env + "PYTHONPATH=$" + ${Python_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/${name}/example.py + ) + set_tests_properties(example_${name} PROPERTIES + TIMEOUT 15 + LABELS examples + ) +endfunction() + kpn_example(01_hello_pipeline) kpn_example(02_named_ports) kpn_example(03_multi_output) @@ -31,7 +50,9 @@ if(KPN_WEB_DEBUG) target_link_libraries(14_debug_hub PRIVATE kpn) kpn_target_enable_web_debug(14_debug_hub) endif() -# 07 and 08 are Python scripts — no compiled target needed. +# 07 and 08 are Python scripts — no compiled target, but run as smoke tests. +kpn_python_example(07_python_network) +kpn_python_example(08_python_subport) # 09 requires OpenCV — only build if found find_package(OpenCV QUIET COMPONENTS core imgproc highgui videoio)