[devtools] Fix fd leak in tests
authorRémi Cardona <remi.cardona@logilab.fr>
Thu, 10 Dec 2015 17:50:46 +0100
changeset 10964 bf381a894cd3
parent 10963 9b1c7f337eb3
child 10965 b1ba18016151
[devtools] Fix fd leak in tests
devtools/test/unittest_i18n.py
--- a/devtools/test/unittest_i18n.py	Wed Dec 09 14:20:30 2015 +0100
+++ b/devtools/test/unittest_i18n.py	Thu Dec 10 17:50:46 2015 +0100
@@ -32,21 +32,22 @@
     """load a po file and  return a set of encountered (msgid, msgctx)"""
     msgs = set()
     msgid = msgctxt = None
-    for line in open(fname):
-        if line.strip() in ('', '#'):
-            continue
-        if line.startswith('msgstr'):
-            assert not (msgid, msgctxt) in msgs
-            msgs.add( (msgid, msgctxt) )
-            msgid = msgctxt = None
-        elif line.startswith('msgid'):
-            msgid = line.split(' ', 1)[1][1:-1]
-        elif line.startswith('msgctx'):
-            msgctxt = line.split(' ', 1)[1][1: -1]
-        elif msgid is not None:
-            msgid += line[1:-1]
-        elif msgctxt is not None:
-            msgctxt += line[1:-1]
+    with open(fname) as fobj:
+        for line in fobj:
+            if line.strip() in ('', '#'):
+                continue
+            if line.startswith('msgstr'):
+                assert not (msgid, msgctxt) in msgs
+                msgs.add( (msgid, msgctxt) )
+                msgid = msgctxt = None
+            elif line.startswith('msgid'):
+                msgid = line.split(' ', 1)[1][1:-1]
+            elif line.startswith('msgctx'):
+                msgctxt = line.split(' ', 1)[1][1: -1]
+            elif msgid is not None:
+                msgid += line[1:-1]
+            elif msgctxt is not None:
+                msgctxt += line[1:-1]
     return msgs