@@ -181,18 +181,17 @@ def test_as_argv(): # almost identical to above
181
181
182
182
def test_as_config (tmp_path ):
183
183
cfg_file = tmp_path / "config.ini"
184
- with open (cfg_file , "w" ) as f :
185
- f .write (
186
- "\n " .join (
187
- [
188
- "[Section]" ,
189
- "name = 'myname'" ,
190
- "int = 3" ,
191
- "list = [4, 5, 6]" ,
192
- "unknown = 'other'" ,
193
- ]
194
- )
184
+ Path (cfg_file ).write_text (
185
+ "\n " .join (
186
+ [
187
+ "[Section]" ,
188
+ "name = 'myname'" ,
189
+ "int = 3" ,
190
+ "list = [4, 5, 6]" ,
191
+ "unknown = 'other'" ,
192
+ ]
195
193
)
194
+ )
196
195
197
196
# test config as kwarg
198
197
opt1 , unknown1 = paramtest_function (entry_cfg = cfg_file , section = "Section" )
@@ -309,8 +308,7 @@ def test_save_cli_options_cfg(tmp_path):
309
308
save_options_to_config (cfg_file , opt , unknown )
310
309
opt_load , unknown_load = paramtest_function (entry_cfg = cfg_file )
311
310
312
- with open (cfg_file ) as f :
313
- content = f .read ()
311
+ content = Path (cfg_file ).read_text ()
314
312
assert "Unknown" in content
315
313
assert "--other" in content
316
314
@@ -352,16 +350,13 @@ def fun(opt):
352
350
return opt
353
351
354
352
cfg_quotes = tmp_path / "config_quotes.ini"
355
- with open (cfg_quotes , "w" ) as f :
356
- f .write ("[Section]\n name = 'My String with Spaces'" )
353
+ Path (cfg_quotes ).write_text ("[Section]\n name = 'My String with Spaces'" )
357
354
358
355
cfg_doublequotes = tmp_path / "config_doublequotes.ini"
359
- with open (cfg_doublequotes , "w" ) as f :
360
- f .write ('[Section]\n name = "My String with Spaces"' )
356
+ Path (cfg_doublequotes ).write_text ('[Section]\n name = "My String with Spaces"' )
361
357
362
358
cfg_noquotes = tmp_path / "config_noquotes.ini"
363
- with open (cfg_noquotes , "w" ) as f :
364
- f .write ("[Section]\n name = My String with Spaces" )
359
+ Path (cfg_noquotes ).write_text ("[Section]\n name = My String with Spaces" )
365
360
366
361
opt_quotes = fun (entry_cfg = cfg_quotes )
367
362
opt_doublequotes = fun (entry_cfg = cfg_doublequotes )
@@ -520,8 +515,7 @@ def fun(opt):
520
515
assert opt .bos == "myString"
521
516
522
517
cfg_file = tmp_path / "bos.ini"
523
- with open (cfg_file , "w" ) as f :
524
- f .write ("[Section]\n bos = 'myString'" )
518
+ Path (cfg_file ).write_text ("[Section]\n bos = 'myString'" )
525
519
opt = fun (entry_cfg = cfg_file )
526
520
assert opt .bos == "myString"
527
521
@@ -538,8 +532,7 @@ def fun(opt):
538
532
return opt
539
533
540
534
cfg_file = tmp_path / "bos.ini"
541
- with open (cfg_file , "w" ) as f :
542
- f .write ("[Section]\n bos1 = 'myString'\n bos2 = True" )
535
+ Path (cfg_file ).write_text ("[Section]\n bos1 = 'myString'\n bos2 = True" )
543
536
opt = fun (entry_cfg = cfg_file )
544
537
assert opt .bos1 == "myString"
545
538
assert opt .bos2 is True
@@ -578,8 +571,7 @@ def fun(opt):
578
571
return opt
579
572
580
573
cfg_file = tmp_path / "bol.ini"
581
- with open (cfg_file , "w" ) as f :
582
- f .write ("[Section]\n bol1 = 1,2\n bol2 = True" )
574
+ Path (cfg_file ).write_text ("[Section]\n bol1 = 1,2\n bol2 = True" )
583
575
opt = fun (entry_cfg = cfg_file )
584
576
assert opt .bol1 == [1 , 2 ]
585
577
assert opt .bol2 is True
0 commit comments