Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(53)

Issue 64: pot2po should support previous messages

Unified Diff

File: translate/convert/test_pot2po.py
Patch Set: Created 1 year, 4 months ago
Jump to:
View side by-side-diff with in line comments
« translate/convert/pot2po.py ('k') | no next file »
Index: translate/convert/test_pot2po.py
===================================================================
--- translate/convert/test_pot2po.py	(revision 7818)
+++ translate/convert/test_pot2po.py	(working copy)
@@ -13,7 +13,7 @@
     def teardown_method(self, method):
         warnings.resetwarnings()
 
-    def convertpot(self, potsource, posource=None):
+    def convertpot(self, potsource, posource=None, *args, **kwargs):
         """helper that converts pot source to po source without requiring files"""
         potfile = wStringIO.StringIO(potsource)
         if posource:
@@ -21,7 +21,9 @@
         else:
             pofile = None
         pooutfile = wStringIO.StringIO()
-        pot2po.convertpot(potfile, pooutfile, pofile)
+        if 'ignore_previous' not in kwargs.keys():
+            kwargs['ignore_previous'] = True
+        pot2po.convertpot(potfile, pooutfile, pofile, *args, **kwargs)
         pooutfile.seek(0)
         return po.pofile(pooutfile.read())
 
@@ -411,6 +413,110 @@
         assert newpounit.isfuzzy()
         assert newpounit.hastypecomment("c-format")
 
+    def test_previous_message_without_msgstr(self):
+        potsource = '#: a.c:1\nmsgid "%d units"\nmsgstr ""\n'
+        posource = '#: a.c:1\nmsgid "%s units"\nmsgstr ""\n'
+        poexpected = potsource
+        newpo = self.convertpot(potsource, posource, ignore_previous=False)
+        newpounit = self.singleunit(newpo)
+        assert str(newpounit) ==  poexpected
+        assert not newpounit.isfuzzy()
+
+    def test_previous_message_singular(self):
+        potsource = '#: a.c:1\nmsgid "%d unit"\nmsgstr "%d unidade"\n'
+        posource = '#: a.c:1\nmsgid "%s unit"\nmsgstr "%s unidade"\n'
+        poexpected = '''#: a.c:1\n#, fuzzy\n#| msgid "%d unit"\nmsgid "%s unit"
+msgstr "%d unidade"\n'''
+        newpo = self.convertpot(potsource, posource, ignore_previous=False)
+        newpounit = self.singleunit(newpo)
+        assert str(newpounit) ==  poexpected
+        assert newpounit.isfuzzy()
+
+    def test_previous_message_with_plural(self):
+        potsource = '''#: a.c:1\nmsgid "%d unit"\nmsgid_plural "%d units"
+msgstr[0] "%d unidade"\nmsgstr[1] "%d unidades"'''
+        posource = '''#: a.c:1\nmsgid "%s unit"\nmsgid_plural "%s units"
+msgstr[0] "%s unidade"\nmsgstr[1] "%s unidades"'''
+        poexpected = '''#: a.c:1
+#, fuzzy
+#| msgid "%d unit"
+#| msgid_plural "%d units"
+msgid "%s unit"
+msgid_plural "%s units"
+msgstr[0] "%d unidade"
+msgstr[1] "%d unidades"\n'''
+        newpo = self.convertpot(potsource, posource, ignore_previous=False)
+        newpounit = self.singleunit(newpo)
+        assert str(newpounit) ==  poexpected
+        assert newpounit.isfuzzy()
+
+    def test_previous_message_with_only_pot_plural(self):
+        potsource = '''#: a.c:1\nmsgid "plural"\nmsgid_plural "plurals"
+msgstr[0] "plural"\nmsgstr[1] "plurais"'''
+        posource = '#: a.c:1\nmsgid "plural"\nmsgstr "plural"\n'
+        poexpected = '''#: a.c:1
+#, fuzzy
+#| msgid "plural"
+#| msgid_plural "plurals"
+msgid "plural"
+msgstr "plural"\n'''
+        newpo = self.convertpot(potsource, posource, ignore_previous=False)
+        newpounit = self.singleunit(newpo)
+        print str(newpounit)
+        print 'Expected'
+        print poexpected
+        assert str(newpounit) ==  poexpected
+        assert newpounit.isfuzzy()
+
+    def test_previous_message_with_only_po_plural(self):
+        #XXX: broken test - missing msgstr[1]
+        #     in msgmerge it just copy the msgstr[0] to msgstr[1] (?)
+        potsource = '#: a.c:1\nmsgid "unit"\n msgstr "unidade"\n'
+        posource = '''#: a.c:1\nmsgid "unit"\nmsgid_plural "units"
+msgstr[0] "unidade"\nmsgstr[1] "unidades"'''
+        poexpected = '''#: a.c:1
+#, fuzzy
+#| msgid "unit"
+msgid "unit"
+msgid_plural "units"
+msgstr[0] "unidade"
+msgstr[1] "unidades"\n'''
+        newpo = self.convertpot(potsource, posource, ignore_previous=False)
+        newpounit = self.singleunit(newpo)
+        #XXX: remove this later
+        print str(newpounit)
+        print 'Expected'
+        print poexpected
+        assert str(newpounit) ==  poexpected
+        assert newpounit.isfuzzy()
+
+    def test_previous_message_with_fuzzy_state_set(self):
+        potsource = '#: a.c:1\n#, fuzzy\nmsgid "%d units"\nmsgstr "%d unidades"\n'
+        posource = '#: a.c:1\nmsgid "%s units"\nmsgstr "%s unidades"\n'
+        poexpected = '#: a.c:1\n#, fuzzy\nmsgid "%s units"\nmsgstr "%d unidades"\n'
+        newpo = self.convertpot(potsource, posource, ignore_previous=False)
+        newpounit = self.singleunit(newpo)
+        assert str(newpounit) ==  poexpected
+        assert newpounit.isfuzzy()
+
+    def test_previous_message_with_context(self):
+        potsource = '''#: a.c:1\nmsgctxt "Testing"\nmsgid "%d unit"
+msgstr "%d unidade"'''
+        posource = '''#: a.c:1\nmsgctxt "Testing"\nmsgid "%s unit"
+msgstr "%s unidade"'''
+        poexpected = '''#: a.c:1
+#, fuzzy
+#| msgctxt "Testing"
+#| msgid "%d unit"
+msgctxt "Testing"
+msgid "%s unit"
+msgstr "%d unidade"\n'''
+        newpo = self.convertpot(potsource, posource, ignore_previous=False)
+        newpounit = self.singleunit(newpo)
+        assert str(newpounit) ==  poexpected
+        assert newpounit.isfuzzy()
+
+
 class TestPOT2POCommand(test_convert.TestConvertCommand, TestPOT2PO):
     """Tests running actual pot2po commands on files"""
     convertmodule = pot2po
@@ -422,5 +528,6 @@
         options = self.help_check(options, "-P, --pot")
         options = self.help_check(options, "--tm")
         options = self.help_check(options, "-s MIN_SIMILARITY, --similarity=MIN_SIMILARITY")
-        options = self.help_check(options, "--nofuzzymatching", last=True)
+        options = self.help_check(options, "--nofuzzymatching")
+        options = self.help_check(options, "--ignore-previous", last=True)
 

« translate/convert/pot2po.py ('k') | no next file »

Powered by Google App Engine
This is Rietveld r159