@@ -108,36 +108,10 @@ def test_views(tmp_path, module_sys, module_file, container_tech, remote):
108
108
)
109
109
110
110
# Before adding any attributes, this file should not exist
111
- view_module = os .path .join (view .path , ".view_module" )
112
- assert not os .path .exists (view_module )
111
+ assert not os .path .exists (view .module_path )
113
112
114
- # Try adding valid attributes
115
- for attribute , check_content in [
116
- ["system_modules" , "module" ],
117
- ["depends_on" , "depends" ],
118
- ]:
119
- assert not view ._config ["view" ][attribute ]
120
- view_handler .add_variable (view_name , attribute , "openmpi" )
121
- assert os .path .exists (view_module )
122
-
123
- # Make sure we have openmpi in the content
124
- content = utils .read_file (view_module )
125
- assert "openmpi" in content and check_content in content
126
-
127
- # Reload the view config file
128
- view .reload ()
129
- assert "openmpi" in view ._config ["view" ][attribute ]
130
-
131
- # We can't add unknown variables
132
- with pytest .raises (SystemExit ):
133
- view_handler .add_variable (view_name , attribute .replace ("_" , "-" ), [1 , 2 , 3 ])
134
-
135
- # Try removing now
136
- view_handler .remove_variable (view_name , attribute , "openmpi" )
137
- view .reload ()
138
- assert not view ._config ["view" ][attribute ]
139
- content = utils .read_file (view_module )
140
- assert "openmpi" not in content and check_content not in content
113
+ # Shared function to check view and handler
114
+ check_view (view , view_handler )
141
115
142
116
# Ensure we can uninstall
143
117
view_handler .delete (view_name , force = True )
@@ -185,38 +159,47 @@ def test_view_components(tmp_path, module_sys, module_file, container_tech, remo
185
159
186
160
# Before adding any attributes, this file should not exist
187
161
view = client .views [view_name ]
188
- view_module = os .path .join (view .path , ".view_module" )
189
- assert not os .path .exists (view_module )
162
+ assert not os .path .exists (view .module_path )
163
+
164
+ check_view (view , view_handler )
165
+
166
+ # Ensure we can uninstall
167
+ view_handler .delete (view_name , force = True )
168
+ assert not os .path .exists (view .path )
190
169
170
+
171
+ def check_view (view , view_handler ):
172
+ """
173
+ Shared function for checking content of view.
174
+ """
191
175
# Try adding valid attributes
192
176
for attribute , check_content in [
193
- ["system_modules" , "module" ],
177
+ ["system_modules" , None ],
194
178
["depends_on" , "depends" ],
195
179
]:
196
180
assert not view ._config ["view" ][attribute ]
197
- view_handler .add_variable (view_name , attribute , "openmpi" )
198
- assert os .path .exists (view_module )
181
+ view_handler .add_variable (view . name , attribute , "openmpi" )
182
+ assert os .path .exists (view . module_path )
199
183
200
184
# Make sure we have openmpi in the content
201
- content = utils .read_file (view_module )
202
- print (content )
203
- assert "openmpi" in content and check_content in content
185
+ content = utils .read_file (view .module_path )
186
+ assert "openmpi" in content
187
+ if check_content :
188
+ assert check_content in content
204
189
205
190
# Reload the view config file
206
191
view .reload ()
207
192
assert "openmpi" in view ._config ["view" ][attribute ]
208
193
209
194
# We can't add unknown variables
210
195
with pytest .raises (SystemExit ):
211
- view_handler .add_variable (view_name , attribute .replace ("_" , "-" ), [1 , 2 , 3 ])
196
+ view_handler .add_variable (view . name , attribute .replace ("_" , "-" ), [1 , 2 , 3 ])
212
197
213
198
# Try removing now
214
- view_handler .remove_variable (view_name , attribute , "openmpi" )
199
+ view_handler .remove_variable (view . name , attribute , "openmpi" )
215
200
view .reload ()
216
201
assert not view ._config ["view" ][attribute ]
217
- content = utils .read_file (view_module )
218
- assert "openmpi" not in content and check_content not in content
219
-
220
- # Ensure we can uninstall
221
- view_handler .delete (view_name , force = True )
222
- assert not os .path .exists (view .path )
202
+ content = utils .read_file (view .module_path )
203
+ assert "openmpi" not in content
204
+ if check_content :
205
+ assert check_content not in content
0 commit comments