Skip to content

Commit

Permalink
Fix and update the ft test.
Browse files Browse the repository at this point in the history
  • Loading branch information
joseph-robertson committed Dec 5, 2024
1 parent b0e5e2a commit 300b10d
Showing 1 changed file with 27 additions and 31 deletions.
58 changes: 27 additions & 31 deletions src/energyplus/Test/PythonPluginSearchPaths_GTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,16 @@
#include "EnergyPlusFixture.hpp"

#include "../ForwardTranslator.hpp"
#include "../ReverseTranslator.hpp"

#include "../../model/Model.hpp"
#include "../../model/PythonPluginSearchPaths.hpp"
#include "../../model/PythonPluginSearchPaths_Impl.hpp"

#include "../../utilities/idf/Workspace.hpp"
#include "../../utilities/idf/IdfObject.hpp"
#include "../../utilities/idf/WorkspaceObject.hpp"
#include "../../utilities/idf/IdfExtensibleGroup.hpp"
#include "../../utilities/idf/WorkspaceExtensibleGroup.hpp"
// E+ FieldEnums
#include <utilities/idd/IddEnums.hxx>
#include <utilities/idd/IddFactory.hxx>
Expand All @@ -52,46 +54,40 @@ TEST_F(EnergyPlusFixture, ForwardTranslator_PythonPluginSearchPaths) {
ForwardTranslator ft;

Model m;
// TODO: Check regular Ctor arguments
PythonPluginSearchPaths pythonPluginSearchPaths(m);
// TODO: Or if a UniqueModelObject (and make sure _Impl is included)
// PythonPluginSearchPaths pythonPluginSearchPaths = m.getUniqueModelObject<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

// TODO: you're responsible for creating all other objects needed so this object actually gets ForwardTranslated
EXPECT_TRUE(pythonPluginSearchPaths.searchPaths().empty());
// No search paths; not translated
{
const Workspace w = ft.translateModel(m);

const Workspace w = ft.translateModel(m);
const auto idfObjs = w.getObjectsByType(IddObjectType::PythonPlugin_SearchPaths);
ASSERT_EQ(1u, idfObjs.size());
const auto idfObjs = w.getObjectsByType(IddObjectType::PythonPlugin_SearchPaths);
ASSERT_EQ(0u, 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());
EXPECT_EQ("No", idfObject.getString(PythonPlugin_SearchPathsFields::AddepinEnvironmentVariabletoSearchPath).get());
}
TEST_F(EnergyPlusFixture, ReverseTranslator_PythonPluginSearchPaths) {

ReverseTranslator rt;

Workspace w(StrictnessLevel::Minimal, IddFileType::EnergyPlus);
{
std::vector<std::string> searchPaths({"/path/to/lib1", "/path/to/lib2"});
EXPECT_TRUE(pythonPluginSearchPaths.setSearchPaths(searchPaths));
EXPECT_EQ(2u, pythonPluginSearchPaths.searchPaths().size());

auto woPPSP = w.addObject(IdfObject(IddObjectType::PythonPlugin_SearchPaths)).get();
const Workspace w = ft.translateModel(m);

woPPSP.setName("My PythonPluginSearchPaths");
EXPECT_TRUE(woPPSP.setString(PythonPlugin_SearchPathsFields::AddCurrentWorkingDirectorytoSearchPath, "No")); // Opposite from IDD default
EXPECT_TRUE(woPPSP.setString(PythonPlugin_SearchPathsFields::AddInputFileDirectorytoSearchPath, "No")); // Opposite from IDD default
EXPECT_TRUE(woPPSP.setString(PythonPlugin_SearchPathsFields::AddepinEnvironmentVariabletoSearchPath, "No")); // Opposite from IDD default
const auto idfObjs = w.getObjectsByType(IddObjectType::PythonPlugin_SearchPaths);
ASSERT_EQ(1u, idfObjs.size());

const Model m = rt.translateWorkspace(w);
const auto modelObjects = m.getConcreteModelObjects<PythonPluginSearchPaths>();
ASSERT_EQ(1u, modelObjects.size());
const auto& idfObject = idfObjs.front();
EXPECT_EQ("No", idfObject.getString(PythonPlugin_SearchPathsFields::AddCurrentWorkingDirectorytoSearchPath).get());
EXPECT_EQ("No", idfObject.getString(PythonPlugin_SearchPathsFields::AddInputFileDirectorytoSearchPath).get());
EXPECT_EQ("No", idfObject.getString(PythonPlugin_SearchPathsFields::AddepinEnvironmentVariabletoSearchPath).get());

const auto& modelObject = modelObjects.front();
EXPECT_FALSE(modelObject.addCurrentWorkingDirectorytoSearchPath());
EXPECT_FALSE(modelObject.addInputFileDirectorytoSearchPath());
EXPECT_FALSE(modelObject.addepinEnvironmentVariabletoSearchPath());
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());
}
}
}

0 comments on commit 300b10d

Please sign in to comment.