GCC Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 84.2% 85 / 0 / 101
Functions: 86.7% 26 / 0 / 30
Branches: 64.7% 55 / 0 / 85

src/model/PythonPluginSearchPaths.cpp
Line Branch Exec Source
1 /***********************************************************************************************************************
2 * OpenStudio(R), Copyright (c) Alliance for Energy Innovation, LLC.
3 * See also https://openstudio.net/license
4 ***********************************************************************************************************************/
5
6 #include "PythonPluginSearchPaths.hpp"
7 #include "PythonPluginSearchPaths_Impl.hpp"
8
9 #include "../utilities/idf/WorkspaceExtensibleGroup.hpp"
10 #include "../utilities/core/Assert.hpp"
11 #include "../utilities/core/Path.hpp"
12
13 #include <utilities/idd/IddEnums.hxx>
14 #include <utilities/idd/OS_PythonPlugin_SearchPaths_FieldEnums.hxx>
15
16 #include <iterator>
17
18 namespace openstudio {
19 namespace model {
20
21 namespace detail {
22
23 4 PythonPluginSearchPaths_Impl::PythonPluginSearchPaths_Impl(const IdfObject& idfObject, Model_Impl* model, bool keepHandle)
24 4 : ModelObject_Impl(idfObject, model, keepHandle) {
25
4/6
✓ Branch 1 taken 4 times.
✓ Branch 4 taken 4 times.
✓ Branch 7 taken 4 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 4 times.
✗ Branch 13 not taken.
4 OS_ASSERT(idfObject.iddObject().type() == PythonPluginSearchPaths::iddObjectType());
26 4 }
27
28 ✗ PythonPluginSearchPaths_Impl::PythonPluginSearchPaths_Impl(const openstudio::detail::WorkspaceObject_Impl& other, Model_Impl* model,
29 ✗ bool keepHandle)
30 ✗ : ModelObject_Impl(other, model, keepHandle) {
31 ✗ OS_ASSERT(other.iddObject().type() == PythonPluginSearchPaths::iddObjectType());
32 ✗ }
33
34 6 PythonPluginSearchPaths_Impl::PythonPluginSearchPaths_Impl(const PythonPluginSearchPaths_Impl& other, Model_Impl* model, bool keepHandle)
35 6 : ModelObject_Impl(other, model, keepHandle) {}
36
37 ✗ const std::vector<std::string>& PythonPluginSearchPaths_Impl::outputVariableNames() const {
38 ✗ static std::vector<std::string> result;
39 ✗ return result;
40 }
41
42 ✗ IddObjectType PythonPluginSearchPaths_Impl::iddObjectType() const {
43 ✗ return PythonPluginSearchPaths::iddObjectType();
44 }
45
46 5 bool PythonPluginSearchPaths_Impl::addCurrentWorkingDirectorytoSearchPath() const {
47 5 return getBooleanFieldValue(OS_PythonPlugin_SearchPathsFields::AddCurrentWorkingDirectorytoSearchPath);
48 }
49
50 5 bool PythonPluginSearchPaths_Impl::addInputFileDirectorytoSearchPath() const {
51 5 return getBooleanFieldValue(OS_PythonPlugin_SearchPathsFields::AddInputFileDirectorytoSearchPath);
52 }
53
54 5 bool PythonPluginSearchPaths_Impl::addepinEnvironmentVariabletoSearchPath() const {
55 5 return getBooleanFieldValue(OS_PythonPlugin_SearchPathsFields::AddepinEnvironmentVariabletoSearchPath);
56 }
57
58 36 std::vector<openstudio::path> PythonPluginSearchPaths_Impl::searchPaths() const {
59 36 std::vector<openstudio::path> result;
60
3/3
✓ Branch 1 taken 36 times.
✓ Branch 8 taken 50 times.
✓ Branch 9 taken 36 times.
86 for (const auto& eg : extensibleGroups()) {
61
1/1
✓ Branch 1 taken 50 times.
50 auto _s = eg.getString(OS_PythonPlugin_SearchPathsExtensibleFields::SearchPath);
62
1/3
✗ Branch 1 not taken.
✓ Branch 2 taken 50 times.
✗ Branch 4 not taken.
50 OS_ASSERT(_s);
63
3/3
✓ Branch 1 taken 50 times.
✓ Branch 4 taken 50 times.
✓ Branch 7 taken 50 times.
50 result.push_back(openstudio::toPath(_s.get()));
64 86 }
65 36 return result;
66 ✗ }
67
68 10 bool PythonPluginSearchPaths_Impl::setAddCurrentWorkingDirectorytoSearchPath(bool addCurrentWorkingDirectorytoSearchPath) {
69 const bool result =
70 10 setBooleanFieldValue(OS_PythonPlugin_SearchPathsFields::AddCurrentWorkingDirectorytoSearchPath, addCurrentWorkingDirectorytoSearchPath);
71
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
10 OS_ASSERT(result);
72 10 return result;
73 }
74
75 10 bool PythonPluginSearchPaths_Impl::setAddInputFileDirectorytoSearchPath(bool addInputFileDirectorytoSearchPath) {
76 const bool result =
77 10 setBooleanFieldValue(OS_PythonPlugin_SearchPathsFields::AddInputFileDirectorytoSearchPath, addInputFileDirectorytoSearchPath);
78
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
10 OS_ASSERT(result);
79 10 return result;
80 }
81
82 10 bool PythonPluginSearchPaths_Impl::setAddepinEnvironmentVariabletoSearchPath(bool addepinEnvironmentVariabletoSearchPath) {
83 const bool result =
84 10 setBooleanFieldValue(OS_PythonPlugin_SearchPathsFields::AddepinEnvironmentVariabletoSearchPath, addepinEnvironmentVariabletoSearchPath);
85
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
10 OS_ASSERT(result);
86 10 return result;
87 }
88
89 13 bool PythonPluginSearchPaths_Impl::addSearchPath(const openstudio::path& searchPath) {
90
1/1
✓ Branch 1 taken 13 times.
13 std::vector<openstudio::path> existingSearchPaths = this->searchPaths();
91
3/3
✓ Branch 4 taken 13 times.
✓ Branch 7 taken 2 times.
✓ Branch 8 taken 11 times.
13 if (std::find(existingSearchPaths.begin(), existingSearchPaths.end(), searchPath) != existingSearchPaths.end()) {
92
7/7
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
✓ Branch 10 taken 2 times.
✓ Branch 13 taken 2 times.
✓ Branch 16 taken 2 times.
✓ Branch 19 taken 2 times.
2 LOG(Info, "Not adding search path '" << searchPath << "' to PythonPlugin:SearchPaths since it is already present");
93 // Return true anyways, it's a success
94 2 return true;
95 }
96
97
3/3
✓ Branch 1 taken 11 times.
✓ Branch 4 taken 11 times.
✓ Branch 7 taken 11 times.
11 auto eg = getObject<ModelObject>().pushExtensibleGroup().cast<WorkspaceExtensibleGroup>();
98
2/2
✓ Branch 1 taken 11 times.
✓ Branch 4 taken 11 times.
11 bool result = eg.setString(OS_PythonPlugin_SearchPathsExtensibleFields::SearchPath, searchPath.generic_string());
99
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 if (!result) {
100 ✗ getObject<ModelObject>().eraseExtensibleGroup(eg.groupIndex());
101 }
102
103 11 return result;
104 13 }
105
106 4 bool PythonPluginSearchPaths_Impl::setSearchPaths(const std::vector<openstudio::path>& searchPaths) {
107 4 bool result = true;
108
109 4 clearSearchPaths();
110
111
2/2
✓ Branch 5 taken 10 times.
✓ Branch 6 taken 4 times.
14 for (const auto& s : searchPaths) {
112
1/1
✓ Branch 1 taken 10 times.
10 bool thisResult = addSearchPath(s);
113
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
10 if (!thisResult) {
114 ✗ LOG(Warn, "Couldn't add search path " << s << " to PythonPlugin:SearchPaths, skipping and continuing.");
115 ✗ result = false;
116 }
117 }
118
119 4 return result;
120 }
121
122 5 void PythonPluginSearchPaths_Impl::clearSearchPaths() {
123
1/1
✓ Branch 1 taken 5 times.
5 clearExtensibleGroups();
124 5 }
125
126 } // namespace detail
127
128 7616 IddObjectType PythonPluginSearchPaths::iddObjectType() {
129
1/1
✓ Branch 1 taken 7616 times.
7616 return {IddObjectType::OS_PythonPlugin_SearchPaths};
130 }
131
132 5 bool PythonPluginSearchPaths::addCurrentWorkingDirectorytoSearchPath() const {
133
1/1
✓ Branch 3 taken 5 times.
5 return getImpl<detail::PythonPluginSearchPaths_Impl>()->addCurrentWorkingDirectorytoSearchPath();
134 }
135
136 5 bool PythonPluginSearchPaths::addInputFileDirectorytoSearchPath() const {
137
1/1
✓ Branch 3 taken 5 times.
5 return getImpl<detail::PythonPluginSearchPaths_Impl>()->addInputFileDirectorytoSearchPath();
138 }
139
140 5 bool PythonPluginSearchPaths::addepinEnvironmentVariabletoSearchPath() const {
141
1/1
✓ Branch 3 taken 5 times.
5 return getImpl<detail::PythonPluginSearchPaths_Impl>()->addepinEnvironmentVariabletoSearchPath();
142 }
143
144 23 std::vector<openstudio::path> PythonPluginSearchPaths::searchPaths() const {
145
1/1
✓ Branch 3 taken 23 times.
23 return getImpl<detail::PythonPluginSearchPaths_Impl>()->searchPaths();
146 }
147
148 10 bool PythonPluginSearchPaths::setAddCurrentWorkingDirectorytoSearchPath(bool addCurrentWorkingDirectorytoSearchPath) {
149
1/1
✓ Branch 3 taken 10 times.
10 return getImpl<detail::PythonPluginSearchPaths_Impl>()->setAddCurrentWorkingDirectorytoSearchPath(addCurrentWorkingDirectorytoSearchPath);
150 }
151
152 10 bool PythonPluginSearchPaths::setAddInputFileDirectorytoSearchPath(bool addInputFileDirectorytoSearchPath) {
153
1/1
✓ Branch 3 taken 10 times.
10 return getImpl<detail::PythonPluginSearchPaths_Impl>()->setAddInputFileDirectorytoSearchPath(addInputFileDirectorytoSearchPath);
154 }
155
156 10 bool PythonPluginSearchPaths::setAddepinEnvironmentVariabletoSearchPath(bool addepinEnvironmentVariabletoSearchPath) {
157
1/1
✓ Branch 3 taken 10 times.
10 return getImpl<detail::PythonPluginSearchPaths_Impl>()->setAddepinEnvironmentVariabletoSearchPath(addepinEnvironmentVariabletoSearchPath);
158 }
159
160 3 bool PythonPluginSearchPaths::addSearchPath(const openstudio::path& searchPath) {
161
1/1
✓ Branch 3 taken 3 times.
3 return getImpl<detail::PythonPluginSearchPaths_Impl>()->addSearchPath(searchPath);
162 }
163
164 ✗ bool PythonPluginSearchPaths::setSearchPaths(const std::vector<openstudio::path>& searchPaths) {
165 ✗ return getImpl<detail::PythonPluginSearchPaths_Impl>()->setSearchPaths(searchPaths);
166 }
167
168 4 bool PythonPluginSearchPaths::setSearchPaths(const std::vector<std::string>& searchPaths) {
169 4 std::vector<openstudio::path> paths;
170
1/1
✓ Branch 2 taken 4 times.
4 paths.reserve(searchPaths.size());
171
2/2
✓ Branch 1 taken 4 times.
✓ Branch 6 taken 4 times.
14 std::transform(searchPaths.cbegin(), searchPaths.cend(), std::back_inserter(paths), [](const std::string& s) { return openstudio::toPath(s); });
172
1/1
✓ Branch 3 taken 4 times.
8 return getImpl<detail::PythonPluginSearchPaths_Impl>()->setSearchPaths(paths);
173 4 }
174
175 1 void PythonPluginSearchPaths::clearSearchPaths() {
176
1/1
✓ Branch 3 taken 1 time.
1 getImpl<detail::PythonPluginSearchPaths_Impl>()->clearSearchPaths();
177 1 }
178
179 /// @cond
180
1/1
✓ Branch 3 taken 9 times.
9 PythonPluginSearchPaths::PythonPluginSearchPaths(std::shared_ptr<detail::PythonPluginSearchPaths_Impl> impl) : ModelObject(std::move(impl)) {}
181 4 PythonPluginSearchPaths::PythonPluginSearchPaths(Model& model) : ModelObject(PythonPluginSearchPaths::iddObjectType(), model) {
182
1/1
✓ Branch 1 taken 4 times.
4 setAddCurrentWorkingDirectorytoSearchPath(true);
183
1/1
✓ Branch 1 taken 4 times.
4 setAddInputFileDirectorytoSearchPath(true);
184
1/1
✓ Branch 1 taken 4 times.
4 setAddepinEnvironmentVariabletoSearchPath(true);
185 4 }
186
187 /// @endcond
188
189 } // namespace model
190 } // namespace openstudio
191