Skip to content
Snippets Groups Projects
Commit a1cfe50c authored by AlQuemist's avatar AlQuemist
Browse files

Add Unit.PyBinding.Embedded.PyInterpreterNumpyTest

parent a3d2b5d3
No related branches found
No related tags found
1 merge request!2274PyCore tests; rm old Python API
......@@ -11,15 +11,12 @@
//
// ************************************************************************************************
//#include "BABuild.h"
#include "PyCore/Embed/PyInterpreter.h"
#include "PyCore/Embed/PyObjectPtr.h"
#include "PyCore/Embed/WithNumpy.h"
#include "PyCore/Sample/ImportMultiLayer.h"
#include "Tests/GTestWrapper/google_test.h"
#include <vector>
#include <string>
#include <vector>
//! Importing numpy and accessing its version string.
......@@ -29,18 +26,35 @@ TEST(Embedded, PyInterpreterTest)
PyInterpreter::initialize();
EXPECT_TRUE(PyInterpreter::isInitialized());
PyInterpreter::Numpy::initialize();
EXPECT_TRUE(PyInterpreter::Numpy::isInitialized());
// add Python path
PyInterpreter::addPythonPath("/Some/Extra/Python/Path/");
EXPECT_FALSE(PyInterpreter::checkError());
// import Numpy
PyObjectPtr numpy_module = PyInterpreter::import("numpy");
EXPECT_TRUE(numpy_module.valid());
// get runtime info
std::string runtime_info = PyInterpreter::runtimeInfo();
std::cout << "Python runtime info:\n" << runtime_info << std::endl;
// set Python path
PyInterpreter::setPythonPath("/Some/Extra/Python/Path/");
}
TEST(Embedded, PyInterpreterNumpyTest)
{
// initialize Python interpreter
PyInterpreter::initialize();
EXPECT_TRUE(PyInterpreter::isInitialized());
PyInterpreter::Numpy::initialize();
EXPECT_TRUE(PyInterpreter::Numpy::isInitialized());
// import Numpy
PyObjectPtr numpy_module = PyInterpreter::import("numpy");
EXPECT_TRUE(numpy_module.valid());
// initialize Numpy
PyInterpreter::Numpy::initialize();
EXPECT_TRUE(PyInterpreter::Numpy::isInitialized());
......@@ -51,7 +65,8 @@ TEST(Embedded, PyInterpreterTest)
for (int ii = 0; ii < a_size; ++ii)
c_array[ii] = ii + 1;
PyObjectPtr np_array1d = PyInterpreter::Numpy::createArray1DfromC(c_array, static_cast<PyInterpreter::Numpy::np_size_t>(a_size));
PyObjectPtr np_array1d = PyInterpreter::Numpy::createArray1DfromC(
c_array, static_cast<PyInterpreter::Numpy::np_size_t>(a_size));
EXPECT_TRUE(np_array1d.valid());
PyInterpreter::Numpy::np_size_t dims[2] = {n_rows, n_cols};
......@@ -68,7 +83,4 @@ TEST(Embedded, PyInterpreterTest)
std::vector<std::size_t> dimensions{1, 2, 3};
PyObjectPtr np_arrayNd = PyInterpreter::Numpy::arrayND(dimensions);
EXPECT_TRUE(np_arrayNd.valid());
// set Python path
PyInterpreter::setPythonPath("/Some/Extra/Python/Path/");
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment