Skip to content

Commit 765e18d

Browse files
committed
Tidy: Ensure output is closed, minor cleanup
1 parent 4637332 commit 765e18d

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/robot/tidy.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -150,21 +150,23 @@ def file(self, path, outpath=None):
150150
151151
Use :func:`inplace` to tidy files in-place.
152152
"""
153-
with self._get_writer(outpath) as writer:
153+
with self._get_output(outpath) as writer:
154154
self._tidy(get_model(path), writer)
155155
if not outpath:
156156
return writer.getvalue().replace('\r\n', '\n')
157157

158-
def _get_writer(self, outpath):
159-
return file_writer(outpath, newline='', usage='Tidy output')
158+
def _get_output(self, path):
159+
return file_writer(path, newline='', usage='Tidy output')
160160

161161
def inplace(self, *paths):
162162
"""Tidy file(s) in-place.
163163
164164
:param paths: Paths of the files to to process.
165165
"""
166166
for path in paths:
167-
self._tidy(get_model(path), output=self._get_writer(path))
167+
model = get_model(path)
168+
with self._get_output(path) as output:
169+
self._tidy(model, output)
168170

169171
def directory(self, path):
170172
"""Tidy a directory.
@@ -176,7 +178,7 @@ def directory(self, path):
176178
data = SuiteStructureBuilder().build([path])
177179
data.visit(self)
178180

179-
def _tidy(self, model, output=None):
181+
def _tidy(self, model, output):
180182
Cleaner().visit(model)
181183
NewlineCleaner(self.line_separator,
182184
self.short_test_name_length).visit(model)

0 commit comments

Comments
 (0)