devtools/test/unittest_i18n.py
changeset 10964 bf381a894cd3
parent 10464 5ad491852062
equal deleted inserted replaced
10963:9b1c7f337eb3 10964:bf381a894cd3
    30 
    30 
    31 def load_po(fname):
    31 def load_po(fname):
    32     """load a po file and  return a set of encountered (msgid, msgctx)"""
    32     """load a po file and  return a set of encountered (msgid, msgctx)"""
    33     msgs = set()
    33     msgs = set()
    34     msgid = msgctxt = None
    34     msgid = msgctxt = None
    35     for line in open(fname):
    35     with open(fname) as fobj:
    36         if line.strip() in ('', '#'):
    36         for line in fobj:
    37             continue
    37             if line.strip() in ('', '#'):
    38         if line.startswith('msgstr'):
    38                 continue
    39             assert not (msgid, msgctxt) in msgs
    39             if line.startswith('msgstr'):
    40             msgs.add( (msgid, msgctxt) )
    40                 assert not (msgid, msgctxt) in msgs
    41             msgid = msgctxt = None
    41                 msgs.add( (msgid, msgctxt) )
    42         elif line.startswith('msgid'):
    42                 msgid = msgctxt = None
    43             msgid = line.split(' ', 1)[1][1:-1]
    43             elif line.startswith('msgid'):
    44         elif line.startswith('msgctx'):
    44                 msgid = line.split(' ', 1)[1][1:-1]
    45             msgctxt = line.split(' ', 1)[1][1: -1]
    45             elif line.startswith('msgctx'):
    46         elif msgid is not None:
    46                 msgctxt = line.split(' ', 1)[1][1: -1]
    47             msgid += line[1:-1]
    47             elif msgid is not None:
    48         elif msgctxt is not None:
    48                 msgid += line[1:-1]
    49             msgctxt += line[1:-1]
    49             elif msgctxt is not None:
       
    50                 msgctxt += line[1:-1]
    50     return msgs
    51     return msgs
    51 
    52 
    52 
    53 
    53 class cubePotGeneratorTC(TestCase):
    54 class cubePotGeneratorTC(TestCase):
    54     """test case for i18n pot file generator"""
    55     """test case for i18n pot file generator"""