# HG changeset patch # User RĂ©mi Cardona # Date 1449766246 -3600 # Node ID bf381a894cd3540ff89dbf3495750ee453ea0bdf # Parent 9b1c7f337eb3053877031a06835cee54f0967008 [devtools] Fix fd leak in tests diff -r 9b1c7f337eb3 -r bf381a894cd3 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