Преглед на файлове

tests: use context manager when opening files in patterns_test

Thomas Waldmann преди 1 месец
родител
ревизия
68590e35f0
променени са 1 файла, в които са добавени 8 реда и са изтрити 4 реда
  1. 8 4
      src/borg/testsuite/patterns_test.py

+ 8 - 4
src/borg/testsuite/patterns_test.py

@@ -412,7 +412,8 @@ def test_exclude_patterns_from_file(tmpdir, lines, expected):
 
     def evaluate(filename):
         patterns = []
-        load_exclude_file(open(filename), patterns)
+        with open(filename) as f:
+            load_exclude_file(f, patterns)
         matcher = PatternMatcher(fallback=True)
         matcher.add_inclexcl(patterns)
         return [path for path in files if matcher.match(path)]
@@ -442,7 +443,8 @@ def test_load_patterns_from_file(tmpdir, lines, expected_roots, expected_numpatt
     def evaluate(filename):
         roots = []
         inclexclpatterns = []
-        load_pattern_file(open(filename), roots, inclexclpatterns)
+        with open(filename) as f:
+            load_pattern_file(f, roots, inclexclpatterns)
         return roots, len(inclexclpatterns)
 
     patternfile = tmpdir.join("patterns.txt")
@@ -492,7 +494,8 @@ def test_load_invalid_patterns_from_file(tmpdir, lines):
     with pytest.raises(argparse.ArgumentTypeError):
         roots = []
         inclexclpatterns = []
-        load_pattern_file(open(filename), roots, inclexclpatterns)
+        with open(filename) as f:
+            load_pattern_file(f, roots, inclexclpatterns)
 
 
 @pytest.mark.parametrize(
@@ -542,7 +545,8 @@ def test_inclexcl_patterns_from_file(tmpdir, lines, expected):
         matcher = PatternMatcher(fallback=True)
         roots = []
         inclexclpatterns = []
-        load_pattern_file(open(filename), roots, inclexclpatterns)
+        with open(filename) as f:
+            load_pattern_file(f, roots, inclexclpatterns)
         matcher.add_inclexcl(inclexclpatterns)
         return [path for path in files if matcher.match(path)]