Compare commits
17 Commits
v0.1.1
...
dd584c9064
| Author | SHA1 | Date | |
|---|---|---|---|
| dd584c9064 | |||
| 4d8cafb5a0 | |||
| 6f832cd67b | |||
| ff46886865 | |||
| 50d183d191 | |||
| 2177715641 | |||
| a728f561be | |||
| 116e528a7d | |||
| cc744e17a1 | |||
| ab39b49558 | |||
| 95275c4418 | |||
| 0d614c2921 | |||
| 9466b091dd | |||
| 511288bd03 | |||
| 51b144f60c | |||
| dee8d4a682 | |||
| e726d47547 |
@@ -1,4 +1,4 @@
|
|||||||
# Testium — Claude Context
|
# Testium — Design Context
|
||||||
|
|
||||||
## What is testium
|
## What is testium
|
||||||
|
|
||||||
@@ -114,11 +114,20 @@ To add a new API call usable from subprocesses:
|
|||||||
### External interpreter resolution (`bins.py`)
|
### External interpreter resolution (`bins.py`)
|
||||||
`src/testium/interpreter/utils/bins.py` — single source of truth for the paths to the external Python and Lua interpreters used by subprocesses.
|
`src/testium/interpreter/utils/bins.py` — single source of truth for the paths to the external Python and Lua interpreters used by subprocesses.
|
||||||
|
|
||||||
- `python_bin()` / `lua_bin()` : resolve once, cache in memory. User can override via the `python_bin` / `lua_bin` global dict keys (typically populated from the YAML config). Falls back to discovery on PATH (candidates: `python3`/`python` and `lua`/`lua5.5`/`lua5.4`/`lua5.3`/`lua5.2`/`lua5.1`).
|
- `python_bin()` / `lua_bin()` : resolve and cache. The cache is keyed by `(name, override)` so that a later change to `gd[python_bin]` (typically when a `param.yaml` sets the key) triggers a re-resolution on the next lookup instead of returning the stale auto-discovered path. Falls back to discovery on PATH (candidates: `python3`/`python` and `lua`/`lua5.5`/`lua5.4`/`lua5.3`/`lua5.2`/`lua5.1`).
|
||||||
- `ensure(*names)` : called by `TestSet._validate_runtime_deps()` at test load. Always requires `python` (the eval engine always runs); requires `lua` only if a `lua_func` item is in the tree. Fails fast with a clear error citing tried candidates and override key.
|
- `ensure(*names)` : called by `TestSet._validate_runtime_deps()` at test load. Always requires `python` (the eval engine always runs); requires `lua` only if a `lua_func` item is in the tree. Fails fast with a clear error citing tried candidates and override key.
|
||||||
|
|
||||||
Engines (`PyProcessBase`, `LuaProcessBase`, `EvalExecEngine`) call `bins.python_bin()`/`bins.lua_bin()` themselves — call sites never pass an explicit binary path.
|
Engines (`PyProcessBase`, `LuaProcessBase`, `EvalExecEngine`) call `bins.python_bin()`/`bins.lua_bin()` themselves — call sites never pass an explicit binary path.
|
||||||
|
|
||||||
|
#### Override-timing contract (`apply_overrides`)
|
||||||
|
`bins.python_bin()` is called for the **first** time inside `eval_process_init()` (the long-lived inline-`<| … |>` subprocess), which happens **before** the YAML param files are loaded. To make `-d python_bin=…` and the GUI `python_bin` preference take effect for `eval_proc` itself, `process.py:run()` applies them to gd **before** `eval_process_init()` via the `apply_overrides()` helper extracted from `update_global()`. The post-load `update_global()` call then re-applies the same overrides (after `prepare_global()` clears gd), keeping the gd value in sync with the cached resolution.
|
||||||
|
|
||||||
|
| Override source | `eval_proc` | `py_func` / `cycle` / `post_exec` |
|
||||||
|
|---|---|---|
|
||||||
|
| `-d python_bin=…` (CLI) | ✅ | ✅ |
|
||||||
|
| GUI `python_bin` preference | ✅ | ✅ |
|
||||||
|
| `python_bin: …` in `param.yaml` | ❌ (eval_proc already started) | ✅ (cache re-resolves on key change) |
|
||||||
|
|
||||||
## Key files
|
## Key files
|
||||||
|
|
||||||
| Path | Role |
|
| Path | Role |
|
||||||
@@ -261,12 +270,18 @@ Both Flatpak and AppImage export `TESTIUM_VERSION` from a launcher (Flatpak: lau
|
|||||||
- `unittest` item: renamed from `unittest_file`.
|
- `unittest` item: renamed from `unittest_file`.
|
||||||
- GUI test tree: check and fold state preserved across same-file reloads.
|
- GUI test tree: check and fold state preserved across same-file reloads.
|
||||||
- Licence: EUPL-1.2.
|
- Licence: EUPL-1.2.
|
||||||
|
- Interpreter override timing: `apply_overrides()` extracted from `update_global()` and called by `process.py:run()` before `eval_process_init()`, so `-d python_bin=…` / GUI prefs reach `bins.python_bin()` on its first lookup. `bins._resolve()` cache is now keyed by `(name, override)` so later `param.yaml` changes are picked up by subsequently constructed engines.
|
||||||
|
|
||||||
## Validation tests
|
## Validation tests
|
||||||
Located in `test/validation/`. Run with `-b` flag:
|
Located in `test/validation/`. Two entry points:
|
||||||
```
|
```
|
||||||
./run.sh -b -- test/validation/main.tum
|
./test/validation/run.sh # wrapper — uses a dedicated venv (see below)
|
||||||
|
./run.sh -b -- test/validation/main.tum # direct — testium's own python is used for test execution
|
||||||
```
|
```
|
||||||
|
The `run.sh` / `run.bat` wrappers create a dedicated Python venv at `${TMPDIR:-/tmp}/testium-validation-venv` (Linux) or `%TEMP%\testium-validation-venv` (Windows), with `--system-site-packages` + `pip install junit-xml`, and run the suite with `-d python_bin=…` so every test-execution subprocess (eval_proc, py_func, cycle, post_exec) runs inside the venv. testium itself keeps running in the project's own environment. `clean` as the first argument recreates the venv.
|
||||||
|
|
||||||
|
The `venv` item (`test/validation/items/venv/`) asserts that the override actually took effect: `python_bin` is set, `sys.executable` matches it, `sys.prefix == dirname(dirname(python_bin))`, and `sys.prefix != sys.base_prefix` (the last marker catches the case where `python_bin` happens to be a system interpreter, which path-equality alone would miss because the venv's `bin/python3` is a symlink to the host). Both `eval_proc` (inline `<| … |>`) and `py_func` paths are exercised.
|
||||||
|
|
||||||
Parallel item tests: `test/validation/items/parallel/test.tum`
|
Parallel item tests: `test/validation/items/parallel/test.tum`
|
||||||
|
|
||||||
## Dependencies
|
## Dependencies
|
||||||
107
build_all.sh
Executable file
107
build_all.sh
Executable file
@@ -0,0 +1,107 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# Build every distribution channel of testium, in order:
|
||||||
|
# 1. Manual PDF -> dist/testium-manual-<v>.pdf
|
||||||
|
# 2. Wheel -> dist/testium-<v>-py3-none-any.whl (PEP 427 name)
|
||||||
|
# 3. PyInstaller binary -> dist/testium-<v>
|
||||||
|
# 4. Flatpak bundle -> dist/testium-<v>.flatpak
|
||||||
|
# 5. AppImage -> dist/Testium-<v>-x86_64.AppImage (original name)
|
||||||
|
# release_note.txt is copied to dist/ up front (with a warning if it has no
|
||||||
|
# entry for the current version).
|
||||||
|
#
|
||||||
|
# All artifacts are collected (copied) under <repo>/dist/. Original outputs in
|
||||||
|
# src/dist/, package/*/dist/, doc/manual/ are left in place. Wheel and AppImage
|
||||||
|
# keep their original names (which already contain the version); manual,
|
||||||
|
# pyinstaller and flatpak are renamed to testium(-manual)-<version>(.suff).
|
||||||
|
#
|
||||||
|
# Re-uses scripts/build_env.sh and scripts/set_env.sh — the same pair invoked
|
||||||
|
# by run.sh — so the venv at test/tmp/.venv stays the single source of Python
|
||||||
|
# dependencies. `build` and `pyinstaller` are installed into that venv on
|
||||||
|
# demand if not already there. Flatpak and AppImage build in their own
|
||||||
|
# container/sandbox; their build.sh scripts have their own toolchain checks.
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
SCRIPT_DIR=$(realpath "$(dirname "$0")")
|
||||||
|
VERSION=$(cat "$SCRIPT_DIR/src/VERSION")
|
||||||
|
DIST_DIR="$SCRIPT_DIR/dist"
|
||||||
|
mkdir -p "$DIST_DIR"
|
||||||
|
|
||||||
|
# Release note: copy it to dist/ and warn (but don't fail) if it has no entry
|
||||||
|
# for the current version.
|
||||||
|
RELEASE_NOTE_SRC="$SCRIPT_DIR/release_note.txt"
|
||||||
|
RELEASE_NOTE="$DIST_DIR/release_note.txt"
|
||||||
|
cp -f "$RELEASE_NOTE_SRC" "$RELEASE_NOTE"
|
||||||
|
if ! grep -qE "^version $VERSION([^.0-9]|$)" "$RELEASE_NOTE_SRC"; then
|
||||||
|
echo "WARNING: release_note.txt has no entry for version $VERSION." >&2
|
||||||
|
fi
|
||||||
|
|
||||||
|
export PY_VENV_NAME=".venv"
|
||||||
|
export PY_VENV_DIR="$SCRIPT_DIR/test/tmp/$PY_VENV_NAME"
|
||||||
|
export REQ_PATH="$SCRIPT_DIR/src/requirements.txt"
|
||||||
|
|
||||||
|
bash "$SCRIPT_DIR/scripts/build_env.sh"
|
||||||
|
source "$SCRIPT_DIR/scripts/set_env.sh"
|
||||||
|
|
||||||
|
# Ensure wheel/PyInstaller toolchains are present in the venv.
|
||||||
|
python -m pip install --quiet --upgrade build pyinstaller
|
||||||
|
|
||||||
|
step() {
|
||||||
|
echo
|
||||||
|
echo "================================================================"
|
||||||
|
echo " $1"
|
||||||
|
echo "================================================================"
|
||||||
|
}
|
||||||
|
|
||||||
|
# 1. Manual PDF
|
||||||
|
step "1/5 Manual PDF (version $VERSION)"
|
||||||
|
bash "$SCRIPT_DIR/doc/manual/sphinx/build_doc.sh"
|
||||||
|
MANUAL_SRC="$SCRIPT_DIR/doc/manual/testium_manual.pdf"
|
||||||
|
MANUAL="$DIST_DIR/testium-manual-${VERSION}.pdf"
|
||||||
|
cp -f "$MANUAL_SRC" "$MANUAL"
|
||||||
|
|
||||||
|
# 2. Wheel — PEP 427 name kept (already contains version)
|
||||||
|
step "2/5 Wheel (version $VERSION)"
|
||||||
|
(
|
||||||
|
cd "$SCRIPT_DIR/src"
|
||||||
|
rm -rf dist build *.egg-info
|
||||||
|
python -m build --wheel
|
||||||
|
)
|
||||||
|
WHEEL_SRC=$(ls -1t "$SCRIPT_DIR/src/dist"/*.whl | head -1)
|
||||||
|
WHEEL="$DIST_DIR/$(basename "$WHEEL_SRC")"
|
||||||
|
cp -f "$WHEEL_SRC" "$WHEEL"
|
||||||
|
|
||||||
|
# 3. PyInstaller binary
|
||||||
|
step "3/5 PyInstaller binary (version $VERSION)"
|
||||||
|
bash "$SCRIPT_DIR/package/pyinstaller/build.sh"
|
||||||
|
PYI_SRC="$SCRIPT_DIR/package/pyinstaller/dist/testium"
|
||||||
|
PYI_BIN="$DIST_DIR/testium-${VERSION}"
|
||||||
|
cp -f "$PYI_SRC" "$PYI_BIN"
|
||||||
|
|
||||||
|
# 4. Flatpak bundle
|
||||||
|
step "4/5 Flatpak bundle (version $VERSION)"
|
||||||
|
(
|
||||||
|
cd "$SCRIPT_DIR/package/flatpak"
|
||||||
|
bash build.sh
|
||||||
|
)
|
||||||
|
FLATPAK_SRC="$SCRIPT_DIR/package/flatpak/testium.flatpak"
|
||||||
|
FLATPAK_BUNDLE="$DIST_DIR/testium-${VERSION}.flatpak"
|
||||||
|
cp -f "$FLATPAK_SRC" "$FLATPAK_BUNDLE"
|
||||||
|
|
||||||
|
# 5. AppImage
|
||||||
|
step "5/5 AppImage (version $VERSION)"
|
||||||
|
(
|
||||||
|
cd "$SCRIPT_DIR/package/appimage"
|
||||||
|
bash build.sh
|
||||||
|
)
|
||||||
|
APPIMAGE_SRC=$(ls -1t "$SCRIPT_DIR/package/appimage"/*.AppImage 2>/dev/null | head -1)
|
||||||
|
APPIMAGE="$DIST_DIR/$(basename "$APPIMAGE_SRC")"
|
||||||
|
cp -f "$APPIMAGE_SRC" "$APPIMAGE"
|
||||||
|
chmod +x "$APPIMAGE"
|
||||||
|
|
||||||
|
step "All packages built"
|
||||||
|
printf " manual : %s\n" "$MANUAL"
|
||||||
|
printf " wheel : %s\n" "$WHEEL"
|
||||||
|
printf " pyinstaller : %s\n" "$PYI_BIN"
|
||||||
|
printf " flatpak : %s\n" "$FLATPAK_BUNDLE"
|
||||||
|
printf " appimage : %s\n" "$APPIMAGE"
|
||||||
|
printf " release_note : %s\n" "$RELEASE_NOTE"
|
||||||
@@ -20,6 +20,22 @@ main:
|
|||||||
param:
|
param:
|
||||||
- 123
|
- 123
|
||||||
|
|
||||||
|
- py_func:
|
||||||
|
name: python long wait
|
||||||
|
doc: The purpose of this step is to try the tasks "stop" interruption
|
||||||
|
file: utils.py
|
||||||
|
func_name: long_wait
|
||||||
|
param:
|
||||||
|
- 10
|
||||||
|
|
||||||
|
- lua_func:
|
||||||
|
name: lua long wait
|
||||||
|
doc: The purpose of this step is to try the tasks "stop" interruption
|
||||||
|
file: lua_func.lua
|
||||||
|
func_name: long_wait
|
||||||
|
param:
|
||||||
|
- 10
|
||||||
|
|
||||||
- sleep:
|
- sleep:
|
||||||
name: sleep item
|
name: sleep item
|
||||||
dialog: true
|
dialog: true
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
tm = require("tm")
|
tm = require("tm")
|
||||||
|
socket = require("socket")
|
||||||
|
|
||||||
local module = {}
|
local module = {}
|
||||||
|
|
||||||
@@ -7,4 +8,8 @@ function module.func_to_be_executed(param)
|
|||||||
return param
|
return param
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function module.long_wait(sec)
|
||||||
|
socket.sleep(sec)
|
||||||
|
end
|
||||||
|
|
||||||
return module
|
return module
|
||||||
@@ -17,18 +17,3 @@ plot_log_path: /tmp/testium_plot/$(testrun_date)/$(testrun_time)/
|
|||||||
python_path_Windows: C:\Users\François\Applications\Python313\python.exe
|
python_path_Windows: C:\Users\François\Applications\Python313\python.exe
|
||||||
python_path_Linux: $(home)/tmp/tum_venv/bin/python3
|
python_path_Linux: $(home)/tmp/tum_venv/bin/python3
|
||||||
|
|
||||||
# lua_bin_Windows: C:\Lua\5.1
|
|
||||||
# lua_bin_Linux: /usr/bin/lua
|
|
||||||
|
|
||||||
LUA_PATH_Linux: /usr/share/lua/5.4/?.lua;/usr/local/share/lua/5.4/?.lua;/usr/local/share/lua/5.4/?/init.lua;/usr/share/lua/5.4/?/init.lua;/usr/local/lib/lua/5.4/?.lua;/usr/local/lib/lua/5.4/?/init.lua;/usr/lib/lua/5.4/?.lua;/usr/lib/lua/5.4/?/init.lua;./?.lua;./?/init.lua;/home/francois/.luarocks/share/lua/5.4/?.lua;/home/francois/.luarocks/share/lua/5.4/?/init.lua
|
|
||||||
LUA_CPATH_Linux: /usr/local/lib/lua/5.4/?.so;/usr/lib/lua/5.4/?.so;/usr/local/lib/lua/5.4/loadall.so;/usr/lib/lua/5.4/loadall.so;./?.so;/home/francois/.luarocks/lib/lua/5.4/?.so
|
|
||||||
PATH_Linux:
|
|
||||||
|
|
||||||
LUA_PATH_Windows: ;.\?.lua;C:\Lua\5.1\lua\?.lua;C:\Lua\5.1\lua\?\init.lua;C:\Lua\5.1\?.lua;C:\Lua\5.1\?\init.lua;C:\Lua\5.1\lua\?.luac
|
|
||||||
LUA_CPATH_Windows: .\?.dll;C:\Lua\5.1\?.dll;C:\Lua\5.1\loadall.dll;C:\Lua\5.1\clibs\?.dll;C:\Lua\5.1\clibs\loadall.dll;.\?51.dll;C:\Lua\5.1\?51.dll;C:\Lua\5.1\clibs\?51.dll
|
|
||||||
PATH_Windows: ""
|
|
||||||
|
|
||||||
lua_env:
|
|
||||||
PATH: $(PATH_$(os))
|
|
||||||
LUA_PATH: $(LUA_PATH_$(os))
|
|
||||||
LUA_CPATH: $(LUA_CPATH_$(os))
|
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
from time import sleep
|
||||||
|
|
||||||
def dummy_exit(useless1, useless2):
|
def dummy_exit(useless1, useless2):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@@ -11,3 +13,6 @@ def funcToBeExecuted (bla):
|
|||||||
def funcToBeExecuted2 (bla):
|
def funcToBeExecuted2 (bla):
|
||||||
print(bla)
|
print(bla)
|
||||||
return blo
|
return blo
|
||||||
|
|
||||||
|
def long_wait (sec):
|
||||||
|
sleep(sec)
|
||||||
Binary file not shown.
@@ -46,8 +46,9 @@ $RUNTIME run --rm \
|
|||||||
appimage-builder --recipe AppImageBuilder.yml --skip-test
|
appimage-builder --recipe AppImageBuilder.yml --skip-test
|
||||||
"
|
"
|
||||||
|
|
||||||
echo "Done: testium-${APP_VERSION}-x86_64.AppImage"
|
APPIMAGE_FILE=$(ls -1t Testium-*-x86_64.AppImage 2>/dev/null | head -1)
|
||||||
|
echo "Done: ${APPIMAGE_FILE}"
|
||||||
|
|
||||||
if [ "${1}" = "install" ]; then
|
if [ "${1}" = "install" ] && [ -n "${APPIMAGE_FILE}" ]; then
|
||||||
install -v "testium-${APP_VERSION}-x86_64.AppImage" "${HOME}/.local/bin/testium"
|
install -v "${APPIMAGE_FILE}" "${HOME}/.local/bin/testium"
|
||||||
fi
|
fi
|
||||||
|
|||||||
@@ -1,23 +1,38 @@
|
|||||||
|
version 0.1.3
|
||||||
|
==============
|
||||||
|
- Stop interrupts engaged blocking steps (console, py_func, lua_func,
|
||||||
|
json_rpc, sleep) within ~200 ms instead of waiting for the step
|
||||||
|
to finish.
|
||||||
|
- GUI Start / Stop / Pause flow simplified.
|
||||||
|
- lua_func: a function returning nil is no longer reported as a failure.
|
||||||
|
- ``-d python_bin=...`` and the GUI ``python_bin`` preference now reach
|
||||||
|
the eval subprocess (used to be silently ignored). ``param.yaml`` can
|
||||||
|
also override ``python_bin`` for py_func / cycle / post_exec.
|
||||||
|
- Validation suite: ``test/validation/run.sh`` (and ``run.bat``)
|
||||||
|
runs the suite inside a dedicated venv in the system temp dir.
|
||||||
|
- build_all.sh: ``release_note.txt`` and the user manual copied into
|
||||||
|
``dist/``; warning if the file has no entry for the version being built.
|
||||||
|
- Flatpak: every GUI file/directory dialog (open test, save report, log
|
||||||
|
path, default report/log dirs, python/lua interpreter pickers) now
|
||||||
|
bypasses the XDG document portal — the v0.1.2 fix was only on the
|
||||||
|
"open test" dialog.
|
||||||
|
|
||||||
|
version 0.1.2
|
||||||
|
==============
|
||||||
|
- Flatpak: opening a test from the GUI now correctly finds its companion
|
||||||
|
files (param.yaml, .py scripts, ...).
|
||||||
|
|
||||||
version 0.1.1
|
version 0.1.1
|
||||||
==============
|
==============
|
||||||
- Packaging: Flatpak bundle (desktop entry, MIME, distributable .flatpak)
|
- New install channels: Flatpak bundle and AppImage. The AppImage runs
|
||||||
and AppImage (containerized build, runs on Arch / non-Debian hosts).
|
on any distribution (built inside a Debian container).
|
||||||
- bins.py: host-only Python/Lua resolution from sandboxed bundles
|
- About dialog: version is now correct in Flatpak and AppImage builds
|
||||||
(Flatpak / AppImage); fail fast at test load if the host interpreter
|
(used to display "unknown").
|
||||||
is missing.
|
- GUI dialogs no longer hang on pure-Wayland sessions.
|
||||||
- run item: runtime-aware launcher (AppImage / Flatpak / PyInstaller /
|
- Plot "last values" API: more tolerant timeout on loaded machines.
|
||||||
source / wheel); drop testium_path / python_bin parameters.
|
- run item: `testium_path` and `python_bin` parameters removed —
|
||||||
- dialog_env: auto-detect Wayland vs xcb from $DISPLAY / $WAYLAND_DISPLAY
|
sub-instances are launched in the same packaging mode as the parent.
|
||||||
instead of forcing xcb (was hanging dialogs on pure-Wayland sessions).
|
- License: EUPL-1.2.
|
||||||
- version: read TESTIUM_VERSION env in Flatpak/AppImage so the About
|
|
||||||
dialog stops reporting "unknown".
|
|
||||||
- runtime_plot last_values: bump timeout 1s -> 5s and narrow the bare
|
|
||||||
except to queue.Empty.
|
|
||||||
- py_func/__main__: robust sys.path init, diagnostic on import failure.
|
|
||||||
- Subprocess stdio (py_func / lua_func) routed into the parent log.
|
|
||||||
- README refocused on users (quick_start, tutorial); CONTRIBUTING filled.
|
|
||||||
- Docs: CLAUDE.md Packaging section rewritten.
|
|
||||||
- LICENSE file (EUPL-1.2) added.
|
|
||||||
|
|
||||||
version 0.1
|
version 0.1
|
||||||
==============
|
==============
|
||||||
|
|||||||
@@ -20,6 +20,12 @@ if [ "$?" -ne 0 ]; then
|
|||||||
echo "venv must be installed on the host distribution."
|
echo "venv must be installed on the host distribution."
|
||||||
exit -1
|
exit -1
|
||||||
fi
|
fi
|
||||||
|
# Check if venv is installed
|
||||||
|
python3 -c "import ensurepip"
|
||||||
|
if [ "$?" -ne 0 ]; then
|
||||||
|
echo "ensurepip must be installed on the host distribution."
|
||||||
|
exit -1
|
||||||
|
fi
|
||||||
|
|
||||||
# Install the virtual environment if needed
|
# Install the virtual environment if needed
|
||||||
if [ ! -d "$PY_VENV_DIR" ]; then
|
if [ ! -d "$PY_VENV_DIR" ]; then
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
0.1.1
|
0.1.2
|
||||||
@@ -11,6 +11,7 @@ import threading
|
|||||||
from telnetlib3 import Telnet, DO, WILL, WONT, TTYPE, IAC, SB, SE, theNULL
|
from telnetlib3 import Telnet, DO, WILL, WONT, TTYPE, IAC, SB, SE, theNULL
|
||||||
|
|
||||||
TIMEOUT_NULL = 0.000001
|
TIMEOUT_NULL = 0.000001
|
||||||
|
STOP_POLL_INTERVAL = 0.2
|
||||||
|
|
||||||
|
|
||||||
class BytesStore(object):
|
class BytesStore(object):
|
||||||
@@ -123,12 +124,14 @@ A {classname}.close() is missing somewhere in your code !'.format(classname=type
|
|||||||
# c = ''
|
# c = ''
|
||||||
return c
|
return c
|
||||||
|
|
||||||
def read_until(self, match, timeout=None, return_data=False, mute=False):
|
def read_until(self, match, timeout=None, return_data=False, mute=False, should_stop=None):
|
||||||
"""
|
"""
|
||||||
read until the string 'match is found
|
read until the string 'match is found
|
||||||
If timeout is not set (None), this function runs indefinitely
|
If timeout is not set (None), this function runs indefinitely
|
||||||
If timeout is set to zero, this function returns immediately
|
If timeout is set to zero, this function returns immediately
|
||||||
If mute is set to True the characters read from the console will not be displayed
|
If mute is set to True the characters read from the console will not be displayed
|
||||||
|
If should_stop is a callable, it is polled between reads (every STOP_POLL_INTERVAL
|
||||||
|
at most) and the loop exits early — like a timeout — when it returns True.
|
||||||
|
|
||||||
If function fails (because of a timeout) it will return a 'status' integer set to -1
|
If function fails (because of a timeout) it will return a 'status' integer set to -1
|
||||||
otherwise it will return 0.
|
otherwise it will return 0.
|
||||||
@@ -139,13 +142,6 @@ A {classname}.close() is missing somewhere in your code !'.format(classname=type
|
|||||||
status = -1
|
status = -1
|
||||||
if not match:
|
if not match:
|
||||||
raise ValueError('match parameter can not be empty')
|
raise ValueError('match parameter can not be empty')
|
||||||
# replace all '\r' by '\n' as any '\r' read will undergo the same replacement
|
|
||||||
# match = match.replace('\r\n', '\n')
|
|
||||||
# match = match.replace('\r', '')
|
|
||||||
|
|
||||||
# update the console timeout in conformity with what is required.
|
|
||||||
|
|
||||||
self.set_read_timeout(timeout)
|
|
||||||
|
|
||||||
if timeout is None:
|
if timeout is None:
|
||||||
timeout = 1000000
|
timeout = 1000000
|
||||||
@@ -159,6 +155,7 @@ A {classname}.close() is missing somewhere in your code !'.format(classname=type
|
|||||||
# buffer is empty
|
# buffer is empty
|
||||||
# Otherwise we are waiting for the timeout to rise
|
# Otherwise we are waiting for the timeout to rise
|
||||||
if timeout < TIMEOUT_NULL:
|
if timeout < TIMEOUT_NULL:
|
||||||
|
self.set_read_timeout(0)
|
||||||
data = self.readchar(0)
|
data = self.readchar(0)
|
||||||
|
|
||||||
while (status < 0) and ((data is not None) and (data != b'')):
|
while (status < 0) and ((data is not None) and (data != b'')):
|
||||||
@@ -191,16 +188,21 @@ A {classname}.close() is missing somewhere in your code !'.format(classname=type
|
|||||||
|
|
||||||
# Timeout different than zero
|
# Timeout different than zero
|
||||||
else:
|
else:
|
||||||
|
# Poll in short chunks so a stop request is honored within
|
||||||
|
# STOP_POLL_INTERVAL, regardless of the per-protocol blocking
|
||||||
|
# behavior of readchar().
|
||||||
|
self.set_read_timeout(STOP_POLL_INTERVAL)
|
||||||
|
|
||||||
time_is_out = threading.Event()
|
time_is_out = threading.Event()
|
||||||
timer = threading.Timer(timeout, lambda: time_is_out.set())
|
timer = threading.Timer(timeout, lambda: time_is_out.set())
|
||||||
timer.start()
|
timer.start()
|
||||||
|
|
||||||
# We are waiting for the timeout to rise
|
try:
|
||||||
|
while (status < 0) and (not time_is_out.is_set()):
|
||||||
|
if should_stop is not None and should_stop():
|
||||||
|
break
|
||||||
|
|
||||||
while (status < 0) and (not time_is_out.isSet()):
|
data = self.readchar(STOP_POLL_INTERVAL)
|
||||||
|
|
||||||
data = self.readchar(timeout)
|
|
||||||
if data is not None:
|
if data is not None:
|
||||||
data = self._compute_char(data)
|
data = self._compute_char(data)
|
||||||
if data != '':
|
if data != '':
|
||||||
@@ -210,7 +212,6 @@ A {classname}.close() is missing somewhere in your code !'.format(classname=type
|
|||||||
|
|
||||||
search_deque.append(data)
|
search_deque.append(data)
|
||||||
if search_deque == match_deque:
|
if search_deque == match_deque:
|
||||||
timer.cancel()
|
|
||||||
status = 0
|
status = 0
|
||||||
if (not mute) and (data != '\n'):
|
if (not mute) and (data != '\n'):
|
||||||
self.string_buffer += '\n'
|
self.string_buffer += '\n'
|
||||||
@@ -224,6 +225,8 @@ A {classname}.close() is missing somewhere in your code !'.format(classname=type
|
|||||||
|
|
||||||
date_str = str(datetime.now()).split('.')[0].split(' ')[1]
|
date_str = str(datetime.now()).split('.')[0].split(' ')[1]
|
||||||
self.string_buffer = '[{} {}]'.format(date_str, self.name)
|
self.string_buffer = '[{} {}]'.format(date_str, self.name)
|
||||||
|
finally:
|
||||||
|
timer.cancel()
|
||||||
|
|
||||||
if return_data:
|
if return_data:
|
||||||
return status, read_data
|
return status, read_data
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ from interpreter.utils.test_init import (
|
|||||||
env_init,
|
env_init,
|
||||||
prepare_global,
|
prepare_global,
|
||||||
update_global,
|
update_global,
|
||||||
|
apply_overrides,
|
||||||
set_standard_gd_keys,
|
set_standard_gd_keys,
|
||||||
test_run_init,
|
test_run_init,
|
||||||
test_run_header,
|
test_run_header,
|
||||||
@@ -210,6 +211,19 @@ class TestProcess(Process):
|
|||||||
|
|
||||||
env_init()
|
env_init()
|
||||||
|
|
||||||
|
# Apply GUI defaults and CLI defines to the global dict
|
||||||
|
# *before* eval_proc starts: bins.python_bin() reads
|
||||||
|
# ``python_bin`` from gd on its very first call (during
|
||||||
|
# eval_process_init) and caches the result. Without this,
|
||||||
|
# ``-d python_bin=...`` and the GUI ``python_bin`` preference
|
||||||
|
# would only take effect for items spawned *after* the cache
|
||||||
|
# was already populated with the auto-discovered interpreter,
|
||||||
|
# i.e. they would silently be ignored for eval_proc itself.
|
||||||
|
# _load_initial_params re-applies the same overrides after
|
||||||
|
# ``prepare_global()`` clears gd, so the gd value stays in
|
||||||
|
# sync with the cached path.
|
||||||
|
apply_overrides(self.__defs, self.__gui_defaults)
|
||||||
|
|
||||||
# Creation of the python evaluation process for loading of the complete test
|
# Creation of the python evaluation process for loading of the complete test
|
||||||
eval_proc = eval_process_init(api_request, 10, test_dir)
|
eval_proc = eval_process_init(api_request, 10, test_dir)
|
||||||
eval_proc.start()
|
eval_proc.start()
|
||||||
|
|||||||
@@ -20,9 +20,26 @@ class TestItem:
|
|||||||
def test_run(f):
|
def test_run(f):
|
||||||
@wraps(f)
|
@wraps(f)
|
||||||
def wrapper(self):
|
def wrapper(self):
|
||||||
if not self.skipped:
|
if self.skipped:
|
||||||
if self.enabled:
|
self.result.set(TestValue.NORUN, "test skipped")
|
||||||
|
print("Test is skipped.")
|
||||||
|
return self.result
|
||||||
|
|
||||||
|
if not self.enabled:
|
||||||
|
self.result.set(TestValue.NORUN, "test disabled")
|
||||||
|
print("Test is disabled.")
|
||||||
|
return self.result
|
||||||
|
|
||||||
self.run_test_init()
|
self.run_test_init()
|
||||||
|
|
||||||
|
while self._is_paused:
|
||||||
|
sleep(0.2)
|
||||||
|
if self.isStopped() :
|
||||||
|
self.result.set(TestValue.NORUN, "test stopped")
|
||||||
|
print("Test is Stopped.")
|
||||||
|
self._is_stopped = False # Restore state for next run
|
||||||
|
return self.result
|
||||||
|
|
||||||
# Conditional execution
|
# Conditional execution
|
||||||
raw_condition = self._prms.getParam(
|
raw_condition = self._prms.getParam(
|
||||||
"condition", default=None, processed=False
|
"condition", default=None, processed=False
|
||||||
@@ -57,15 +74,10 @@ def test_run(f):
|
|||||||
self.result.set(TestValue.NORUN, msg)
|
self.result.set(TestValue.NORUN, msg)
|
||||||
self.result.reported = {"input_condition": msg}
|
self.result.reported = {"input_condition": msg}
|
||||||
self.run_test_end()
|
self.run_test_end()
|
||||||
else:
|
|
||||||
self.result.set(TestValue.NORUN, "test disabled")
|
|
||||||
print("Test is disabled.")
|
|
||||||
else:
|
|
||||||
self.result.set(TestValue.NORUN, "test skipped")
|
|
||||||
print("Test is skipped.")
|
|
||||||
|
|
||||||
return self.result
|
return self.result
|
||||||
|
|
||||||
|
|
||||||
return wrapper
|
return wrapper
|
||||||
|
|
||||||
|
|
||||||
@@ -255,8 +267,6 @@ class TestItem:
|
|||||||
self._sendStatusStarted()
|
self._sendStatusStarted()
|
||||||
if self._is_breakpoint:
|
if self._is_breakpoint:
|
||||||
self._is_paused = True
|
self._is_paused = True
|
||||||
while self._is_paused:
|
|
||||||
sleep(0.2)
|
|
||||||
|
|
||||||
if self.is_container:
|
if self.is_container:
|
||||||
self.report.incLevel()
|
self.report.incLevel()
|
||||||
@@ -274,9 +284,6 @@ class TestItem:
|
|||||||
if self.is_container:
|
if self.is_container:
|
||||||
self.report.decLevel()
|
self.report.decLevel()
|
||||||
|
|
||||||
while self._is_paused:
|
|
||||||
sleep(0.2)
|
|
||||||
|
|
||||||
# Post evaluation of the test result
|
# Post evaluation of the test result
|
||||||
self.process_result()
|
self.process_result()
|
||||||
# expected_result treatment
|
# expected_result treatment
|
||||||
@@ -311,6 +318,7 @@ class TestItem:
|
|||||||
self.report.addTest(self, self.result, rk)
|
self.report.addTest(self, self.result, rk)
|
||||||
self._sendStatusFinished()
|
self._sendStatusFinished()
|
||||||
|
|
||||||
|
|
||||||
def process_result(self):
|
def process_result(self):
|
||||||
if self._post_eval is None:
|
if self._post_eval is None:
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -307,11 +307,17 @@ class TestItemConsoleReadUntil(TestItemConsoleAction):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
status, data = cons.read_until(
|
status, data = cons.read_until(
|
||||||
ru, timeout=read_timeout, return_data=True, mute=mute
|
ru, timeout=read_timeout, return_data=True, mute=mute,
|
||||||
|
should_stop=self.isStopped,
|
||||||
)
|
)
|
||||||
if status == 0:
|
if status == 0:
|
||||||
self.result.set(TestValue.SUCCESS)
|
self.result.set(TestValue.SUCCESS)
|
||||||
self.result.value = data
|
self.result.value = data
|
||||||
|
elif self.isStopped():
|
||||||
|
self.result.set(
|
||||||
|
result=TestValue.FAILURE,
|
||||||
|
message="Console read aborted on stop request",
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
self.result.set(result=TestValue.FAILURE, message="No matching text")
|
self.result.set(result=TestValue.FAILURE, message="No matching text")
|
||||||
if mute:
|
if mute:
|
||||||
|
|||||||
@@ -105,6 +105,7 @@ class TestItemJSRPCActionQuery(TestItemAction):
|
|||||||
jrpc_id = randint(1, (2**32) - 1)
|
jrpc_id = randint(1, (2**32) - 1)
|
||||||
send_only = self._prms.expanse(self._send_only)
|
send_only = self._prms.expanse(self._send_only)
|
||||||
timeout = self._prms.expanse(self._timeout)
|
timeout = self._prms.expanse(self._timeout)
|
||||||
|
self.token.set_should_stop(self.isStopped)
|
||||||
try:
|
try:
|
||||||
success, result = self.token.query(
|
success, result = self.token.query(
|
||||||
meth, obj, jrpc_id, send_only, timeout=timeout
|
meth, obj, jrpc_id, send_only, timeout=timeout
|
||||||
@@ -146,6 +147,7 @@ class TestItemJSRPCActionReceive(TestItemAction):
|
|||||||
def execute(self):
|
def execute(self):
|
||||||
timeout = self._prms.expanse(self._timeout)
|
timeout = self._prms.expanse(self._timeout)
|
||||||
jrpc_id = self._prms.expanse(self._jrpc_id)
|
jrpc_id = self._prms.expanse(self._jrpc_id)
|
||||||
|
self.token.set_should_stop(self.isStopped)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
success, result = self.token.receive(jrpc_id, timeout)
|
success, result = self.token.receive(jrpc_id, timeout)
|
||||||
|
|||||||
@@ -2,10 +2,11 @@ import json
|
|||||||
import socket
|
import socket
|
||||||
import re
|
import re
|
||||||
import struct
|
import struct
|
||||||
|
import time
|
||||||
|
|
||||||
from runtime.tum_except import ETUMRuntimeError
|
from runtime.tum_except import ETUMRuntimeError
|
||||||
import api.testium as tm
|
import api.testium as tm
|
||||||
from api.console import Console
|
from api.console import Console, STOP_POLL_INTERVAL
|
||||||
|
|
||||||
|
|
||||||
def is_ip_address(address):
|
def is_ip_address(address):
|
||||||
@@ -45,9 +46,16 @@ class JrpcAdapter:
|
|||||||
self._jrpc_version = version
|
self._jrpc_version = version
|
||||||
self._mute = mute
|
self._mute = mute
|
||||||
self._timeout = timeout
|
self._timeout = timeout
|
||||||
|
# Optional callable polled by _receive() implementations to abort
|
||||||
|
# waits early when the test is being stopped. Set by the test item
|
||||||
|
# action before each query/receive call.
|
||||||
|
self._should_stop = None
|
||||||
if not (version == "1.0" or version == "2.0"):
|
if not (version == "1.0" or version == "2.0"):
|
||||||
raise ETUMRuntimeError("Invalid JSONRPC version passed.")
|
raise ETUMRuntimeError("Invalid JSONRPC version passed.")
|
||||||
|
|
||||||
|
def set_should_stop(self, cb):
|
||||||
|
self._should_stop = cb
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def timeout(self):
|
def timeout(self):
|
||||||
return self._timeout
|
return self._timeout
|
||||||
@@ -249,13 +257,23 @@ class JrpcUdpAdapter(JrpcAdapter):
|
|||||||
print(f" | sent to @{self._server}:{self._snd_port}")
|
print(f" | sent to @{self._server}:{self._snd_port}")
|
||||||
|
|
||||||
def _receive(self, timeout: float) -> str:
|
def _receive(self, timeout: float) -> str:
|
||||||
|
# Poll in short chunks so a stop request is honored within
|
||||||
# configures the reception timeout
|
# STOP_POLL_INTERVAL.
|
||||||
self.sock.settimeout(timeout)
|
self.sock.settimeout(STOP_POLL_INTERVAL)
|
||||||
|
deadline = time.monotonic() + float(timeout)
|
||||||
# Receives the answer from the server
|
data = None
|
||||||
|
addr = None
|
||||||
|
while True:
|
||||||
|
if self._should_stop is not None and self._should_stop():
|
||||||
|
raise ETUMRuntimeError("JSONRPC udp receive aborted on stop request.")
|
||||||
try:
|
try:
|
||||||
data, addr = self.sock.recvfrom(self._bufsize)
|
data, addr = self.sock.recvfrom(self._bufsize)
|
||||||
|
break
|
||||||
|
except socket.timeout:
|
||||||
|
if time.monotonic() >= deadline:
|
||||||
|
raise ETUMRuntimeError(
|
||||||
|
"JSONRPC udp answer took too long. Try to increase the timeout."
|
||||||
|
)
|
||||||
|
|
||||||
# In case of buffer overload we chose to complain
|
# In case of buffer overload we chose to complain
|
||||||
if len(data) >= self._bufsize:
|
if len(data) >= self._bufsize:
|
||||||
@@ -271,10 +289,6 @@ class JrpcUdpAdapter(JrpcAdapter):
|
|||||||
print(f" | UDP answer: '{res}'")
|
print(f" | UDP answer: '{res}'")
|
||||||
print(f" | received from @{addr[0]}:{addr[1]}")
|
print(f" | received from @{addr[0]}:{addr[1]}")
|
||||||
|
|
||||||
except socket.timeout:
|
|
||||||
raise ETUMRuntimeError(
|
|
||||||
"JSONRPC udp answer took too long. Try to increase the timeout."
|
|
||||||
)
|
|
||||||
return res
|
return res
|
||||||
|
|
||||||
def _build_query(self, method: str, obj, jrpc_id: int):
|
def _build_query(self, method: str, obj, jrpc_id: int):
|
||||||
@@ -339,11 +353,16 @@ class JrpcConsoleAdapter(JrpcAdapter):
|
|||||||
|
|
||||||
def _receive(self, timeout: float) -> str:
|
def _receive(self, timeout: float) -> str:
|
||||||
status, data = self._cons.read_until(
|
status, data = self._cons.read_until(
|
||||||
self._endswith, timeout, return_data=True, mute=self._mute
|
self._endswith, timeout, return_data=True, mute=self._mute,
|
||||||
|
should_stop=self._should_stop,
|
||||||
)
|
)
|
||||||
|
|
||||||
# if we did not receive anything, we complain
|
# if we did not receive anything, we complain
|
||||||
if not status == 0:
|
if not status == 0:
|
||||||
|
if self._should_stop is not None and self._should_stop():
|
||||||
|
raise ETUMRuntimeError(
|
||||||
|
f"JSONRPC console receive aborted on stop request."
|
||||||
|
)
|
||||||
raise ETUMRuntimeError(
|
raise ETUMRuntimeError(
|
||||||
f"The '{self._cons.name}' console did not answer in the requested time."
|
f"The '{self._cons.name}' console did not answer in the requested time."
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -45,6 +45,18 @@ class TestItemLuaFunc(TestItem):
|
|||||||
tm.setgd(_LUA_FUNC_CONTEXTS_KEY, contexts)
|
tm.setgd(_LUA_FUNC_CONTEXTS_KEY, contexts)
|
||||||
return contexts[ctx_id], True
|
return contexts[ctx_id], True
|
||||||
|
|
||||||
|
def stop(self):
|
||||||
|
super().stop()
|
||||||
|
# Tear down the worker so any in-flight func_call returns promptly.
|
||||||
|
# join() clears _rpc/_process so a subsequent item reusing the same
|
||||||
|
# context_id can restart the engine cleanly.
|
||||||
|
try:
|
||||||
|
engine, _ = self._get_engine()
|
||||||
|
engine.stop()
|
||||||
|
engine.join()
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
|
||||||
@test_run
|
@test_run
|
||||||
def execute(self):
|
def execute(self):
|
||||||
self.result.set(
|
self.result.set(
|
||||||
@@ -96,8 +108,14 @@ Is the lua environnment well defined in the "LUA_PATH" and "LUA_CPATH" variables
|
|||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
|
except ConnectionAbortedError:
|
||||||
|
self.result.set(TestValue.FAILURE, "lua_func aborted on stop request")
|
||||||
|
print("lua_func aborted on stop request.")
|
||||||
except:
|
except:
|
||||||
traceback.print_exception(*sys.exc_info())
|
traceback.print_exception(*sys.exc_info())
|
||||||
|
if self.isStopped():
|
||||||
|
self.result.set(TestValue.FAILURE, "lua_func aborted on stop request")
|
||||||
|
else:
|
||||||
self.result.set(
|
self.result.set(
|
||||||
TestValue.FAILURE,
|
TestValue.FAILURE,
|
||||||
'Unrecoverable "lua_func" item error from {}'.format(self.func_name),
|
'Unrecoverable "lua_func" item error from {}'.format(self.func_name),
|
||||||
|
|||||||
@@ -45,6 +45,18 @@ class TestItemPyFunc(TestItem):
|
|||||||
tm.setgd(_PY_FUNC_CONTEXTS_KEY, contexts)
|
tm.setgd(_PY_FUNC_CONTEXTS_KEY, contexts)
|
||||||
return contexts[ctx_id], True
|
return contexts[ctx_id], True
|
||||||
|
|
||||||
|
def stop(self):
|
||||||
|
super().stop()
|
||||||
|
# Tear down the worker so any in-flight func_call returns promptly.
|
||||||
|
# join() clears _rpc/_process so a subsequent item reusing the same
|
||||||
|
# context_id can restart the engine cleanly.
|
||||||
|
try:
|
||||||
|
engine, _ = self._get_engine()
|
||||||
|
engine.stop()
|
||||||
|
engine.join()
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
|
||||||
@test_run
|
@test_run
|
||||||
def execute(self):
|
def execute(self):
|
||||||
self.result.set(
|
self.result.set(
|
||||||
@@ -94,8 +106,14 @@ python_bin = {tm.gd("python_bin", "no python path defined")}"""
|
|||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
|
except ConnectionAbortedError:
|
||||||
|
self.result.set(TestValue.FAILURE, "py_func aborted on stop request")
|
||||||
|
print("py_func aborted on stop request.")
|
||||||
except:
|
except:
|
||||||
traceback.print_exception(*sys.exc_info())
|
traceback.print_exception(*sys.exc_info())
|
||||||
|
if self.isStopped():
|
||||||
|
self.result.set(TestValue.FAILURE, "py_func aborted on stop request")
|
||||||
|
else:
|
||||||
self.result.set(
|
self.result.set(
|
||||||
TestValue.FAILURE,
|
TestValue.FAILURE,
|
||||||
'Unrecoverable "py_func" item error from {}'.format(self.func_name),
|
'Unrecoverable "py_func" item error from {}'.format(self.func_name),
|
||||||
|
|||||||
@@ -80,4 +80,7 @@ class TestItemSleep(TestItem):
|
|||||||
end_time = _time.time() + float(timeout)
|
end_time = _time.time() + float(timeout)
|
||||||
while _time.time() < end_time and not self._is_stopped:
|
while _time.time() < end_time and not self._is_stopped:
|
||||||
sleep(min(0.05, end_time - _time.time()))
|
sleep(min(0.05, end_time - _time.time()))
|
||||||
|
if self._is_stopped:
|
||||||
|
self.result.set(TestValue.FAILURE, 'Sleep aborted on stop request')
|
||||||
|
else:
|
||||||
self.result.set(TestValue.SUCCESS, 'Sleep %s sec' % (str(timeout)))
|
self.result.set(TestValue.SUCCESS, 'Sleep %s sec' % (str(timeout)))
|
||||||
|
|||||||
@@ -202,16 +202,24 @@ _SPECS = {
|
|||||||
"lua": ("Lua 5.1+", "lua_bin", _LUA_CANDIDATES, _is_lua51),
|
"lua": ("Lua 5.1+", "lua_bin", _LUA_CANDIDATES, _is_lua51),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Cached per (name, override) so that runtime changes to gd[gd_key] —
|
||||||
|
# e.g. ``python_bin`` set from a YAML config file loaded *after*
|
||||||
|
# eval_proc has already resolved its own interpreter — are picked up by
|
||||||
|
# the next lookup instead of returning the stale, auto-discovered path.
|
||||||
|
# Long-lived subprocesses (eval_proc) keep whatever they captured at
|
||||||
|
# construction time, but every new PyProcessBase / FuncExecEngine spawned
|
||||||
|
# afterwards sees the current override.
|
||||||
_resolved = {}
|
_resolved = {}
|
||||||
|
|
||||||
|
|
||||||
def _resolve(name):
|
def _resolve(name):
|
||||||
if name in _resolved:
|
|
||||||
return _resolved[name]
|
|
||||||
|
|
||||||
display, gd_key, candidates, validator = _SPECS[name]
|
display, gd_key, candidates, validator = _SPECS[name]
|
||||||
override = tm.gd(gd_key, "") or ""
|
override = tm.gd(gd_key, "") or ""
|
||||||
|
|
||||||
|
cached = _resolved.get(name)
|
||||||
|
if cached is not None and cached[0] == override:
|
||||||
|
return cached[1]
|
||||||
|
|
||||||
path = ""
|
path = ""
|
||||||
if override:
|
if override:
|
||||||
# Absolute path: accept as-is (user knows exactly what they want).
|
# Absolute path: accept as-is (user knows exactly what they want).
|
||||||
@@ -239,7 +247,7 @@ def _resolve(name):
|
|||||||
path = p
|
path = p
|
||||||
break
|
break
|
||||||
|
|
||||||
_resolved[name] = path
|
_resolved[name] = (override, path)
|
||||||
return path
|
return path
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -146,4 +146,12 @@ class LuaProcessBase:
|
|||||||
"""
|
"""
|
||||||
if self._rpc is not None:
|
if self._rpc is not None:
|
||||||
self._rpc.stop()
|
self._rpc.stop()
|
||||||
|
# Force-kill the worker if it's still running. Needed when user code
|
||||||
|
# in the worker is stuck and won't notice the parent closing the RPC
|
||||||
|
# socket on its own.
|
||||||
|
if self._process is not None and self._process.poll() is None:
|
||||||
|
try:
|
||||||
|
self._process.terminate()
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|||||||
@@ -123,3 +123,11 @@ class PyProcessBase:
|
|||||||
def stop(self):
|
def stop(self):
|
||||||
if self._rpc is not None:
|
if self._rpc is not None:
|
||||||
self._rpc.stop()
|
self._rpc.stop()
|
||||||
|
# Force-kill the worker if it's still running. Needed when user code
|
||||||
|
# in the worker is stuck (e.g. sleep, blocking I/O) and won't notice
|
||||||
|
# the parent closing the RPC socket on its own.
|
||||||
|
if self._process is not None and self._process.poll() is None:
|
||||||
|
try:
|
||||||
|
self._process.terminate()
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
|||||||
@@ -165,11 +165,14 @@ def env_init():
|
|||||||
_constants_init()
|
_constants_init()
|
||||||
|
|
||||||
|
|
||||||
def update_global(config_files, defines, gui_defaults, silent=False):
|
def apply_overrides(defines, gui_defaults):
|
||||||
"""Global dict updated with the content of the config file and a dict provided.
|
"""Push GUI defaults then CLI defines into the global dict.
|
||||||
this function returns the resulting dict.
|
|
||||||
|
Extracted from update_global so it can be called *before* eval_proc
|
||||||
|
starts: interpreter overrides (python_bin, lua_bin) must be visible
|
||||||
|
to bins.python_bin() on its first lookup, which happens during
|
||||||
|
eval_process_init.
|
||||||
"""
|
"""
|
||||||
# GUI preferences applied first
|
|
||||||
for k, v in gui_defaults.items():
|
for k, v in gui_defaults.items():
|
||||||
try:
|
try:
|
||||||
val = ast.literal_eval(v)
|
val = ast.literal_eval(v)
|
||||||
@@ -177,7 +180,6 @@ def update_global(config_files, defines, gui_defaults, silent=False):
|
|||||||
val = v
|
val = v
|
||||||
tm.setgd(k, val)
|
tm.setgd(k, val)
|
||||||
|
|
||||||
# Then command line defines
|
|
||||||
for k, v in defines.items():
|
for k, v in defines.items():
|
||||||
try:
|
try:
|
||||||
val = ast.literal_eval(v)
|
val = ast.literal_eval(v)
|
||||||
@@ -185,6 +187,14 @@ def update_global(config_files, defines, gui_defaults, silent=False):
|
|||||||
val = v
|
val = v
|
||||||
tm.setgd(k, val)
|
tm.setgd(k, val)
|
||||||
|
|
||||||
|
|
||||||
|
def update_global(config_files, defines, gui_defaults, silent=False):
|
||||||
|
"""Global dict updated with the content of the config file and a dict provided.
|
||||||
|
this function returns the resulting dict.
|
||||||
|
"""
|
||||||
|
# GUI preferences applied first, then command line defines
|
||||||
|
apply_overrides(defines, gui_defaults)
|
||||||
|
|
||||||
# Then the configuration files
|
# Then the configuration files
|
||||||
# load global dic before test item
|
# load global dic before test item
|
||||||
_feed_gd_with_params(config_files, silent)
|
_feed_gd_with_params(config_files, silent)
|
||||||
|
|||||||
@@ -41,8 +41,7 @@ end
|
|||||||
--- INTERNAL: Handle requests from the client
|
--- INTERNAL: Handle requests from the client
|
||||||
function JSONRPC:_handle_request(req)
|
function JSONRPC:_handle_request(req)
|
||||||
local method = self.methods[req.method]
|
local method = self.methods[req.method]
|
||||||
local ok, ret
|
local ok, ret, err
|
||||||
local res, err
|
|
||||||
if not method then
|
if not method then
|
||||||
if req.id then self:_send_error(req.id, string.format("Method '%s' not registered in lua server")) end
|
if req.id then self:_send_error(req.id, string.format("Method '%s' not registered in lua server")) end
|
||||||
return
|
return
|
||||||
@@ -52,15 +51,18 @@ function JSONRPC:_handle_request(req)
|
|||||||
|
|
||||||
-- Only send response if it's not a Notification (notifications have no ID)
|
-- Only send response if it's not a Notification (notifications have no ID)
|
||||||
if req.id then
|
if req.id then
|
||||||
if ok then
|
if not ok then
|
||||||
res = ret
|
-- pcall trapped a runtime error in the method itself.
|
||||||
if res == nil then
|
self:_send_error(req.id, tostring(ret))
|
||||||
|
elseif err ~= nil then
|
||||||
|
-- Method ran but signaled a logical error via its 2nd return.
|
||||||
self:_send_error(req.id, tostring(err))
|
self:_send_error(req.id, tostring(err))
|
||||||
else
|
else
|
||||||
self:_send({ jsonrpc = "2.0", result = { returned_value = res }, id = req.id })
|
-- Success. A user function returning nothing yields ret==nil;
|
||||||
end
|
-- encode it as JSON null so "returned_value" stays present.
|
||||||
else
|
local val = ret
|
||||||
self:_send_error(req.id, tostring(err))
|
if val == nil then val = json.null end
|
||||||
|
self:_send({ jsonrpc = "2.0", result = { returned_value = val }, id = req.id })
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
21
src/testium/main_win/file_dialog.py
Normal file
21
src/testium/main_win/file_dialog.py
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
"""Helpers for Qt file/directory dialogs.
|
||||||
|
|
||||||
|
In Flatpak the native QFileDialog goes through the XDG document portal,
|
||||||
|
which returns ``/run/user/UID/doc/.../<file>`` and only exposes the
|
||||||
|
selected file — sibling files (param.yaml, scripts, recent paths in
|
||||||
|
preferences, ...) are unreachable. Forcing Qt's own non-native dialog
|
||||||
|
makes it walk the real filesystem mounted via ``--filesystem=home``
|
||||||
|
and return a regular path.
|
||||||
|
"""
|
||||||
|
|
||||||
|
import os
|
||||||
|
|
||||||
|
from PySide6.QtWidgets import QFileDialog
|
||||||
|
|
||||||
|
|
||||||
|
def options():
|
||||||
|
"""Default ``QFileDialog`` options for the current runtime."""
|
||||||
|
opts = QFileDialog.Options()
|
||||||
|
if os.path.isfile("/.flatpak-info"):
|
||||||
|
opts |= QFileDialog.Option.DontUseNativeDialog
|
||||||
|
return opts
|
||||||
@@ -3,6 +3,7 @@ from PySide6.QtWidgets import QDialog, QFileDialog
|
|||||||
from PySide6.QtGui import QFont
|
from PySide6.QtGui import QFont
|
||||||
|
|
||||||
from main_win.preference_win.preference_core_win import Ui_preferenceWindow
|
from main_win.preference_win.preference_core_win import Ui_preferenceWindow
|
||||||
|
from main_win import file_dialog
|
||||||
|
|
||||||
import interpreter.utils.settings as prefs
|
import interpreter.utils.settings as prefs
|
||||||
|
|
||||||
@@ -193,6 +194,7 @@ class PrefWindow(QDialog):
|
|||||||
self,
|
self,
|
||||||
caption="Select the default report directory",
|
caption="Select the default report directory",
|
||||||
dir=self.ui.editDefaultReportPath.text(),
|
dir=self.ui.editDefaultReportPath.text(),
|
||||||
|
options=file_dialog.options(),
|
||||||
)
|
)
|
||||||
if path:
|
if path:
|
||||||
self.ui.editDefaultReportPath.setText(path)
|
self.ui.editDefaultReportPath.setText(path)
|
||||||
@@ -203,6 +205,7 @@ class PrefWindow(QDialog):
|
|||||||
self,
|
self,
|
||||||
caption="Select the default log directory",
|
caption="Select the default log directory",
|
||||||
dir=self.ui.editDefaultLogPath.text(),
|
dir=self.ui.editDefaultLogPath.text(),
|
||||||
|
options=file_dialog.options(),
|
||||||
)
|
)
|
||||||
if path:
|
if path:
|
||||||
self.ui.editDefaultLogPath.setText(path)
|
self.ui.editDefaultLogPath.setText(path)
|
||||||
@@ -213,6 +216,7 @@ class PrefWindow(QDialog):
|
|||||||
self,
|
self,
|
||||||
caption="Select the python interpreter",
|
caption="Select the python interpreter",
|
||||||
dir=self.ui.editPythonPath.text(),
|
dir=self.ui.editPythonPath.text(),
|
||||||
|
options=file_dialog.options(),
|
||||||
)
|
)
|
||||||
if path:
|
if path:
|
||||||
self.ui.editPythonPath.setText(path)
|
self.ui.editPythonPath.setText(path)
|
||||||
@@ -220,7 +224,10 @@ class PrefWindow(QDialog):
|
|||||||
@Slot()
|
@Slot()
|
||||||
def on_butLuaPath_pressed(self):
|
def on_butLuaPath_pressed(self):
|
||||||
path, _ = QFileDialog.getOpenFileName(
|
path, _ = QFileDialog.getOpenFileName(
|
||||||
self, caption="Select the lua interpreter", dir=self.ui.editLuaPath.text()
|
self,
|
||||||
|
caption="Select the lua interpreter",
|
||||||
|
dir=self.ui.editLuaPath.text(),
|
||||||
|
options=file_dialog.options(),
|
||||||
)
|
)
|
||||||
if path:
|
if path:
|
||||||
self.ui.editLuaPath.setText(path)
|
self.ui.editLuaPath.setText(path)
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ from PySide6.QtWidgets import QApplication, QFileDialog, QProgressDialog
|
|||||||
from interpreter.process import TestProcess
|
from interpreter.process import TestProcess
|
||||||
from interpreter.utils.test_ctrl import TestSetController
|
from interpreter.utils.test_ctrl import TestSetController
|
||||||
from main_win.test_controller_service import TestControllerService
|
from main_win.test_controller_service import TestControllerService
|
||||||
|
from main_win import file_dialog
|
||||||
import interpreter.utils.settings as prefs
|
import interpreter.utils.settings as prefs
|
||||||
from runtime.tum_except import ETUMFileError, ETUMRuntimeError
|
from runtime.tum_except import ETUMFileError, ETUMRuntimeError
|
||||||
|
|
||||||
@@ -213,7 +214,8 @@ class TestFileManager:
|
|||||||
if w.testFile is not None:
|
if w.testFile is not None:
|
||||||
d = os.path.dirname(w.testFile)
|
d = os.path.dirname(w.testFile)
|
||||||
file_name, _ = QFileDialog.getOpenFileName(
|
file_name, _ = QFileDialog.getOpenFileName(
|
||||||
w, "Open the test file", d, "testium file (*.tum);;All Files (*)"
|
w, "Open the test file", d,
|
||||||
|
"testium file (*.tum);;All Files (*)", options=file_dialog.options()
|
||||||
)
|
)
|
||||||
if file_name:
|
if file_name:
|
||||||
self.reload(file_name)
|
self.reload(file_name)
|
||||||
|
|||||||
@@ -176,7 +176,7 @@ class TestRunner:
|
|||||||
w.actionOpenTest.setDisabled(True)
|
w.actionOpenTest.setDisabled(True)
|
||||||
w.actionExit.setDisabled(True)
|
w.actionExit.setDisabled(True)
|
||||||
icon = QtGui.QIcon()
|
icon = QtGui.QIcon()
|
||||||
icon.addPixmap(QtGui.QPixmap(icon_prefix() + "/pause.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
|
icon.addPixmap(QtGui.QPixmap(icon_prefix() + "/pause2.png"), QtGui.QIcon.Normal, QtGui.QIcon.On)
|
||||||
w.actionStart_test.setIcon(icon)
|
w.actionStart_test.setIcon(icon)
|
||||||
w.actionStart_test.setText("Pause test")
|
w.actionStart_test.setText("Pause test")
|
||||||
w.actionPreferences.setDisabled(True)
|
w.actionPreferences.setDisabled(True)
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ from interpreter.utils.icons import icon_prefix
|
|||||||
|
|
||||||
from main_win.test_run.outlog import OutLog
|
from main_win.test_run.outlog import OutLog
|
||||||
from main_win.test_run.test_run import ThreadTestStatus
|
from main_win.test_run.test_run import ThreadTestStatus
|
||||||
|
from main_win import file_dialog
|
||||||
import interpreter.utils.settings as prefs
|
import interpreter.utils.settings as prefs
|
||||||
from runtime.stdout_redirect import stdio_redir
|
from runtime.stdout_redirect import stdio_redir
|
||||||
import api.testium as tm
|
import api.testium as tm
|
||||||
@@ -484,7 +485,8 @@ class MainWindow(QMainWindow, Ui_MainWindow):
|
|||||||
else:
|
else:
|
||||||
initialPath = None
|
initialPath = None
|
||||||
fileName, _ = QFileDialog.getSaveFileName(
|
fileName, _ = QFileDialog.getSaveFileName(
|
||||||
self, "Path to Log file", initialPath, "Log Files (*.log);;All Files (*)"
|
self, "Path to Log file", initialPath, "Log Files (*.log);;All Files (*)",
|
||||||
|
options=file_dialog.options(),
|
||||||
)
|
)
|
||||||
if fileName:
|
if fileName:
|
||||||
shutil.copy(self.logFileName, fileName)
|
shutil.copy(self.logFileName, fileName)
|
||||||
@@ -525,7 +527,8 @@ class MainWindow(QMainWindow, Ui_MainWindow):
|
|||||||
else:
|
else:
|
||||||
initialPath = None
|
initialPath = None
|
||||||
fileName, _ = QFileDialog.getSaveFileName(
|
fileName, _ = QFileDialog.getSaveFileName(
|
||||||
self, "Path to log file", initialPath, "Log Files (*.log);;All Files (*)"
|
self, "Path to log file", initialPath, "Log Files (*.log);;All Files (*)",
|
||||||
|
options=file_dialog.options(),
|
||||||
)
|
)
|
||||||
if fileName:
|
if fileName:
|
||||||
self.editLogFilePath.setText(fileName)
|
self.editLogFilePath.setText(fileName)
|
||||||
|
|||||||
@@ -200,6 +200,7 @@ class JsonRpcConnection:
|
|||||||
|
|
||||||
Raises:
|
Raises:
|
||||||
TimeoutError: If no response is received within `timeout`.
|
TimeoutError: If no response is received within `timeout`.
|
||||||
|
ConnectionAbortedError: If stop() was called while waiting.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
req_id = next(self.id_gen)
|
req_id = next(self.id_gen)
|
||||||
@@ -214,7 +215,12 @@ class JsonRpcConnection:
|
|||||||
self.pending.pop(req_id, None)
|
self.pending.pop(req_id, None)
|
||||||
raise TimeoutError("Timeout JSON-RPC")
|
raise TimeoutError("Timeout JSON-RPC")
|
||||||
|
|
||||||
return self.pending.pop(req_id)["response"]
|
entry = self.pending.pop(req_id)
|
||||||
|
if entry["response"] is None:
|
||||||
|
# Woken by stop() (or by a malformed dispatch) rather than by a
|
||||||
|
# real response — abort the call so callers don't block further.
|
||||||
|
raise ConnectionAbortedError("JSON-RPC client stopped")
|
||||||
|
return entry["response"]
|
||||||
|
|
||||||
def print_info(self, msg):
|
def print_info(self, msg):
|
||||||
if self.dbg_out is not None:
|
if self.dbg_out is not None:
|
||||||
@@ -223,6 +229,10 @@ class JsonRpcConnection:
|
|||||||
def stop(self):
|
def stop(self):
|
||||||
if self.running:
|
if self.running:
|
||||||
self.running = False
|
self.running = False
|
||||||
|
# Wake any in-flight call() so it doesn't sit on its (default 1h)
|
||||||
|
# timeout. The response stays None and call() raises ConnectionAbortedError.
|
||||||
|
for entry in list(self.pending.values()):
|
||||||
|
entry["event"].set()
|
||||||
|
|
||||||
def join(self):
|
def join(self):
|
||||||
self.recv_thread.join()
|
self.recv_thread.join()
|
||||||
|
|||||||
@@ -1,10 +1,43 @@
|
|||||||
# Validation
|
# Validation
|
||||||
|
|
||||||
This directory contains the necessary material to run the testium validation.
|
This directory contains the testium validation suite.
|
||||||
|
|
||||||
Here is the documentation on how to configure the validation, run it and check that the
|
## Running the suite
|
||||||
results are correct.
|
|
||||||
|
|
||||||
# Tests
|
```sh
|
||||||
|
./test/validation/run.sh # Linux
|
||||||
|
test\validation\run.bat # Windows
|
||||||
|
```
|
||||||
|
|
||||||
TBD
|
The wrapper creates a dedicated Python venv in the system temp dir
|
||||||
|
(`${TMPDIR:-/tmp}/testium-validation-venv` on Linux, `%TEMP%\testium-validation-venv`
|
||||||
|
on Windows), using `--system-site-packages` so existing system packages
|
||||||
|
stay visible. The validation suite is then run with that venv pinned as
|
||||||
|
`python_bin`. Every test-execution subprocess (inline `<| ... |>`
|
||||||
|
evaluation, `py_func`, `cycle`, `post_execution`, ...) runs inside the
|
||||||
|
venv, while testium itself keeps running in the project's own
|
||||||
|
environment.
|
||||||
|
|
||||||
|
Pass `clean` as the first argument to recreate the venv from scratch
|
||||||
|
(useful after a system Python upgrade):
|
||||||
|
|
||||||
|
```sh
|
||||||
|
./test/validation/run.sh clean
|
||||||
|
```
|
||||||
|
|
||||||
|
## What is checked
|
||||||
|
|
||||||
|
The `venv` item under `items/venv/` asserts that the venv is actually
|
||||||
|
being used:
|
||||||
|
|
||||||
|
* `python_bin` is set in the global dict.
|
||||||
|
* The eval subprocess (used for `<| ... |>` expressions) has
|
||||||
|
`sys.executable == python_bin`, `sys.prefix == dirname(dirname(python_bin))`,
|
||||||
|
and `sys.prefix != sys.base_prefix` (i.e. is actually inside a venv).
|
||||||
|
* A `py_func` subprocess passes the same three checks.
|
||||||
|
|
||||||
|
These checks use `abspath`/`normpath` rather than `realpath` on
|
||||||
|
purpose: the venv's `bin/python3` is a symlink to the host interpreter,
|
||||||
|
so `realpath` would map both venv and non-venv interpreters to the same
|
||||||
|
target. `sys.prefix != sys.base_prefix` is the venv-specific marker
|
||||||
|
that distinguishes the two cases.
|
||||||
|
|||||||
@@ -49,4 +49,12 @@ function module.test_delgd()
|
|||||||
return 0
|
return 0
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function module.return_nothing()
|
||||||
|
-- Returns no value: ret is nil but no error.
|
||||||
|
end
|
||||||
|
|
||||||
|
function module.return_explicit_nil()
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
|
||||||
return module
|
return module
|
||||||
@@ -186,6 +186,18 @@
|
|||||||
file: $(test_path)$(psep)lua_func.lua
|
file: $(test_path)$(psep)lua_func.lua
|
||||||
func_name: test_delgd
|
func_name: test_delgd
|
||||||
|
|
||||||
|
- lua_func:
|
||||||
|
name: function returning nothing should succeed
|
||||||
|
key: $(test)_PASS
|
||||||
|
file: $(test_path)$(psep)lua_func.lua
|
||||||
|
func_name: return_nothing
|
||||||
|
|
||||||
|
- lua_func:
|
||||||
|
name: function returning explicit nil should succeed
|
||||||
|
key: $(test)_PASS
|
||||||
|
file: $(test_path)$(psep)lua_func.lua
|
||||||
|
func_name: return_explicit_nil
|
||||||
|
|
||||||
- group:
|
- group:
|
||||||
name: context_id tests
|
name: context_id tests
|
||||||
steps:
|
steps:
|
||||||
|
|||||||
@@ -54,3 +54,10 @@ def test_delgd():
|
|||||||
tm.delgd("_py_delgd_test")
|
tm.delgd("_py_delgd_test")
|
||||||
assert tm.gd("_py_delgd_test", None) is None
|
assert tm.gd("_py_delgd_test", None) is None
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
def return_nothing():
|
||||||
|
# Falls off the end: implicit None return, no error.
|
||||||
|
pass
|
||||||
|
|
||||||
|
def return_explicit_none():
|
||||||
|
return None
|
||||||
|
|||||||
@@ -196,6 +196,18 @@
|
|||||||
file: $(test_path)$(psep)py_func.py
|
file: $(test_path)$(psep)py_func.py
|
||||||
func_name: test_delgd
|
func_name: test_delgd
|
||||||
|
|
||||||
|
- py_func:
|
||||||
|
name: function returning nothing should succeed
|
||||||
|
key: $(test)_PASS
|
||||||
|
file: $(test_path)$(psep)py_func.py
|
||||||
|
func_name: return_nothing
|
||||||
|
|
||||||
|
- py_func:
|
||||||
|
name: function returning explicit None should succeed
|
||||||
|
key: $(test)_PASS
|
||||||
|
file: $(test_path)$(psep)py_func.py
|
||||||
|
func_name: return_explicit_none
|
||||||
|
|
||||||
- group:
|
- group:
|
||||||
name: context_id tests
|
name: context_id tests
|
||||||
steps:
|
steps:
|
||||||
|
|||||||
1
test/validation/items/venv/param.yaml
Normal file
1
test/validation/items/venv/param.yaml
Normal file
@@ -0,0 +1 @@
|
|||||||
|
no_param: Null
|
||||||
53
test/validation/items/venv/test.tum
Normal file
53
test/validation/items/venv/test.tum
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
# venv test: assert that the dedicated validation venv is the python
|
||||||
|
# being used for every test-execution subprocess (eval_proc / py_func /
|
||||||
|
# cycle / ...). The venv path is pinned by ``-d python_bin=...`` in
|
||||||
|
# test/validation/run.sh (or run.bat).
|
||||||
|
#
|
||||||
|
# We use ``abspath``/``normpath`` rather than ``realpath`` on purpose:
|
||||||
|
# the venv's ``bin/python3`` is a symlink to the host python, so
|
||||||
|
# realpath would map every venv interpreter to the same system path and
|
||||||
|
# the comparison would silently pass even *without* a venv.
|
||||||
|
# ``sys.prefix != sys.base_prefix`` is the venv-specific marker that
|
||||||
|
# catches that case.
|
||||||
|
|
||||||
|
- check:
|
||||||
|
name: python_bin is set in the global dict
|
||||||
|
key: $(test)_PASS
|
||||||
|
values:
|
||||||
|
- <| bool(r"$(python_bin)") |>
|
||||||
|
|
||||||
|
- check:
|
||||||
|
name: eval_proc subprocess runs in the validation venv
|
||||||
|
key: $(test)_PASS
|
||||||
|
values:
|
||||||
|
- <| os.path.normpath(os.path.abspath(sys.executable)) == os.path.normpath(os.path.abspath(r"$(python_bin)")) |>
|
||||||
|
|
||||||
|
- check:
|
||||||
|
name: eval_proc sys.prefix matches python_bin venv root
|
||||||
|
key: $(test)_PASS
|
||||||
|
values:
|
||||||
|
- <| os.path.normpath(os.path.abspath(sys.prefix)) == os.path.dirname(os.path.dirname(os.path.normpath(os.path.abspath(r"$(python_bin)")))) |>
|
||||||
|
|
||||||
|
- check:
|
||||||
|
name: eval_proc is actually inside a venv (sys.prefix != sys.base_prefix)
|
||||||
|
key: $(test)_PASS
|
||||||
|
values:
|
||||||
|
- <| os.path.normpath(os.path.abspath(sys.prefix)) != os.path.normpath(os.path.abspath(sys.base_prefix)) |>
|
||||||
|
|
||||||
|
- py_func:
|
||||||
|
name: py_func subprocess runs in the validation venv
|
||||||
|
key: $(test)_PASS
|
||||||
|
file: $(test_path)$(psep)verify_venv.py
|
||||||
|
func_name: check_sys_executable
|
||||||
|
|
||||||
|
- py_func:
|
||||||
|
name: py_func sys.prefix matches python_bin venv root
|
||||||
|
key: $(test)_PASS
|
||||||
|
file: $(test_path)$(psep)verify_venv.py
|
||||||
|
func_name: check_sys_prefix_in_venv
|
||||||
|
|
||||||
|
- py_func:
|
||||||
|
name: py_func is actually inside a venv
|
||||||
|
key: $(test)_PASS
|
||||||
|
file: $(test_path)$(psep)verify_venv.py
|
||||||
|
func_name: check_is_venv
|
||||||
62
test/validation/items/venv/verify_venv.py
Normal file
62
test/validation/items/venv/verify_venv.py
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
|
import py_func.tm as tm
|
||||||
|
|
||||||
|
|
||||||
|
def _norm(p):
|
||||||
|
# normpath + normcase, without resolving symlinks. realpath() would
|
||||||
|
# follow the venv's ``python3`` symlink to ``/usr/bin/python3.X`` and
|
||||||
|
# defeat the comparison.
|
||||||
|
return os.path.normcase(os.path.normpath(os.path.abspath(p)))
|
||||||
|
|
||||||
|
|
||||||
|
def _venv_dir():
|
||||||
|
# python_bin is at ``<venv>/(bin|Scripts)/python*`` so the venv root
|
||||||
|
# is two levels above the executable.
|
||||||
|
exe = tm.gd("python_bin", "")
|
||||||
|
if not exe:
|
||||||
|
return ""
|
||||||
|
return os.path.dirname(os.path.dirname(_norm(exe)))
|
||||||
|
|
||||||
|
|
||||||
|
def check_sys_executable():
|
||||||
|
"""py_func subprocess: sys.executable must match the configured python_bin."""
|
||||||
|
expected = _norm(tm.gd("python_bin", ""))
|
||||||
|
actual = _norm(sys.executable)
|
||||||
|
if expected and actual == expected:
|
||||||
|
return True
|
||||||
|
return (
|
||||||
|
-1,
|
||||||
|
f"sys.executable={actual!r} differs from python_bin={expected!r}",
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def check_sys_prefix_in_venv():
|
||||||
|
"""py_func subprocess: sys.prefix must match the venv root derived
|
||||||
|
from python_bin (two levels up from the executable)."""
|
||||||
|
venv = _venv_dir()
|
||||||
|
if not venv:
|
||||||
|
return (-1, "python_bin is not set in the global dict")
|
||||||
|
actual = _norm(sys.prefix)
|
||||||
|
if actual == venv:
|
||||||
|
return True
|
||||||
|
return (
|
||||||
|
-1,
|
||||||
|
f"sys.prefix={actual!r} is not the validation venv {venv!r}",
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def check_is_venv():
|
||||||
|
"""py_func subprocess: confirm we are inside a venv, i.e. sys.prefix
|
||||||
|
differs from sys.base_prefix. This catches the case where python_bin
|
||||||
|
happens to be a system interpreter and the path-based check would
|
||||||
|
pass trivially."""
|
||||||
|
actual = _norm(sys.prefix)
|
||||||
|
base = _norm(sys.base_prefix)
|
||||||
|
if actual != base:
|
||||||
|
return True
|
||||||
|
return (
|
||||||
|
-1,
|
||||||
|
f"sys.prefix == sys.base_prefix == {actual!r}: not running in a venv",
|
||||||
|
)
|
||||||
61
test/validation/run.bat
Normal file
61
test/validation/run.bat
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
@echo off
|
||||||
|
SETLOCAL EnableExtensions
|
||||||
|
|
||||||
|
REM Runs the testium validation suite with a dedicated Python venv used
|
||||||
|
REM by every py_func / cycle / inline-eval subprocess. testium itself
|
||||||
|
REM keeps running in the project's own environment; the validation venv
|
||||||
|
REM only isolates *test execution*.
|
||||||
|
REM
|
||||||
|
REM test\validation\run.bat [clean] [extra testium args]
|
||||||
|
REM
|
||||||
|
REM Requires the project venv to already exist (run the project's
|
||||||
|
REM run.bat once first, or any other testium install method).
|
||||||
|
|
||||||
|
SET "SCRIPT_DIR=%~dp0"
|
||||||
|
SET "PROJECT_DIR=%SCRIPT_DIR%..\.."
|
||||||
|
REM Venv in the user temp dir (Windows equivalent of /tmp).
|
||||||
|
SET "VENV_DIR=%TEMP%\testium-validation-venv"
|
||||||
|
SET "PROJECT_VENV=%PROJECT_DIR%\test\tmp\testium_venv"
|
||||||
|
|
||||||
|
IF /I "%~1"=="clean" (
|
||||||
|
rmdir /s /q "%VENV_DIR%"
|
||||||
|
SHIFT
|
||||||
|
)
|
||||||
|
|
||||||
|
REM Locate a host Python.
|
||||||
|
SET "PYTHON_EXE=python"
|
||||||
|
py --version >nul 2>&1
|
||||||
|
IF %ERRORLEVEL% EQU 0 (
|
||||||
|
SET "PYTHON_EXE=py"
|
||||||
|
goto :PYTHON_FOUND
|
||||||
|
)
|
||||||
|
python --version >nul 2>&1
|
||||||
|
IF %ERRORLEVEL% EQU 0 (
|
||||||
|
SET "PYTHON_EXE=python"
|
||||||
|
goto :PYTHON_FOUND
|
||||||
|
)
|
||||||
|
echo ERROR : Python could not be found on this system.
|
||||||
|
exit /b 1
|
||||||
|
|
||||||
|
:PYTHON_FOUND
|
||||||
|
|
||||||
|
IF NOT EXIST "%VENV_DIR%" (
|
||||||
|
echo Creating validation venv at %VENV_DIR%
|
||||||
|
%PYTHON_EXE% -m venv --system-site-packages "%VENV_DIR%"
|
||||||
|
IF %ERRORLEVEL% NEQ 0 (
|
||||||
|
echo ERROR while creating the validation venv.
|
||||||
|
exit /b 1
|
||||||
|
)
|
||||||
|
call "%VENV_DIR%\Scripts\pip" install --quiet --upgrade pip
|
||||||
|
call "%VENV_DIR%\Scripts\pip" install --quiet junit-xml
|
||||||
|
)
|
||||||
|
|
||||||
|
SET "VENV_PYTHON=%VENV_DIR%\Scripts\python.exe"
|
||||||
|
|
||||||
|
IF NOT EXIST "%PROJECT_VENV%" (
|
||||||
|
echo ERROR : project venv not found at %PROJECT_VENV%. Run the project run.bat once first.
|
||||||
|
exit /b 1
|
||||||
|
)
|
||||||
|
|
||||||
|
call "%PROJECT_VENV%\Scripts\activate"
|
||||||
|
python "%PROJECT_DIR%\src\testium" -b -d "python_bin=%VENV_PYTHON%" -- "%SCRIPT_DIR%main.tum" %*
|
||||||
47
test/validation/run.sh
Executable file
47
test/validation/run.sh
Executable file
@@ -0,0 +1,47 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# Runs the testium validation suite with a dedicated Python venv used by
|
||||||
|
# every py_func / cycle / inline-eval subprocess (i.e. everything that
|
||||||
|
# goes through ``bins.python_bin()``). testium itself keeps running in
|
||||||
|
# the project's own environment — the validation venv only isolates
|
||||||
|
# *test execution*.
|
||||||
|
#
|
||||||
|
# ./test/validation/run.sh [clean] [extra testium args]
|
||||||
|
#
|
||||||
|
# ``clean`` (optional, must be the first arg) removes the venv before
|
||||||
|
# recreating it; this is the way to refresh the venv after a system
|
||||||
|
# Python upgrade.
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
SCRIPT_PATH="$(readlink -f "$0")"
|
||||||
|
SCRIPT_DIR="$(realpath "$(dirname "$SCRIPT_PATH")")"
|
||||||
|
PROJECT_DIR="$(realpath "$SCRIPT_DIR/../..")"
|
||||||
|
# Venv lives in the system temp dir so it stays out of the project tree
|
||||||
|
# (and is naturally cleaned up by tmpfiles/reboot on most distros).
|
||||||
|
VENV_DIR="${TMPDIR:-/tmp}/testium-validation-venv"
|
||||||
|
|
||||||
|
if [ "${1:-}" = "clean" ]; then
|
||||||
|
rm -rf "$VENV_DIR"
|
||||||
|
shift
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ ! -d "$VENV_DIR" ]; then
|
||||||
|
echo "Creating validation venv at $VENV_DIR"
|
||||||
|
# --system-site-packages so we don't have to reinstall pyside6, lxml
|
||||||
|
# & friends just to support the validation helpers. We still pip
|
||||||
|
# install junit-xml below because it is the one dep that does *not*
|
||||||
|
# ship as a system package on most distros and is required by
|
||||||
|
# post_execution.py.
|
||||||
|
python3 -m venv --system-site-packages "$VENV_DIR"
|
||||||
|
"$VENV_DIR/bin/pip" install --quiet --upgrade pip
|
||||||
|
"$VENV_DIR/bin/pip" install --quiet junit-xml
|
||||||
|
fi
|
||||||
|
|
||||||
|
VENV_PYTHON="$VENV_DIR/bin/python3"
|
||||||
|
|
||||||
|
# Delegate to the project's run.sh so testium itself still runs in the
|
||||||
|
# project venv (with pyside6, gitpython, ...). ``-d python_bin=...``
|
||||||
|
# pins every test-execution subprocess to the validation venv.
|
||||||
|
exec "$PROJECT_DIR/run.sh" -b \
|
||||||
|
-d "python_bin=$VENV_PYTHON" \
|
||||||
|
-- "$SCRIPT_DIR/main.tum" "$@"
|
||||||
Reference in New Issue
Block a user