v2.0.0
Loading...
Searching...
No Matches
python_test_helper.h
Go to the documentation of this file.
1//=============================================================================================================
25
26#ifndef PYTHON_TEST_HELPER_H
27#define PYTHON_TEST_HELPER_H
28
29//=============================================================================================================
30// INCLUDES
31//=============================================================================================================
32
33#include "utils_global.h"
34#include "python_runner.h"
35
36//=============================================================================================================
37// EIGEN INCLUDES
38//=============================================================================================================
39
40#include <Eigen/Core>
41
42//=============================================================================================================
43// QT INCLUDES
44//=============================================================================================================
45
46#include <QObject>
47#include <QString>
48#include <QStringList>
49#include <QVariantMap>
50
51//=============================================================================================================
52// DEFINE NAMESPACE UTILSLIB
53//=============================================================================================================
54
55namespace UTILSLIB
56{
57
58//=============================================================================================================
88
89//=============================================================================================================
100#define GUARD_PYTHON(available, reason) \
101 do { \
102 if (!(available)) { \
103 if (UTILSLIB::PythonTestHelper::isPythonRequired()) \
104 QFAIL(qPrintable(QString("HARD FAIL (MNE_REQUIRE_PYTHON=true): %1").arg(reason))); \
105 QSKIP(qPrintable(QString("SKIP: %1").arg(reason))); \
106 } \
107 } while (0)
108
115#define GUARD_PYTHON_PACKAGE(helper, packageName) \
116 GUARD_PYTHON((helper).hasPackage(packageName), \
117 QString("Python package '%1' not available").arg(packageName))
118
120{
121public:
122 //=========================================================================================================
127
128 //=========================================================================================================
134 bool isAvailable() const;
135
136 //=========================================================================================================
142 bool isPythonAvailable() const;
143
144 //=========================================================================================================
152 bool hasPackage(const QString& packageName) const;
153
154 //=========================================================================================================
163 PythonRunnerResult eval(const QString& code, int timeoutMs = 30000) const;
164
165 //=========================================================================================================
175 double evalDouble(const QString& code, bool* ok = nullptr, int timeoutMs = 30000) const;
176
177 //=========================================================================================================
188 Eigen::VectorXd evalVector(const QString& code, bool* ok = nullptr, int timeoutMs = 60000) const;
189
190 //=========================================================================================================
201 Eigen::MatrixXd evalMatrix(const QString& code, bool* ok = nullptr, int timeoutMs = 60000) const;
202
203 //=========================================================================================================
213 PythonRunnerResult runScript(const QString& scriptPath,
214 const QStringList& args = {},
215 int timeoutMs = 120000) const;
216
217 //=========================================================================================================
223 static QString testDataPath();
224
225 //=========================================================================================================
234 static bool isPythonRequired();
235
236 //=========================================================================================================
247 static bool writeMatrix(const QString& filePath, const Eigen::MatrixXd& mat);
248
249 //=========================================================================================================
259 static Eigen::MatrixXd readMatrix(const QString& filePath, bool* ok = nullptr);
260
261 //=========================================================================================================
287 Eigen::MatrixXd evalMatrixViaFile(const QString& code,
288 const QString& outputFilePath,
289 bool* ok = nullptr,
290 int timeoutMs = 120000) const;
291
292private:
293 mutable PythonRunner m_runner;
294};
295
296} // namespace UTILSLIB
297
298#endif // PYTHON_TEST_HELPER_H
Public umbrella header for UTILSLIB exposing the UTILSSHARED_EXPORT macro and build-info accessors.
#define UTILSSHARED_EXPORT
Embedding-free launcher that runs MNE-Python (or any user) scripts as a child process and streams the...
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