Skip to content

Commit

Permalink
Update ctor to set required fields.
Browse files Browse the repository at this point in the history
  • Loading branch information
joseph-robertson committed Dec 12, 2024
1 parent 8c127f6 commit 233146e
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 4 deletions.
36 changes: 33 additions & 3 deletions src/energyplus/Test/PythonPluginSearchPaths_GTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,14 @@ TEST_F(EnergyPlusFixture, ForwardTranslator_PythonPluginSearchPaths) {
PythonPluginSearchPaths pythonPluginSearchPaths = m.getUniqueModelObject<PythonPluginSearchPaths>();

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);
Expand All @@ -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<std::string> 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());
Expand All @@ -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));

Expand Down
6 changes: 5 additions & 1 deletion src/model/PythonPluginSearchPaths.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,11 @@ namespace model {

/// @cond
PythonPluginSearchPaths::PythonPluginSearchPaths(std::shared_ptr<detail::PythonPluginSearchPaths_Impl> 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

Expand Down

0 comments on commit 233146e

Please sign in to comment.