Skip to content
Snippets Groups Projects
Commit b2126110 authored by Wuttke, Joachim's avatar Wuttke, Joachim
Browse files

split into two tests

parent 86c38f21
No related branches found
No related tags found
1 merge request!524improve export-to-Python tests
Pipeline #51620 passed
...@@ -361,14 +361,12 @@ TEST_F(PyEmbedded, EmbeddedMultiLayer) ...@@ -361,14 +361,12 @@ TEST_F(PyEmbedded, EmbeddedMultiLayer)
} }
//! We use one of our standard sample builders to build a sample, then generate Python snippet //! We use one of our standard sample builders to build a sample, then generate Python snippet
//! using our standard ExportToPython machinery. //! using our standard ExportToPython machinery. Ditto for a cloned sample.
//! Given snippet is compiled and executed in embedded interpretor. Resulting multi layer //! Two exported code snippets must be identical.
//! is casted back to C++ object and used again, to generate code snippet.
//! Two code snippets must be identical.
TEST_F(PyEmbedded, ExportToPythonAndBack) TEST_F(PyEmbedded, CloneAndExportToPython)
{ {
std::unique_ptr<MultiLayer> sample1(ExemplarySamples::createCylindersAndPrisms()); std::unique_ptr<MultiLayer> sample1(ExemplarySamples::createMultiLayerWithNCRoughness());
const std::string code1 = Py::Export::sampleCode(*sample1); const std::string code1 = Py::Export::sampleCode(*sample1);
std::cout << "Test ExportToPythonAndBack: code1:\n" << code1 << std::endl; std::cout << "Test ExportToPythonAndBack: code1:\n" << code1 << std::endl;
...@@ -380,17 +378,31 @@ TEST_F(PyEmbedded, ExportToPythonAndBack) ...@@ -380,17 +378,31 @@ TEST_F(PyEmbedded, ExportToPythonAndBack)
else else
std::cout << "Test ExportToPythonAndBack: code2 = code1" << std::endl; std::cout << "Test ExportToPythonAndBack: code2 = code1" << std::endl;
EXPECT_TRUE(code2 == code1); EXPECT_TRUE(code2 == code1);
}
//! We use one of our standard sample builders to build a sample, then generate Python snippet
//! using our standard ExportToPython machinery.
//! Given snippet is compiled and executed in embedded interpretor. Resulting multi layer
//! is casted back to C++ object and used again, to generate code snippet.
//! Two code snippets must be identical.
TEST_F(PyEmbedded, ExportToPythonAndBack)
{
std::unique_ptr<MultiLayer> sample1(ExemplarySamples::createCylindersAndPrisms());
const std::string code1 = Py::Export::sampleCode(*sample1);
std::cout << "Test ExportToPythonAndBack: code1:\n" << code1 << std::endl;
const std::string snippet = const std::string snippet =
"import bornagain as ba\n" + Py::Fmt::printImportedSymbols(code1) + "\n\n" + code1; "import bornagain as ba\n" + Py::Fmt::printImportedSymbols(code1) + "\n\n" + code1;
const auto sample3 = const auto sample2 =
Py::Import::createFromPython(snippet, "get_sample", BABuild::buildLibDir()); Py::Import::createFromPython(snippet, "get_sample", BABuild::buildLibDir());
const std::string code3 = Py::Export::sampleCode(*sample3); const std::string code2 = Py::Export::sampleCode(*sample2);
if (code3 != code1) if (code2 != code1)
std::cout << "Test ExportToPythonAndBack: code3:\n" << code3 << std::endl; std::cout << "Test ExportToPythonAndBack: code2:\n" << code2 << std::endl;
else else
std::cout << "Test ExportToPythonAndBack: code3 = code1" << std::endl; std::cout << "Test ExportToPythonAndBack: code2 = code1" << std::endl;
EXPECT_TRUE(code3 == code1); EXPECT_TRUE(code2 == code1);
} }
//! Retrieves list of functions from the imported script and checks, that there is //! Retrieves list of functions from the imported script and checks, that there is
......
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