[i18n test] load_po: fix bug in case of multi-lines msgid and ensure there are no duplicated messages stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Tue, 30 Jul 2013 10:05:58 +0200
branchstable
changeset 9200 1ba5961b19dd
parent 9199 f66e2d331f4b
child 9201 b0f6e8c14e7f
[i18n test] load_po: fix bug in case of multi-lines msgid and ensure there are no duplicated messages
devtools/test/data/cubes/i18ntestcube/views.py
devtools/test/unittest_i18n.py
--- a/devtools/test/unittest_i18n.py	Tue Jul 30 08:23:17 2013 +0200
+++ b/devtools/test/unittest_i18n.py	Tue Jul 30 10:05:58 2013 +0200
@@ -28,30 +28,30 @@
 DATADIR = osp.join(osp.abspath(osp.dirname(__file__)), 'data')
 
 def load_po(fname):
-    msgs = []
-    msgid = None
-    msgctxt = None
+    """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'):
-            msgs.append((msgid, msgctxt))
-            msgid = None
-            msgctxt = None
+            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
 
-        else:
-            if msgctxt is not None:
-                msgctxt += line[1:-1]
-            elif msgid is not None:
-                msgid += line[1:-1]
-    return set(msgs)
 
 class cubePotGeneratorTC(TestCase):
     """test case for i18n pot file generator"""
+
     def setUp(self):
         self._CUBES_PATH = CubicWebNoAppConfiguration.CUBES_PATH[:]
         CubicWebNoAppConfiguration.CUBES_PATH.append(osp.join(DATADIR, 'cubes'))