##// END OF EJS Templates
Some refactoring on PB11 wrappers...
Some refactoring on PB11 wrappers Most sciqlop core wrappers are moved into a dedicated python module. We needs to get rid off sqpapp! All current sciqlop modules should either be stateless or act as real singletons they must not need any app to be used. This will ease testing, wrapping and usage. Signed-off-by: Alexis Jeandet <alexis.jeandet@member.fsf.org>

File last commit:

r1341:f18e017310bc
r1341:f18e017310bc
Show More
PyTestAmdaWrapper.cpp
135 lines | 5.0 KiB | text/x-c | CppLexer
/ plugins / amda / tests / PyTestAmdaWrapper.cpp
Initial Pybind11 binding experiment working....
r1339 /*------------------------------------------------------------------------------
-- This file is a part of the SciQLOP Software
-- Copyright (C) 2018, Plasma Physics Laboratory - CNRS
--
-- This program is free software; you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation; either version 2 of the License, or
-- (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program; if not, write to the Free Software
-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-------------------------------------------------------------------------------*/
/*-- Author : Alexis Jeandet
-- Mail : alexis.jeandet@member.fsf.org
----------------------------------------------------------------------------*/
#include <string>
#include <sstream>
#include <memory>
#include <pybind11/pybind11.h>
#include <pybind11/operators.h>
#include <pybind11/embed.h>
Added basic tests around Amda plugin Python wrapper...
r1340 #include <pybind11/numpy.h>
#include <pybind11/chrono.h>
Initial Pybind11 binding experiment working....
r1339
#include <SqpApplication.h>
#include <Variable/VariableController.h>
#include <Time/TimeController.h>
#include <Data/SqpRange.h>
#include <Data/DataSeriesType.h>
#include <Common/DateUtils.h>
#include <Variable/Variable.h>
#include <Data/ScalarSeries.h>
Added basic tests around Amda plugin Python wrapper...
r1340 #include <Data/VectorSeries.h>
Initial Pybind11 binding experiment working....
r1339
#include <AmdaProvider.h>
#include <AmdaResultParser.h>
Some refactoring on PB11 wrappers...
r1341 //#include <QDate>
//#include <QTime>
//#include <QUuid>
//#include <QString>
Initial Pybind11 binding experiment working....
r1339 #include <QFile>
Some refactoring on PB11 wrappers...
r1341 #include <pywrappers_common.h>
#include <CoreWrappers.h>
Added basic tests around Amda plugin Python wrapper...
r1340
Initial Pybind11 binding experiment working....
r1339
Some refactoring on PB11 wrappers...
r1341 using namespace std::chrono;
namespace py = pybind11;
Initial Pybind11 binding experiment working....
r1339
Added basic tests around Amda plugin Python wrapper...
r1340
Initial Pybind11 binding experiment working....
r1339 PYBIND11_MODULE(pytestamda, m){
Some refactoring on PB11 wrappers...
r1341
Added basic tests around Amda plugin Python wrapper...
r1340 int argc = 0;
char ** argv=nullptr;
SqpApplication::setOrganizationName("LPP");
SqpApplication::setOrganizationDomain("lpp.fr");
SqpApplication::setApplicationName("SciQLop");
static SqpApplication app(argc, argv);
Some refactoring on PB11 wrappers...
r1341 auto qtmod = py::module::import("sciqlopqt");
auto sciqlopmod = py::module::import("pysciqlopcore");
Initial Pybind11 binding experiment working....
r1339
Some refactoring on PB11 wrappers...
r1341 m.doc() = "hello";
Initial Pybind11 binding experiment working....
r1339
Added basic tests around Amda plugin Python wrapper...
r1340 py::class_<VariableController>(m, "VariableController")
.def_static("createVariable",[](const QString &name,
std::shared_ptr<IDataProvider> provider){
return sqpApp->variableController().createVariable(name, {{"dataType", "vector"}, {"xml:id", "c1_b"}}, provider);
})
.def_static("hasPendingDownloads",
[](){return sqpApp->variableController().hasPendingDownloads();}
Some refactoring on PB11 wrappers...
r1341 )
.def_static("addSynchronizationGroup",
[](QUuid uuid){sqpApp->variableController().onAddSynchronizationGroupId(uuid);}
)
.def_static("removeSynchronizationGroup",
[](QUuid uuid){sqpApp->variableController().onRemoveSynchronizationGroupId(uuid);}
)
.def_static("synchronizeVar",
[](std::shared_ptr<Variable> variable, QUuid uuid){sqpApp->variableController().onAddSynchronized(variable, uuid);}
)
.def_static("deSynchronizeVar",
[](std::shared_ptr<Variable> variable, QUuid uuid){sqpApp->variableController().desynchronize(variable, uuid);}
)
.def_static("deleteVariable",
[](std::shared_ptr<Variable> variable){
sqpApp->variableController().deleteVariable(variable);}
)
.def_static("update_range",[](std::shared_ptr<Variable> variable, const SqpRange &range, bool synchronise){
sqpApp->variableController().onRequestDataLoading({variable}, range, synchronise);
})
.def_static("wait_for_downloads",[](){
while (sqpApp->variableController().hasPendingDownloads()) {
usleep(100);
}
});
Initial Pybind11 binding experiment working....
r1339
Added basic tests around Amda plugin Python wrapper...
r1340 py::class_<TimeController>(m,"TimeController")
.def_static("setTime", [](SqpRange range){sqpApp->timeController().onTimeToUpdate(range);});
Some refactoring on PB11 wrappers...
r1341
auto amda_provider = std::make_shared<AmdaProvider>();
m.def("amda_provider",[amda_provider](){return amda_provider;}, py::return_value_policy::copy);
Added basic tests around Amda plugin Python wrapper...
r1340
py::class_<AmdaProvider, std::shared_ptr<AmdaProvider>, IDataProvider>(m, "AmdaProvider");
Initial Pybind11 binding experiment working....
r1339
py::class_<AmdaResultParser>(m, "AmdaResultParser")
.def_static("readTxt", AmdaResultParser::readTxt)
.def("readScalarTxt", [](const QString& path){
return std::dynamic_pointer_cast<ScalarSeries>(AmdaResultParser::readTxt(path, DataSeriesType::SCALAR));
}, py::return_value_policy::copy);
}
Added basic tests around Amda plugin Python wrapper...
r1340 int pytestamda_test(const char* testScriptPath )
Initial Pybind11 binding experiment working....
r1339 {
py::scoped_interpreter guard{};
py::globals()["__file__"] = py::str(testScriptPath);
py::eval_file(testScriptPath);
return 0;
}
Some refactoring on PB11 wrappers...
r1341