@@ -106,31 +106,37 @@ def test_views(tmp_path, module_sys, module_file, container_tech, remote):
106
106
os .path .join (client .settings .module_base , "ghcr.io" , "autamus" )
107
107
)
108
108
109
- # Try adding system modules
110
- assert not view ._config ["view" ]["system_modules" ]
109
+ # Before adding any attributes, this file should not exist
111
110
view_module = os .path .join (view .path , ".view_module" )
112
111
assert not os .path .exists (view_module )
113
- view_handler .add_variable (view_name , "system_modules" , "openmpi" )
114
- assert os .path .exists (view_module )
115
112
116
- # Make sure we have openmpi in the content
117
- content = utils .read_file (view_module )
118
- assert "openmpi" in content
113
+ # Try adding valid attributes
114
+ for attribute , check_content in [
115
+ ["system_modules" , "module" ],
116
+ ["depends_on" , "depends" ],
117
+ ]:
118
+ assert not view ._config ["view" ][attribute ]
119
+ view_handler .add_variable (view_name , attribute , "openmpi" )
120
+ assert os .path .exists (view_module )
119
121
120
- # Reload the view config file
121
- view . reload ( )
122
- assert "openmpi" in view . _config [ "view" ][ "system_modules" ]
122
+ # Make sure we have openmpi in the content
123
+ content = utils . read_file ( view_module )
124
+ assert "openmpi" in content and check_content in content
123
125
124
- # We can't add unknown variables
125
- with pytest . raises ( SystemExit ):
126
- view_handler . add_variable ( view_name , "system-modules" , [ 1 , 2 , 3 ])
126
+ # Reload the view config file
127
+ view . reload ()
128
+ assert "openmpi" in view . _config [ "view" ][ attribute ]
127
129
128
- # Try removing now
129
- view_handler .remove_variable (view_name , "system_modules" , "openmpi" )
130
- view .reload ()
131
- assert not view ._config ["view" ]["system_modules" ]
132
- content = utils .read_file (view_module )
133
- assert "openmpi" not in content
130
+ # We can't add unknown variables
131
+ with pytest .raises (SystemExit ):
132
+ view_handler .add_variable (view_name , attribute .replace ("_" , "-" ), [1 , 2 , 3 ])
133
+
134
+ # Try removing now
135
+ view_handler .remove_variable (view_name , attribute , "openmpi" )
136
+ view .reload ()
137
+ assert not view ._config ["view" ][attribute ]
138
+ content = utils .read_file (view_module )
139
+ assert "openmpi" not in content and check_content not in content
134
140
135
141
# Ensure we can uninstall
136
142
view_handler .delete (view_name , force = True )
@@ -141,3 +147,75 @@ def test_views(tmp_path, module_sys, module_file, container_tech, remote):
141
147
view_client .create_from_file (
142
148
view_name , views_config , settings_file = client .settings .settings_file , force = True
143
149
)
150
+
151
+
152
+ @pytest .mark .parametrize (
153
+ "module_sys,module_file,container_tech,remote" ,
154
+ [
155
+ ("lmod" , "module.lua" , "singularity" , True ),
156
+ ("lmod" , "module.lua" , "podman" , True ),
157
+ ("tcl" , "module.tcl" , "singularity" , True ),
158
+ ("tcl" , "module.tcl" , "podman" , True ),
159
+ ("lmod" , "module.lua" , "singularity" , False ),
160
+ ("lmod" , "module.lua" , "podman" , False ),
161
+ ("tcl" , "module.tcl" , "singularity" , False ),
162
+ ("tcl" , "module.tcl" , "podman" , False ),
163
+ ],
164
+ )
165
+ def test_view_components (tmp_path , module_sys , module_file , container_tech , remote ):
166
+ """
167
+ Test view components
168
+ """
169
+ client = init_client (str (tmp_path ), module_sys , container_tech , remote = remote )
170
+
171
+ # Create the view handler based on the client settings file
172
+ view_handler = views .ViewsHandler (
173
+ settings_file = client .settings .settings_file , module_sys = module_sys
174
+ )
175
+
176
+ # A view name
177
+ view_name = "mpi"
178
+ assert view_name not in client .views
179
+
180
+ # Create the view!
181
+ view_handler .create (view_name )
182
+ client .detect_views ()
183
+ assert view_name in client .views
184
+
185
+ # Before adding any attributes, this file should not exist
186
+ view = client .views [view_name ]
187
+ view_module = os .path .join (view .path , ".view_module" )
188
+ assert not os .path .exists (view_module )
189
+
190
+ # Try adding valid attributes
191
+ for attribute , check_content in [
192
+ ["system_modules" , "module" ],
193
+ ["depends_on" , "depends" ],
194
+ ]:
195
+ assert not view ._config ["view" ][attribute ]
196
+ view_handler .add_variable (view_name , attribute , "openmpi" )
197
+ assert os .path .exists (view_module )
198
+
199
+ # Make sure we have openmpi in the content
200
+ content = utils .read_file (view_module )
201
+ print (content )
202
+ assert "openmpi" in content and check_content in content
203
+
204
+ # Reload the view config file
205
+ view .reload ()
206
+ assert "openmpi" in view ._config ["view" ][attribute ]
207
+
208
+ # We can't add unknown variables
209
+ with pytest .raises (SystemExit ):
210
+ view_handler .add_variable (view_name , attribute .replace ("_" , "-" ), [1 , 2 , 3 ])
211
+
212
+ # Try removing now
213
+ view_handler .remove_variable (view_name , attribute , "openmpi" )
214
+ view .reload ()
215
+ assert not view ._config ["view" ][attribute ]
216
+ content = utils .read_file (view_module )
217
+ assert "openmpi" not in content and check_content not in content
218
+
219
+ # Ensure we can uninstall
220
+ view_handler .delete (view_name , force = True )
221
+ assert not os .path .exists (view .path )
0 commit comments