Skip to content

Commit ea6450b

Browse files
tests: use context manager when opening files in patterns_test
1 parent 5b92b86 commit ea6450b

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/borg/testsuite/patterns.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,8 @@ def test_exclude_patterns_from_file(tmpdir, lines, expected):
275275

276276
def evaluate(filename):
277277
patterns = []
278-
load_exclude_file(open(filename), patterns)
278+
with open(filename) as fh:
279+
load_exclude_file(fh, patterns)
279280
matcher = PatternMatcher(fallback=True)
280281
matcher.add_inclexcl(patterns)
281282
return [path for path in files if matcher.match(path)]
@@ -306,7 +307,8 @@ def test_load_patterns_from_file(tmpdir, lines, expected_roots, expected_numpatt
306307
def evaluate(filename):
307308
roots = []
308309
inclexclpatterns = []
309-
load_pattern_file(open(filename), roots, inclexclpatterns)
310+
with open(filename) as fh:
311+
load_pattern_file(fh, roots, inclexclpatterns)
310312
return roots, len(inclexclpatterns)
311313
patternfile = tmpdir.join("patterns.txt")
312314

@@ -356,7 +358,8 @@ def test_load_invalid_patterns_from_file(tmpdir, lines):
356358
with pytest.raises(argparse.ArgumentTypeError):
357359
roots = []
358360
inclexclpatterns = []
359-
load_pattern_file(open(filename), roots, inclexclpatterns)
361+
with open(filename) as fh:
362+
load_pattern_file(fh, roots, inclexclpatterns)
360363

361364

362365
@pytest.mark.parametrize("lines, expected", [
@@ -400,7 +403,8 @@ def evaluate(filename):
400403
matcher = PatternMatcher(fallback=True)
401404
roots = []
402405
inclexclpatterns = []
403-
load_pattern_file(open(filename), roots, inclexclpatterns)
406+
with open(filename) as fh:
407+
load_pattern_file(fh, roots, inclexclpatterns)
404408
matcher.add_inclexcl(inclexclpatterns)
405409
return [path for path in files if matcher.match(path)]
406410

0 commit comments

Comments
 (0)