v2.0.0
Loading...
Searching...
No Matches
python_test_helper.h
Go to the documentation of this file.
1//=============================================================================================================
34
35#ifndef PYTHON_TEST_HELPER_H
36#define PYTHON_TEST_HELPER_H
37
38//=============================================================================================================
39// INCLUDES
40//=============================================================================================================
41
42#include "utils_global.h"
43#include "python_runner.h"
44
45//=============================================================================================================
46// EIGEN INCLUDES
47//=============================================================================================================
48
49#include <Eigen/Core>
50
51//=============================================================================================================
52// QT INCLUDES
53//=============================================================================================================
54
55#include <QObject>
56#include <QString>
57#include <QStringList>
58#include <QVariantMap>
59
60//=============================================================================================================
61// DEFINE NAMESPACE UTILSLIB
62//=============================================================================================================
63
64namespace UTILSLIB
65{
66
67//=============================================================================================================
97
98//=============================================================================================================
109#define GUARD_PYTHON(available, reason) \
110 do { \
111 if (!(available)) { \
112 if (UTILSLIB::PythonTestHelper::isPythonRequired()) \
113 QFAIL(qPrintable(QString("HARD FAIL (MNE_REQUIRE_PYTHON=true): %1").arg(reason))); \
114 QSKIP(qPrintable(QString("SKIP: %1").arg(reason))); \
115 } \
116 } while (0)
117
124#define GUARD_PYTHON_PACKAGE(helper, packageName) \
125 GUARD_PYTHON((helper).hasPackage(packageName), \
126 QString("Python package '%1' not available").arg(packageName))
127
129{
130public:
131 //=========================================================================================================
136
137 //=========================================================================================================
143 bool isAvailable() const;
144
145 //=========================================================================================================
151 bool isPythonAvailable() const;
152
153 //=========================================================================================================
161 bool hasPackage(const QString& packageName) const;
162
163 //=========================================================================================================
172 PythonRunnerResult eval(const QString& code, int timeoutMs = 30000) const;
173
174 //=========================================================================================================
184 double evalDouble(const QString& code, bool* ok = nullptr, int timeoutMs = 30000) const;
185
186 //=========================================================================================================
197 Eigen::VectorXd evalVector(const QString& code, bool* ok = nullptr, int timeoutMs = 60000) const;
198
199 //=========================================================================================================
210 Eigen::MatrixXd evalMatrix(const QString& code, bool* ok = nullptr, int timeoutMs = 60000) const;
211
212 //=========================================================================================================
222 PythonRunnerResult runScript(const QString& scriptPath,
223 const QStringList& args = {},
224 int timeoutMs = 120000) const;
225
226 //=========================================================================================================
232 static QString testDataPath();
233
234 //=========================================================================================================
243 static bool isPythonRequired();
244
245 //=========================================================================================================
256 static bool writeMatrix(const QString& filePath, const Eigen::MatrixXd& mat);
257
258 //=========================================================================================================
268 static Eigen::MatrixXd readMatrix(const QString& filePath, bool* ok = nullptr);
269
270 //=========================================================================================================
296 Eigen::MatrixXd evalMatrixViaFile(const QString& code,
297 const QString& outputFilePath,
298 bool* ok = nullptr,
299 int timeoutMs = 120000) const;
300
301private:
302 mutable PythonRunner m_runner;
303};
304
305} // namespace UTILSLIB
306
307#endif // PYTHON_TEST_HELPER_H
PythonRunner class declaration — standardized interface for calling Python scripts.
utils library export/import macros.
#define UTILSSHARED_EXPORT
Shared utilities (I/O helpers, spectral analysis, layout management, warp algorithms).
Script execution result container.
Python script launcher with logging and progress support.
Eigen::VectorXd evalVector(const QString &code, bool *ok=nullptr, int timeoutMs=60000) const
static bool writeMatrix(const QString &filePath, const Eigen::MatrixXd &mat)
double evalDouble(const QString &code, bool *ok=nullptr, int timeoutMs=30000) 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
bool hasPackage(const QString &packageName) const
PythonRunnerResult eval(const QString &code, int timeoutMs=30000) const
static Eigen::MatrixXd readMatrix(const QString &filePath, bool *ok=nullptr)
Eigen::MatrixXd evalMatrix(const QString &code, bool *ok=nullptr, int timeoutMs=60000) const