Class allowing use of python scripts within a test case.
More...
#include <shamtest/PyScriptHandle.hpp>
|
| | PyScriptHandle () |
| | Construct PyScriptHandle and create an instance of PyScriptHandle::locals.
|
| |
| pybind11::dict & | data () |
| | return reference to the locals
|
| |
| template<class T > |
| void | register_array (std::string name, std::vector< T > &arr) |
| | register an array in a local py variable
|
| |
| template<class T > |
| void | register_value (std::string name, T val) |
| | register a value in a local py variable
|
| |
| template<size_t N> |
| bool | exec (const char(&expr)[N], pybind11::object &&global=pybind11::globals()) |
| | execute the given script
|
| |
|
| pybind11::dict | locals |
| | local python variables
|
| |
Class allowing use of python scripts within a test case.
Example :
std::vector<f64> x = {0, 1, 2, 4, 5};
std::vector<f64> y = {1, 2, 4, 6, 1};
hdnl.data()["y"] = y;
hdnl.exec(R"(
print("startpy")
import matplotlib.pyplot as plt
plt.plot(x,y)
plt.show()
)");
Class allowing use of python scripts within a test case.
pybind11::dict & data()
return reference to the locals
Definition at line 66 of file PyScriptHandle.hpp.
◆ PyScriptHandle()
| PyScriptHandle::PyScriptHandle |
( |
| ) |
|
|
inline |
◆ data()
| pybind11::dict & PyScriptHandle::data |
( |
| ) |
|
|
inline |
◆ exec()
template<size_t N>
| bool PyScriptHandle::exec |
( |
const char(&) |
expr[N], |
|
|
pybind11::object && |
global = pybind11::globals() |
|
) |
| |
|
inline |
execute the given script
- Template Parameters
-
| N | length of the source chars |
- Parameters
-
| expr | the source to be executed |
| global | the global py variable |
- Returns
- true the script executed successfully
-
false the script executed with an error
Definition at line 119 of file PyScriptHandle.hpp.
◆ register_array()
template<class T >
| void PyScriptHandle::register_array |
( |
std::string |
name, |
|
|
std::vector< T > & |
arr |
|
) |
| |
|
inline |
register an array in a local py variable
- Template Parameters
-
| T | type of the array (has to be registered to python) |
- Parameters
-
| name | name of the python variable |
| arr | the array to pass |
Definition at line 93 of file PyScriptHandle.hpp.
◆ register_value()
template<class T >
| void PyScriptHandle::register_value |
( |
std::string |
name, |
|
|
T |
val |
|
) |
| |
|
inline |
register a value in a local py variable
- Template Parameters
-
| T | type of the value (has to be registered to python) |
- Parameters
-
| name | name of the python variable |
| val | the value to pass |
Definition at line 105 of file PyScriptHandle.hpp.
◆ locals
| pybind11::dict PyScriptHandle::locals |
The documentation for this struct was generated from the following file: