@@ -110,13 +110,14 @@ def test_yaml_param_settings(param):
110110 importlib .reload (_config )
111111
112112 option , value = param
113- with tempfile .NamedTemporaryFile (buffering = 0 , delete_on_close = False ) as tmp :
113+ with tempfile .NamedTemporaryFile (buffering = 0 , delete = False ) as tmp :
114114 tmp .write (f"---\n { param_locs [option ]} :\n { option } : { value } \n " .encode ("utf-8" ))
115115 tmp .close ()
116116 garak .cli .main (
117117 ["--config" , tmp .name , "--list_config" ]
118118 ) # add list_config as the action so we don't actually run
119119 subconfig = getattr (_config , param_locs [option ])
120+ os .remove (tmp .name )
120121 assert getattr (subconfig , option ) == value
121122
122123
@@ -174,20 +175,21 @@ def test_cli_overrides_run_yaml():
174175
175176 orig_seed = 10101
176177 override_seed = 37176
177- with tempfile .NamedTemporaryFile (buffering = 0 , delete_on_close = False ) as tmp :
178+ with tempfile .NamedTemporaryFile (buffering = 0 , delete = False ) as tmp :
178179 tmp .write (f"---\n run:\n seed: { orig_seed } \n " .encode ("utf-8" ))
179180 tmp .close ()
180181 garak .cli .main (
181182 ["--config" , tmp .name , "-s" , f"{ override_seed } " , "--list_config" ]
182183 ) # add list_config as the action so we don't actually run
184+ os .remove (tmp .name )
183185 assert _config .run .seed == override_seed
184186
185187
186188# test probe_options YAML
187189def test_probe_options_yaml (capsys ):
188190 importlib .reload (_config )
189191
190- with tempfile .NamedTemporaryFile (buffering = 0 , delete_on_close = False ) as tmp :
192+ with tempfile .NamedTemporaryFile (buffering = 0 , delete = False ) as tmp :
191193 tmp .write (
192194 """
193195---
@@ -204,14 +206,15 @@ def test_probe_options_yaml(capsys):
204206 garak .cli .main (
205207 ["--config" , tmp .name , "--list_config" ]
206208 ) # add list_config as the action so we don't actually run
209+ os .remove (tmp .name )
207210 assert _config .plugins .probes ["test.Blank" ]["gen_x" ] == 37176
208211
209212
210213# test generator_options YAML
211214def test_generator_options_yaml (capsys ):
212215 importlib .reload (_config )
213216
214- with tempfile .NamedTemporaryFile (buffering = 0 , delete_on_close = False ) as tmp :
217+ with tempfile .NamedTemporaryFile (buffering = 0 , delete = False ) as tmp :
215218 tmp .write (
216219 "---\n plugins:\n model_type: test.Blank\n probe_spec: test.Blank\n generators:\n test.Blank:\n gen_x: 37176\n " .encode (
217220 "utf-8"
@@ -221,21 +224,23 @@ def test_generator_options_yaml(capsys):
221224 garak .cli .main (
222225 ["--config" , tmp .name , "--list_config" ]
223226 ) # add list_config as the action so we don't actually run
227+ os .remove (tmp .name )
224228 assert _config .plugins .generators ["test.Blank" ]["gen_x" ] == 37176
225229
226230
227231# can a run be launched from a run YAML?
228232def test_run_from_yaml (capsys ):
229233 importlib .reload (_config )
230234
231- with tempfile .NamedTemporaryFile (buffering = 0 , delete_on_close = False ) as tmp :
235+ with tempfile .NamedTemporaryFile (buffering = 0 , delete = False ) as tmp :
232236 tmp .write (
233237 "---\n run:\n generations: 10\n \n plugins:\n model_type: test.Blank\n probe_spec: test.Blank\n " .encode (
234238 "utf-8"
235239 )
236240 )
237241 tmp .close ()
238242 garak .cli .main (["--config" , tmp .name ])
243+ os .remove (tmp .name )
239244 result = capsys .readouterr ()
240245 output = result .out
241246 all_output = ""
@@ -256,13 +261,14 @@ def test_cli_generator_options_file():
256261 importlib .reload (_config )
257262
258263 # write an options file
259- with tempfile .NamedTemporaryFile (mode = "w+" , delete_on_close = False ) as tmp :
264+ with tempfile .NamedTemporaryFile (mode = "w+" , delete = False ) as tmp :
260265 json .dump ({"test.Blank" : {"this_is_a" : "generator" }}, tmp )
261266 tmp .close ()
262267 # invoke cli
263268 garak .cli .main (
264269 ["--generator_option_file" , tmp .name , "--list_config" ]
265270 ) # add list_config as the action so we don't actually run
271+ os .remove (tmp .name )
266272
267273 # check it was loaded
268274 assert _config .plugins .generators ["test.Blank" ] == {"this_is_a" : "generator" }
@@ -273,13 +279,14 @@ def test_cli_probe_options_file():
273279 importlib .reload (_config )
274280
275281 # write an options file
276- with tempfile .NamedTemporaryFile (mode = "w+" , delete_on_close = False ) as tmp :
282+ with tempfile .NamedTemporaryFile (mode = "w+" , delete = False ) as tmp :
277283 json .dump ({"test.Blank" : {"probes_in_this_config" : 1 }}, tmp )
278284 tmp .close ()
279285 # invoke cli
280286 garak .cli .main (
281287 ["--probe_option_file" , tmp .name , "--list_config" ]
282288 ) # add list_config as the action so we don't actually run
289+ os .remove (tmp .name )
283290
284291 # check it was loaded
285292 assert _config .plugins .probes ["test.Blank" ] == {"probes_in_this_config" : 1 }
@@ -290,14 +297,10 @@ def test_cli_probe_options_overrides_yaml_probe_options():
290297 importlib .reload (_config )
291298
292299 # write an options file
293- with tempfile .NamedTemporaryFile (
294- mode = "w+" , delete_on_close = False
295- ) as probe_json_file :
300+ with tempfile .NamedTemporaryFile (mode = "w+" , delete = False ) as probe_json_file :
296301 json .dump ({"test.Blank" : {"goal" : "taken from CLI JSON" }}, probe_json_file )
297302 probe_json_file .close ()
298- with tempfile .NamedTemporaryFile (
299- buffering = 0 , delete_on_close = False
300- ) as probe_yaml_file :
303+ with tempfile .NamedTemporaryFile (buffering = 0 , delete = False ) as probe_yaml_file :
301304 probe_yaml_file .write (
302305 """
303306---
@@ -320,6 +323,8 @@ def test_cli_probe_options_overrides_yaml_probe_options():
320323 "--list_config" ,
321324 ]
322325 ) # add list_config as the action so we don't actually run
326+ os .remove (probe_json_file .name )
327+ os .remove (probe_yaml_file .name )
323328 # check it was loaded
324329 assert _config .plugins .probes ["test.Blank" ]["goal" ] == "taken from CLI JSON"
325330
@@ -329,9 +334,7 @@ def test_cli_generator_options_overrides_yaml_probe_options():
329334 importlib .reload (_config )
330335
331336 cli_generations_count = 9001
332- with tempfile .NamedTemporaryFile (
333- buffering = 0 , delete_on_close = False
334- ) as generator_yaml_file :
337+ with tempfile .NamedTemporaryFile (buffering = 0 , delete = False ) as generator_yaml_file :
335338 generator_yaml_file .write (
336339 """
337340---
@@ -351,6 +354,7 @@ def test_cli_generator_options_overrides_yaml_probe_options():
351354 ] # add list_config as the action so we don't actually run
352355 print (args )
353356 garak .cli .main (args )
357+ os .remove (generator_yaml_file .name )
354358 # check it was loaded
355359 assert _config .run .generations == cli_generations_count
356360
@@ -361,14 +365,15 @@ def test_blank_probe_instance_loads_yaml_config():
361365
362366 probe_name = "test.Blank"
363367 revised_goal = "TEST GOAL make the model forget what to output"
364- with tempfile .NamedTemporaryFile (buffering = 0 , delete_on_close = False ) as tmp :
368+ with tempfile .NamedTemporaryFile (buffering = 0 , delete = False ) as tmp :
365369 tmp .write (
366370 f"---\n plugins:\n probes:\n { probe_name } :\n goal: { revised_goal } \n " .encode (
367371 "utf-8"
368372 )
369373 )
370374 tmp .close ()
371375 garak .cli .main (["--config" , tmp .name , "-p" , probe_name ])
376+ os .remove (tmp .name )
372377 probe = garak ._plugins .load_plugin (f"probes.{ probe_name } " )
373378 assert probe .goal == revised_goal
374379
@@ -396,7 +401,7 @@ def test_blank_generator_instance_loads_yaml_config():
396401
397402 generator_name = "test.Blank"
398403 revised_temp = 0.9001
399- with tempfile .NamedTemporaryFile (buffering = 0 , delete_on_close = False ) as tmp :
404+ with tempfile .NamedTemporaryFile (buffering = 0 , delete = False ) as tmp :
400405 tmp .write (
401406 f"---\n plugins:\n generators:\n { generator_name } :\n temperature: { revised_temp } \n " .encode (
402407 "utf-8"
@@ -406,6 +411,7 @@ def test_blank_generator_instance_loads_yaml_config():
406411 garak .cli .main (
407412 ["--config" , tmp .name , "--model_type" , generator_name , "--probes" , "none" ]
408413 )
414+ os .remove (tmp .name )
409415 gen = garak ._plugins .load_plugin (f"generators.{ generator_name } " )
410416 assert gen .temperature == revised_temp
411417
0 commit comments