Skip to content

Commit 708f991

Browse files
committed
Tests: enclose garbage files within with: statement
1 parent 1a93928 commit 708f991

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

tmuxp/testsuite/test_config.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,8 @@ def test_export_json(self):
6868

6969
json_config_data = configparser.export('json', indent=2)
7070

71-
buf = open(json_config_file, 'w')
72-
buf.write(json_config_data)
73-
buf.close()
71+
with open(json_config_file, 'w') as buf:
72+
buf.write(json_config_data)
7473

7574
new_config = kaptan.Kaptan()
7675
new_config_data = new_config.import_config(json_config_file).get()
@@ -86,9 +85,8 @@ def test_export_yaml(self):
8685
yaml_config_data = configparser.export(
8786
'yaml', indent=2, default_flow_style=False)
8887

89-
buf = open(yaml_config_file, 'w')
90-
buf.write(yaml_config_data)
91-
buf.close()
88+
with open(yaml_config_file, 'w') as buf:
89+
buf.write(yaml_config_data)
9290

9391
new_config = kaptan.Kaptan()
9492
new_config_data = new_config.import_config(yaml_config_file).get()
@@ -98,9 +96,8 @@ def test_scan_config(self):
9896
configs = []
9997

10098
garbage_file = os.path.join(TMUXP_DIR, 'config.psd')
101-
buf = open(garbage_file, 'w')
102-
buf.write('wat')
103-
buf.close()
99+
with open(garbage_file, 'w') as buf:
100+
buf.write('wat')
104101

105102
if os.path.exists(TMUXP_DIR):
106103
for r, d, f in os.walk(TMUXP_DIR):

0 commit comments

Comments
 (0)