#include <python_test_helper.h>
Public Member Functions | |
| PythonTestHelper () | |
| bool | isAvailable () const |
| bool | isPythonAvailable () const |
| bool | hasPackage (const QString &packageName) const |
| PythonRunnerResult | eval (const QString &code, int timeoutMs=30000) const |
| double | evalDouble (const QString &code, bool *ok=nullptr, int timeoutMs=30000) const |
| Eigen::VectorXd | evalVector (const QString &code, bool *ok=nullptr, int timeoutMs=60000) const |
| Eigen::MatrixXd | evalMatrix (const QString &code, bool *ok=nullptr, int timeoutMs=60000) const |
| PythonRunnerResult | runScript (const QString &scriptPath, const QStringList &args={}, int timeoutMs=120000) const |
| Eigen::MatrixXd | evalMatrixViaFile (const QString &code, const QString &outputFilePath, bool *ok=nullptr, int timeoutMs=120000) const |
Static Public Member Functions | |
| static QString | testDataPath () |
| static bool | isPythonRequired () |
| static bool | writeMatrix (const QString &filePath, const Eigen::MatrixXd &mat) |
| static Eigen::MatrixXd | readMatrix (const QString &filePath, bool *ok=nullptr) |
Definition at line 128 of file python_test_helper.h.
| PythonTestHelper::PythonTestHelper | ( | ) |
Constructs a PythonTestHelper with auto-detected Python.
Definition at line 59 of file python_test_helper.cpp.
| PythonRunnerResult PythonTestHelper::eval | ( | const QString & | code, |
| int | timeoutMs = 30000 ) const |
Run inline Python code and return the result.
| [in] | code | Python code to execute via python -c. |
| [in] | timeoutMs | Timeout in milliseconds (-1 = no limit). |
Definition at line 86 of file python_test_helper.cpp.
| double PythonTestHelper::evalDouble | ( | const QString & | code, |
| bool * | ok = nullptr, | ||
| int | timeoutMs = 30000 ) const |
Run inline Python code that prints a single double value, and parse it.
| [in] | code | Python code whose stdout is a single number. |
| [in] | ok | Set to true on success, false on parse failure. |
| [in] | timeoutMs | Timeout in milliseconds. |
Definition at line 94 of file python_test_helper.cpp.
| MatrixXd PythonTestHelper::evalMatrix | ( | const QString & | code, |
| bool * | ok = nullptr, | ||
| int | timeoutMs = 60000 ) const |
Run inline Python code that prints a matrix (one row per line, space-separated values), and parse it into an Eigen MatrixXd.
| [in] | code | Python code whose stdout is a space-separated matrix. |
| [in] | ok | Set to true on success. |
| [in] | timeoutMs | Timeout in milliseconds. |
Definition at line 153 of file python_test_helper.cpp.
| MatrixXd PythonTestHelper::evalMatrixViaFile | ( | const QString & | code, |
| const QString & | outputFilePath, | ||
| bool * | ok = nullptr, | ||
| int | timeoutMs = 120000 ) const |
Run Python code that writes a matrix to outputFilePath (e.g. via numpy.savetxt), then read the result back as an Eigen MatrixXd.
This is preferred over evalMatrix() for large matrices or when full double precision is required, because it avoids stdout parsing.
Example:
| [in] | code | Python code to execute. |
| [in] | outputFilePath | Path where Python writes the matrix. |
| [out] | ok | Set to true on success. |
| [in] | timeoutMs | Timeout in milliseconds. |
Definition at line 319 of file python_test_helper.cpp.
| VectorXd PythonTestHelper::evalVector | ( | const QString & | code, |
| bool * | ok = nullptr, | ||
| int | timeoutMs = 60000 ) const |
Run inline Python code that prints a flat array of doubles (one per line or space-separated), and parse it into an Eigen VectorXd.
| [in] | code | Python code whose stdout is numeric values. |
| [in] | ok | Set to true on success. |
| [in] | timeoutMs | Timeout in milliseconds. |
Definition at line 110 of file python_test_helper.cpp.
| bool PythonTestHelper::hasPackage | ( | const QString & | packageName | ) | const |
Check if a specific Python package is importable.
| [in] | packageName | Package name (e.g. "numpy", "scipy", "mne"). |
Definition at line 79 of file python_test_helper.cpp.
| bool PythonTestHelper::isAvailable | ( | ) | const |
Check if Python is available and MNE-Python is importable.
Definition at line 65 of file python_test_helper.cpp.
| bool PythonTestHelper::isPythonAvailable | ( | ) | const |
Check if Python is available (without checking for mne package).
Definition at line 72 of file python_test_helper.cpp.
|
static |
Check whether the environment demands Python availability.
When MNE_REQUIRE_PYTHON=true is set, test guards should QFAIL instead of QSKIP, ensuring skips are never silent in CI.
Definition at line 229 of file python_test_helper.cpp.
|
static |
Read an Eigen matrix from a text file (space-separated values, one row per line). Compatible with numpy.savetxt() output.
| [in] | filePath | Input file path. |
| [out] | ok | Set to true on success, false on failure. |
Definition at line 262 of file python_test_helper.cpp.
| PythonRunnerResult PythonTestHelper::runScript | ( | const QString & | scriptPath, |
| const QStringList & | args = {}, | ||
| int | timeoutMs = 120000 ) const |
Run a Python script file and return the result.
| [in] | scriptPath | Path to the .py file. |
| [in] | args | Arguments forwarded to the script. |
| [in] | timeoutMs | Timeout in milliseconds. |
Definition at line 212 of file python_test_helper.cpp.
|
static |
Get the standard path to mne-cpp-test-data from the test binary location.
Definition at line 222 of file python_test_helper.cpp.
|
static |
Write an Eigen matrix to a text file with full double precision. The format is one row per line, space-separated values, using %.17e notation — compatible with Python's numpy.loadtxt().
| [in] | filePath | Output file path. |
| [in] | mat | Matrix to write. |
Definition at line 237 of file python_test_helper.cpp.