diff --git a/Tests/Functional/PyEmbedded/Tests.cpp b/Tests/Functional/PyEmbedded/Tests.cpp index d26c516144d4b8846996b8b406f65475617bc78a..f6a7d6bf7b6782172da2372af4ce90aae3c55bbc 100644 --- a/Tests/Functional/PyEmbedded/Tests.cpp +++ b/Tests/Functional/PyEmbedded/Tests.cpp @@ -361,14 +361,12 @@ TEST_F(PyEmbedded, EmbeddedMultiLayer) } //! 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. +//! using our standard ExportToPython machinery. Ditto for a cloned sample. +//! Two exported 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); std::cout << "Test ExportToPythonAndBack: code1:\n" << code1 << std::endl; @@ -380,17 +378,31 @@ TEST_F(PyEmbedded, ExportToPythonAndBack) else std::cout << "Test ExportToPythonAndBack: code2 = code1" << std::endl; 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 = "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()); - const std::string code3 = Py::Export::sampleCode(*sample3); - if (code3 != code1) - std::cout << "Test ExportToPythonAndBack: code3:\n" << code3 << std::endl; + const std::string code2 = Py::Export::sampleCode(*sample2); + if (code2 != code1) + std::cout << "Test ExportToPythonAndBack: code2:\n" << code2 << std::endl; else - std::cout << "Test ExportToPythonAndBack: code3 = code1" << std::endl; - EXPECT_TRUE(code3 == code1); + std::cout << "Test ExportToPythonAndBack: code2 = code1" << std::endl; + EXPECT_TRUE(code2 == code1); } //! Retrieves list of functions from the imported script and checks, that there is