Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
PyScriptHandle Struct Reference

Class allowing use of python scripts within a test case. More...

#include <shamtest/PyScriptHandle.hpp>

Public Member Functions

 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

Public Attributes

pybind11::dict locals
 local python variables

Detailed Description

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()["x"] = x;
hdnl.data()["y"] = y;
hdnl.exec(R"(
print("startpy")
import matplotlib.pyplot as plt
plt.plot(x,y)
plt.show()
)");
bool exec(const char(&expr)[N], pybind11::object &&global=pybind11::globals())
execute the given script
pybind11::dict & data()
return reference to the locals
PyScriptHandle()
Construct PyScriptHandle and create an instance of PyScriptHandle::locals.

Definition at line 62 of file PyScriptHandle.hpp.

Constructor & Destructor Documentation

◆ PyScriptHandle()

PyScriptHandle::PyScriptHandle ( )
inline

Construct PyScriptHandle and create an instance of PyScriptHandle::locals.

Definition at line 72 of file PyScriptHandle.hpp.

Member Function Documentation

◆ data()

pybind11::dict & PyScriptHandle::data ( )
inline

return reference to the locals

Returns
pybind11::dict& reference to PyScriptHandle::locals

Definition at line 79 of file PyScriptHandle.hpp.

◆ exec()

template<size_t N>
bool PyScriptHandle::exec ( const char(&) expr[N],
pybind11::object && global = pybind11::globals() )
inline

execute the given script

Template Parameters
Nlength of the source chars
Parameters
exprthe source to be executed
globalthe global py variable
Returns
true the script executed successfully
false the script executed with an error

Definition at line 115 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
Ttype of the array (has to be registered to python)
Parameters
namename of the python variable
arrthe array to pass

Definition at line 89 of file PyScriptHandle.hpp.

Here is the call graph for this function:

◆ 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
Ttype of the value (has to be registered to python)
Parameters
namename of the python variable
valthe value to pass

Definition at line 101 of file PyScriptHandle.hpp.

Here is the call graph for this function:

Member Data Documentation

◆ locals

pybind11::dict PyScriptHandle::locals

local python variables

Definition at line 67 of file PyScriptHandle.hpp.


The documentation for this struct was generated from the following file: