From 233146edf716510c354880820c2dc486a5e1e36d Mon Sep 17 00:00:00 2001 From: Joe Robertson Date: Thu, 12 Dec 2024 09:47:39 -0700 Subject: [PATCH] Update ctor to set required fields. --- .../Test/PythonPluginSearchPaths_GTest.cpp | 36 +++++++++++++++++-- src/model/PythonPluginSearchPaths.cpp | 6 +++- 2 files changed, 38 insertions(+), 4 deletions(-) diff --git a/src/energyplus/Test/PythonPluginSearchPaths_GTest.cpp b/src/energyplus/Test/PythonPluginSearchPaths_GTest.cpp index c5c1e2c150..2fd2f666c1 100644 --- a/src/energyplus/Test/PythonPluginSearchPaths_GTest.cpp +++ b/src/energyplus/Test/PythonPluginSearchPaths_GTest.cpp @@ -65,13 +65,14 @@ TEST_F(EnergyPlusFixture, ForwardTranslator_PythonPluginSearchPaths) { PythonPluginSearchPaths pythonPluginSearchPaths = m.getUniqueModelObject(); pythonPluginSearchPaths.setName("My PythonPluginSearchPaths"); - EXPECT_TRUE(pythonPluginSearchPaths.setAddCurrentWorkingDirectorytoSearchPath(false)); // Opposite from IDD default - EXPECT_TRUE(pythonPluginSearchPaths.setAddInputFileDirectorytoSearchPath(false)); // Opposite from IDD default - EXPECT_TRUE(pythonPluginSearchPaths.setAddepinEnvironmentVariabletoSearchPath(false)); // Opposite from IDD default EXPECT_TRUE(pythonPluginSearchPaths.searchPaths().empty()); // No search paths; not translated { + EXPECT_TRUE(pythonPluginSearchPaths.setAddCurrentWorkingDirectorytoSearchPath(false)); // Opposite from IDD default + EXPECT_TRUE(pythonPluginSearchPaths.setAddInputFileDirectorytoSearchPath(false)); // Opposite from IDD default + EXPECT_TRUE(pythonPluginSearchPaths.setAddepinEnvironmentVariabletoSearchPath(false)); // Opposite from IDD default + const Workspace w = ft.translateModel(m); const auto idfObjs = w.getObjectsByType(IddObjectType::PythonPlugin_SearchPaths); @@ -88,6 +89,31 @@ TEST_F(EnergyPlusFixture, ForwardTranslator_PythonPluginSearchPaths) { const auto idfObjs = w.getObjectsByType(IddObjectType::PythonPlugin_SearchPaths); ASSERT_EQ(1u, idfObjs.size()); + const auto& idfObject = idfObjs.front(); + EXPECT_EQ("Yes", idfObject.getString(PythonPlugin_SearchPathsFields::AddCurrentWorkingDirectorytoSearchPath).get()); + EXPECT_EQ("Yes", idfObject.getString(PythonPlugin_SearchPathsFields::AddInputFileDirectorytoSearchPath).get()); + EXPECT_EQ("Yes", idfObject.getString(PythonPlugin_SearchPathsFields::AddepinEnvironmentVariabletoSearchPath).get()); + + ASSERT_EQ(2u, idfObject.extensibleGroups().size()); + for (int i = 0; i < 2; ++i) { + EXPECT_EQ(searchPaths[i], idfObject.extensibleGroups()[i].getString(PythonPlugin_SearchPathsExtensibleFields::SearchPath).get()); + } + } + + { + EXPECT_TRUE(pythonPluginSearchPaths.setAddCurrentWorkingDirectorytoSearchPath(false)); // Opposite from IDD default + EXPECT_TRUE(pythonPluginSearchPaths.setAddInputFileDirectorytoSearchPath(false)); // Opposite from IDD default + EXPECT_TRUE(pythonPluginSearchPaths.setAddepinEnvironmentVariabletoSearchPath(false)); // Opposite from IDD default + + std::vector searchPaths({"/path/to/lib1", "/path/to/lib2"}); + EXPECT_TRUE(pythonPluginSearchPaths.setSearchPaths(searchPaths)); + EXPECT_EQ(2u, pythonPluginSearchPaths.searchPaths().size()); + + const Workspace w = ft.translateModel(m); + + const auto idfObjs = w.getObjectsByType(IddObjectType::PythonPlugin_SearchPaths); + ASSERT_EQ(1u, idfObjs.size()); + const auto& idfObject = idfObjs.front(); EXPECT_EQ("No", idfObject.getString(PythonPlugin_SearchPathsFields::AddCurrentWorkingDirectorytoSearchPath).get()); EXPECT_EQ("No", idfObject.getString(PythonPlugin_SearchPathsFields::AddInputFileDirectorytoSearchPath).get()); @@ -100,6 +126,10 @@ TEST_F(EnergyPlusFixture, ForwardTranslator_PythonPluginSearchPaths) { } { + EXPECT_TRUE(pythonPluginSearchPaths.setAddCurrentWorkingDirectorytoSearchPath(false)); // Opposite from IDD default + EXPECT_TRUE(pythonPluginSearchPaths.setAddInputFileDirectorytoSearchPath(false)); // Opposite from IDD default + EXPECT_TRUE(pythonPluginSearchPaths.setAddepinEnvironmentVariabletoSearchPath(false)); // Opposite from IDD default + openstudio::path p = resourcesPath() / toPath("model/PythonPluginThermochromicWindow.py"); ASSERT_TRUE(exists(p)); diff --git a/src/model/PythonPluginSearchPaths.cpp b/src/model/PythonPluginSearchPaths.cpp index 633c173f3f..6b76ee58dc 100644 --- a/src/model/PythonPluginSearchPaths.cpp +++ b/src/model/PythonPluginSearchPaths.cpp @@ -196,7 +196,11 @@ namespace model { /// @cond PythonPluginSearchPaths::PythonPluginSearchPaths(std::shared_ptr impl) : ParentObject(std::move(impl)) {} - PythonPluginSearchPaths::PythonPluginSearchPaths(Model& model) : ParentObject(PythonPluginSearchPaths::iddObjectType(), model) {} + PythonPluginSearchPaths::PythonPluginSearchPaths(Model& model) : ParentObject(PythonPluginSearchPaths::iddObjectType(), model) { + setAddCurrentWorkingDirectorytoSearchPath(true); + setAddInputFileDirectorytoSearchPath(true); + setAddepinEnvironmentVariabletoSearchPath(true); + } /// @endcond