]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
selftest/subunit: python file modernisation
authorDouglas Bagnall <douglas.bagnall@catalyst.net.nz>
Thu, 19 Nov 2020 03:44:42 +0000 (16:44 +1300)
committerNoel Power <npower@samba.org>
Wed, 9 Dec 2020 16:00:39 +0000 (16:00 +0000)
Python idioms for iterating over a line and closing it have improved,
and we should keep up.

Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Noel Power <npower@samba.org>
selftest/subunithelper.py

index 26158cad33938003347684fa9076cd9d5cb7af08..4fbb5442839552f3a90fdb50bde54b2a1cb75159 100644 (file)
@@ -45,10 +45,7 @@ def parse_results(msg_ops, statistics, fh):
     exitcode = 0
     open_tests = {}
 
-    while fh:
-        l = fh.readline()
-        if l == "":
-            break
+    for l in fh:
         parts = l.split(None, 1)
         if not len(parts) == 2 or not l.startswith(parts[0]):
             msg_ops.output_msg(l)
@@ -80,10 +77,7 @@ def parse_results(msg_ops, statistics, fh):
                 reason = ""
                 # reason may be specified in next lines
                 terminated = False
-                while fh:
-                    l = fh.readline()
-                    if l == "":
-                        break
+                for l in fh:
                     msg_ops.control_msg(l)
                     if l == "]\n":
                         terminated = True
@@ -250,8 +244,7 @@ def read_test_regexes(*names):
             files.append(name)
 
     for filename in files:
-        f = open(filename, 'r')
-        try:
+        with open(filename, 'r') as f:
             for l in f:
                 l = l.strip()
                 if l == "" or l[0] == "#":
@@ -261,8 +254,7 @@ def read_test_regexes(*names):
                     ret[regex.strip()] = reason.strip()
                 else:
                     ret[l] = None
-        finally:
-            f.close()
+
     return ret