| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 | 2 |
| 3 from translate.convert import pot2po | 3 from translate.convert import pot2po |
| 4 from translate.convert import test_convert | 4 from translate.convert import test_convert |
| 5 from translate.misc import wStringIO | 5 from translate.misc import wStringIO |
| 6 from translate.storage import po | 6 from translate.storage import po |
| 7 import warnings | 7 import warnings |
| 8 | 8 |
| 9 class TestPOT2PO: | 9 class TestPOT2PO: |
| 10 def setup_method(self, method): | 10 def setup_method(self, method): |
| 11 warnings.resetwarnings() | 11 warnings.resetwarnings() |
| 12 | 12 |
| 13 def teardown_method(self, method): | 13 def teardown_method(self, method): |
| 14 warnings.resetwarnings() | 14 warnings.resetwarnings() |
| 15 | 15 |
| 16 def convertpot(self, potsource, posource=None): | 16 def convertpot(self, potsource, posource=None): |
| 17 """helper that converts pot source to po source without requiring files"
"" | 17 """helper that converts pot source to po source without requiring files"
"" |
| 18 potfile = wStringIO.StringIO(potsource) | 18 potfile = wStringIO.StringIO(potsource) |
| 19 if posource: | 19 if posource: |
| 20 pofile = wStringIO.StringIO(posource) | 20 pofile = wStringIO.StringIO(posource) |
| 21 else: | 21 else: |
| 22 pofile = None | 22 pofile = None |
| 23 pooutfile = wStringIO.StringIO() | 23 pooutfile = wStringIO.StringIO() |
| 24 pot2po.convertpot(potfile, pooutfile, pofile) | 24 pot2po.convertpot(potfile, pooutfile, pofile) |
| 25 pooutfile.seek(0) | 25 pooutfile.seek(0) |
| 26 return po.pofile(pooutfile.read()) | 26 return po.pofile(pooutfile.read()) |
| 27 | 27 |
| 28 def singleunit(self, pofile): | 28 def singleunit(self, pofile): |
| 29 """checks that the pofile contains a single non-header unit, and returns
it""" | 29 """checks that the pofile contains a single non-header unit, and returns
it""" |
| 30 assert len(pofile.units) == 2 | 30 assert len(pofile.units) == 2 |
| 31 assert pofile.units[0].isheader() | 31 assert pofile.units[0].isheader() |
| 32 print pofile.units[1] | 32 print pofile.units[1] |
| 33 return pofile.units[1] | 33 return pofile.units[1] |
| 34 | 34 |
| 35 def test_convertpot_blank(self): | 35 def test_convertpot_blank(self): |
| 36 """checks that the convertpot function is working for a simple file init
ialisation""" | 36 """checks that the convertpot function is working for a simple file init
ialisation""" |
| 37 potsource = '''#: simple.label%ssimple.accesskey\nmsgid "A &hard coded n
ewline.\\n"\nmsgstr ""\n''' % po.lsep | 37 potsource = '''#: simple.label:1%ssimple.accesskey:1\nmsgid "A &hard cod
ed newline.\\n"\nmsgstr ""\n''' % po.lsep |
| 38 newpo = self.convertpot(potsource) | 38 newpo = self.convertpot(potsource) |
| 39 assert str(self.singleunit(newpo)) == potsource | 39 assert str(self.singleunit(newpo)) == potsource |
| 40 | 40 |
| 41 def test_convertpot_blank_plurals(self): | 41 def test_convertpot_blank_plurals(self): |
| 42 """checks that the convertpot function is working for initialising plura
ls correctly""" | 42 """checks that the convertpot function is working for initialising plura
ls correctly""" |
| 43 potsource = r'''msgid "" | 43 potsource = r'''msgid "" |
| 44 msgstr"" | 44 msgstr"" |
| 45 | 45 |
| 46 msgid "%d manual" | 46 msgid "%d manual" |
| 47 msgid_plural "%d manuals" | 47 msgid_plural "%d manuals" |
| 48 msgstr[0] "" | 48 msgstr[0] "" |
| 49 msgstr[1] "" | 49 msgstr[1] "" |
| 50 ''' | 50 ''' |
| 51 posource = r'''msgid "" | 51 posource = r'''msgid "" |
| 52 msgstr"" | 52 msgstr"" |
| 53 "Plural-Forms: nplurals=1; plural=0;\n" | 53 "Plural-Forms: nplurals=1; plural=0;\n" |
| 54 ''' | 54 ''' |
| 55 | 55 |
| 56 poexpected = r'''msgid "%d manual" | 56 poexpected = r'''msgid "%d manual" |
| 57 msgid_plural "%d manuals" | 57 msgid_plural "%d manuals" |
| 58 msgstr[0] "" | 58 msgstr[0] "" |
| 59 ''' | 59 ''' |
| 60 newpo = self.convertpot(potsource, posource) | 60 newpo = self.convertpot(potsource, posource) |
| 61 assert str(self.singleunit(newpo)) == poexpected | 61 assert str(self.singleunit(newpo)) == poexpected |
| 62 | 62 |
| 63 def test_merging_simple(self): | 63 def test_merging_simple(self): |
| 64 """checks that the convertpot function is working for a simple merge""" | 64 """checks that the convertpot function is working for a simple merge""" |
| 65 potsource = '''#: simple.label%ssimple.accesskey\nmsgid "A &hard coded n
ewline.\\n"\nmsgstr ""\n''' % po.lsep | 65 potsource = '''#: simple.label:1%ssimple.accesskey:1\nmsgid "A &hard cod
ed newline.\\n"\nmsgstr ""\n''' % po.lsep |
| 66 posource = '''#: simple.label%ssimple.accesskey\nmsgid "A &hard coded ne
wline.\\n"\nmsgstr "&Hart gekoeerde nuwe lyne\\n"\n''' % po.lsep | 66 posource = '''#: simple.label:1%ssimple.accesskey:1\nmsgid "A &hard code
d newline.\\n"\nmsgstr "&Hart gekoeerde nuwe lyne\\n"\n''' % po.lsep |
| 67 newpo = self.convertpot(potsource, posource) | 67 newpo = self.convertpot(potsource, posource) |
| 68 assert str(self.singleunit(newpo)) == posource | 68 assert str(self.singleunit(newpo)) == posource |
| 69 | 69 |
| 70 def test_merging_messages_marked_fuzzy(self): | 70 def test_merging_messages_marked_fuzzy(self): |
| 71 """test that when we merge PO files with a fuzzy message that it remains
fuzzy""" | 71 """test that when we merge PO files with a fuzzy message that it remains
fuzzy""" |
| 72 potsource = '''#: simple.label%ssimple.accesskey\nmsgid "A &hard coded n
ewline.\\n"\nmsgstr ""\n''' % po.lsep | 72 potsource = '''#: simple.label:1%ssimple.accesskey:1\nmsgid "A &hard cod
ed newline.\\n"\nmsgstr ""\n''' % po.lsep |
| 73 posource = '''#: simple.label%ssimple.accesskey\n#, fuzzy\nmsgid "A &har
d coded newline.\\n"\nmsgstr "&Hart gekoeerde nuwe lyne\\n"\n''' % po.lsep | 73 posource = '''#: simple.label:1%ssimple.accesskey:1\n#, fuzzy\nmsgid "A
&hard coded newline.\\n"\nmsgstr "&Hart gekoeerde nuwe lyne\\n"\n''' % po.lsep |
| 74 newpo = self.convertpot(potsource, posource) | 74 newpo = self.convertpot(potsource, posource) |
| 75 assert str(self.singleunit(newpo)) == posource | 75 assert str(self.singleunit(newpo)) == posource |
| 76 | 76 |
| 77 def test_merging_plurals_with_fuzzy_matching(self): | 77 def test_merging_plurals_with_fuzzy_matching(self): |
| 78 """test that when we merge PO files with a fuzzy message that it remains
fuzzy""" | 78 """test that when we merge PO files with a fuzzy message that it remains
fuzzy""" |
| 79 potsource = r'''#: file.cpp:2 | 79 potsource = r'''#: file.cpp:2 |
| 80 msgid "%d manual" | 80 msgid "%d manual" |
| 81 msgid_plural "%d manuals" | 81 msgid_plural "%d manuals" |
| 82 msgstr[0] "" | 82 msgstr[0] "" |
| 83 msgstr[1] "" | 83 msgstr[1] "" |
| 84 ''' | 84 ''' |
| 85 posource = r'''#: file.cpp:3 | 85 posource = r'''#: file.cpp:3 |
| 86 #, fuzzy | 86 #, fuzzy |
| 87 msgid "%d manual" | 87 msgid "%d manual" |
| 88 msgid_plural "%d manuals" | 88 msgid_plural "%d manuals" |
| 89 msgstr[0] "%d handleiding." | 89 msgstr[0] "%d handleiding." |
| 90 msgstr[1] "%d handleidings." | 90 msgstr[1] "%d handleidings." |
| 91 ''' | 91 ''' |
| 92 # The #: comment and msgid's are different between the pot and the po | 92 # The #: comment and msgid's are different between the pot and the po |
| 93 poexpected = r'''#: file.cpp:2 | 93 poexpected = r'''#: file.cpp:2 |
| 94 #, fuzzy | 94 #, fuzzy |
| 95 msgid "%d manual" | 95 msgid "%d manual" |
| 96 msgid_plural "%d manuals" | 96 msgid_plural "%d manuals" |
| 97 msgstr[0] "%d handleiding." | 97 msgstr[0] "%d handleiding." |
| 98 msgstr[1] "%d handleidings." | 98 msgstr[1] "%d handleidings." |
| 99 ''' | 99 ''' |
| 100 newpo = self.convertpot(potsource, posource) | 100 newpo = self.convertpot(potsource, posource) |
| 101 assert str(self.singleunit(newpo)) == poexpected | 101 assert str(self.singleunit(newpo)) == poexpected |
| 102 | 102 |
| 103 def xtest_merging_msgid_change(self): | 103 def xtest_merging_msgid_change(self): |
| 104 """tests that if the msgid changes but the location stays the same that
we merge""" | 104 """tests that if the msgid changes but the location stays the same that
we merge""" |
| 105 potsource = '''#: simple.label\n#: simple.accesskey\nmsgid "Its &hard co
ding a newline.\\n"\nmsgstr ""\n''' | 105 potsource = '''#: simple.label:1\n#: simple.accesskey\nmsgid "Its &hard
coding a newline.\\n"\nmsgstr ""\n''' |
| 106 posource = '''#: simple.label\n#: simple.accesskey\nmsgid "A &hard coded
newline.\\n"\nmsgstr "&Hart gekoeerde nuwe lyne\\n"\n''' | 106 posource = '''#: simple.label:1\n#: simple.accesskey\nmsgid "A &hard cod
ed newline.\\n"\nmsgstr "&Hart gekoeerde nuwe lyne\\n"\n''' |
| 107 poexpected = '''#: simple.label\n#: simple.accesskey\n#, fuzzy\nmsgid "I
ts &hard coding a newline.\\n"\nmsgstr "&Hart gekoeerde nuwe lyne\\n"\n''' | 107 poexpected = '''#: simple.label:1\n#: simple.accesskey\n#, fuzzy\nmsgid
"Its &hard coding a newline.\\n"\nmsgstr "&Hart gekoeerde nuwe lyne\\n"\n''' |
| 108 newpo = self.convertpot(potsource, posource) | 108 newpo = self.convertpot(potsource, posource) |
| 109 print newpo | 109 print newpo |
| 110 assert str(self.singleunit(newpo)) == poexpected | 110 assert str(self.singleunit(newpo)) == poexpected |
| 111 | 111 |
| 112 def test_merging_location_change(self): | 112 def test_merging_location_change(self): |
| 113 """tests that if the location changes but the msgid stays the same that
we merge""" | 113 """tests that if the location changes but the msgid stays the same that
we merge""" |
| 114 potsource = '''#: new_simple.label%snew_simple.accesskey\nmsgid "A &hard
coded newline.\\n"\nmsgstr ""\n''' % po.lsep | 114 potsource = '''#: new_simple.label:1%snew_simple.accesskey:1\nmsgid "A &
hard coded newline.\\n"\nmsgstr ""\n''' % po.lsep |
| 115 posource = '''#: simple.label%ssimple.accesskey\nmsgid "A &hard coded ne
wline.\\n"\nmsgstr "&Hart gekoeerde nuwe lyne\\n"\n''' % po.lsep | 115 posource = '''#: simple.label:1%ssimple.accesskey:1\nmsgid "A &hard code
d newline.\\n"\nmsgstr "&Hart gekoeerde nuwe lyne\\n"\n''' % po.lsep |
| 116 poexpected = '''#: new_simple.label%snew_simple.accesskey\nmsgid "A &har
d coded newline.\\n"\nmsgstr "&Hart gekoeerde nuwe lyne\\n"\n''' % po.lsep | 116 poexpected = '''#: new_simple.label:1%snew_simple.accesskey:1\nmsgid "A
&hard coded newline.\\n"\nmsgstr "&Hart gekoeerde nuwe lyne\\n"\n''' % po.lsep |
| 117 newpo = self.convertpot(potsource, posource) | 117 newpo = self.convertpot(potsource, posource) |
| 118 print newpo | 118 print newpo |
| 119 assert str(self.singleunit(newpo)) == poexpected | 119 assert str(self.singleunit(newpo)) == poexpected |
| 120 | 120 |
| 121 def test_merging_location_and_whitespace_change(self): | 121 def test_merging_location_and_whitespace_change(self): |
| 122 """test that even if the location changes that if the msgid only has whi
tespace changes we can still merge""" | 122 """test that even if the location changes that if the msgid only has whi
tespace changes we can still merge""" |
| 123 potsource = '''#: singlespace.label%ssinglespace.accesskey\nmsgid "&We h
ave spaces"\nmsgstr ""\n''' % po.lsep | 123 potsource = '''#: singlespace.label:1%ssinglespace.accesskey:1\nmsgid "&
We have spaces"\nmsgstr ""\n''' % po.lsep |
| 124 posource = '''#: doublespace.label%sdoublespace.accesskey\nmsgid "&We h
ave spaces"\nmsgstr "&One het spasies"\n''' % po.lsep | 124 posource = '''#: doublespace.label:1%sdoublespace.accesskey:1\nmsgid "&W
e have spaces"\nmsgstr "&One het spasies"\n''' % po.lsep |
| 125 poexpected = '''#: singlespace.label%ssinglespace.accesskey\n#, fuzzy\nm
sgid "&We have spaces"\nmsgstr "&One het spasies"\n''' % po.lsep | 125 poexpected = '''#: singlespace.label:1%ssinglespace.accesskey:1\n#, fuzz
y\nmsgid "&We have spaces"\nmsgstr "&One het spasies"\n''' % po.lsep |
| 126 newpo = self.convertpot(potsource, posource) | 126 newpo = self.convertpot(potsource, posource) |
| 127 print newpo | 127 print newpo |
| 128 assert str(self.singleunit(newpo)) == poexpected | 128 assert str(self.singleunit(newpo)) == poexpected |
| 129 | 129 |
| 130 def test_merging_location_ambiguous_with_disambiguous(self): | 130 def test_merging_location_ambiguous_with_disambiguous(self): |
| 131 """test that when we have a PO in ambiguous (Gettext form) and merge wit
h disamabiguous (KDE comment form) | 131 """test that when we have a PO in ambiguous (Gettext form) and merge wit
h disamabiguous (KDE comment form) |
| 132 that we don't duplicate the location #: comments""" | 132 that we don't duplicate the location #: comments""" |
| 133 potsource = '''#: location.c:1\nmsgid ""\n"_: location.c:1\\n"\n"Source"
\nmsgstr ""\n\n''' + \ | 133 potsource = '''#: location.c:1\nmsgid ""\n"_: location.c:1\\n"\n"Source"
\nmsgstr ""\n\n''' + \ |
| 134 '''#: location.c:10\nmsgid ""\n"_: location.c:10\\n"\n"Sourc
e"\nmsgstr ""\n''' | 134 '''#: location.c:10\nmsgid ""\n"_: location.c:10\\n"\n"Sourc
e"\nmsgstr ""\n''' |
| 135 posource = '''#: location.c:1\n#: location.c:10\nmsgid "Source"\nmsgstr
"Target"\n\n''' | 135 posource = '''#: location.c:1\n#: location.c:10\nmsgid "Source"\nmsgstr
"Target"\n\n''' |
| 136 poexpected1 = '''#: location.c:1\nmsgid ""\n"_: location.c:1\\n"\n"Sourc
e"\nmsgstr "Target"\n''' | 136 poexpected1 = '''#: location.c:1\nmsgid ""\n"_: location.c:1\\n"\n"Sourc
e"\nmsgstr "Target"\n''' |
| 137 poexpected2 = '''#: location.c:10\nmsgid ""\n"_: location.c:10\\n"\n"Sou
rce"\nmsgstr "Target"\n''' | 137 poexpected2 = '''#: location.c:10\nmsgid ""\n"_: location.c:10\\n"\n"Sou
rce"\nmsgstr "Target"\n''' |
| 138 newpo = self.convertpot(potsource, posource) | 138 newpo = self.convertpot(potsource, posource) |
| 139 print "Expected:\n", poexpected1, "Actual:\n", newpo.units[1] | |
| 140 assert str(newpo.units[1]) == poexpected1 | 139 assert str(newpo.units[1]) == poexpected1 |
| 141 assert str(newpo.units[2]) == poexpected2 | 140 assert str(newpo.units[2]) == poexpected2 |
| 142 | 141 |
| 143 def wtest_merging_accelerator_changes(self): | 142 def wtest_merging_accelerator_changes(self): |
| 144 """test that a change in the accelerator localtion still allows merging"
"" | 143 """test that a change in the accelerator localtion still allows merging"
"" |
| 145 potsource = '''#: someline.c\nmsgid "A&bout"\nmsgstr ""\n''' | 144 potsource = '''#: someline.c:1\nmsgid "A&bout"\nmsgstr ""\n''' |
| 146 posource = '''#: someline.c\nmsgid "&About"\nmsgstr "&Info"\n''' | 145 posource = '''#: someline.c:1\nmsgid "&About"\nmsgstr "&Info"\n''' |
| 147 poexpected = '''#: someline.c\nmsgid "A&bout"\nmsgstr "&Info"\n''' | 146 poexpected = '''#: someline.c:1\nmsgid "A&bout"\nmsgstr "&Info"\n''' |
| 148 newpo = self.convertpot(potsource, posource) | 147 newpo = self.convertpot(potsource, posource) |
| 149 print newpo | 148 print newpo |
| 150 assert str(self.singleunit(newpo)) == poexpected | 149 assert str(self.singleunit(newpo)) == poexpected |
| 151 | 150 |
| 152 def xtest_lines_cut_differently(self): | 151 def xtest_lines_cut_differently(self): |
| 153 """Checks that the correct formatting is preserved when pot an po lines
differ.""" | 152 """Checks that the correct formatting is preserved when pot an po lines
differ.""" |
| 154 potsource = '''#: simple.label\nmsgid "Line split "\n"differently"\nmsgs
tr ""\n''' | 153 potsource = '''#: simple.label:1\nmsgid "Line split "\n"differently"\nms
gstr ""\n''' |
| 155 posource = '''#: simple.label\nmsgid "Line"\n" split differently"\nmsgst
r "Lyne verskillend gesny"\n''' | 154 posource = '''#: simple.label:1\nmsgid "Line"\n" split differently"\nmsg
str "Lyne verskillend gesny"\n''' |
| 156 newpo = self.convertpot(potsource, posource) | 155 newpo = self.convertpot(potsource, posource) |
| 157 newpounit = self.singleunit(newpo) | 156 newpounit = self.singleunit(newpo) |
| 158 assert str(newpounit) == posource | 157 assert str(newpounit) == posource |
| 159 | 158 |
| 160 def test_merging_automatic_comments_dont_duplicate(self): | 159 def test_merging_automatic_comments_dont_duplicate(self): |
| 161 """ensure that we can merge #. comments correctly""" | 160 """ensure that we can merge #. comments correctly""" |
| 162 potsource = '''#. Row 35\nmsgid "&About"\nmsgstr ""\n''' | 161 potsource = '''#. Row 35\nmsgid "&About"\nmsgstr ""\n''' |
| 163 posource = '''#. Row 35\nmsgid "&About"\nmsgstr "&Info"\n''' | 162 posource = '''#. Row 35\nmsgid "&About"\nmsgstr "&Info"\n''' |
| 164 newpo = self.convertpot(potsource, posource) | 163 newpo = self.convertpot(potsource, posource) |
| 165 newpounit = self.singleunit(newpo) | 164 newpounit = self.singleunit(newpo) |
| 166 assert str(newpounit) == posource | 165 assert str(newpounit) == posource |
| 167 | 166 |
| 168 def test_merging_automatic_comments_new_overides_old(self): | 167 def test_merging_automatic_comments_new_overides_old(self): |
| 169 """ensure that new #. comments override the old comments""" | 168 """ensure that new #. comments override the old comments""" |
| 170 potsource = '''#. new comment\n#: someline.c\nmsgid "&About"\nmsgstr ""\
n''' | 169 potsource = '''#. new comment\n#: someline.c:1\nmsgid "&About"\nmsgstr "
"\n''' |
| 171 posource = '''#. old comment\n#: someline.c\nmsgid "&About"\nmsgstr "&In
fo"\n''' | 170 posource = '''#. old comment\n#: someline.c:1\nmsgid "&About"\nmsgstr "&
Info"\n''' |
| 172 poexpected = '''#. new comment\n#: someline.c\nmsgid "&About"\nmsgstr "&
Info"\n''' | 171 poexpected = '''#. new comment\n#: someline.c:1\nmsgid "&About"\nmsgstr
"&Info"\n''' |
| 173 newpo = self.convertpot(potsource, posource) | 172 newpo = self.convertpot(potsource, posource) |
| 174 newpounit = self.singleunit(newpo) | 173 newpounit = self.singleunit(newpo) |
| 175 assert str(newpounit) == poexpected | 174 assert str(newpounit) == poexpected |
| 176 | 175 |
| 177 def test_merging_comments_with_blank_comment_lines(self): | 176 def test_merging_comments_with_blank_comment_lines(self): |
| 178 """test that when we merge a comment that has a blank line we keep the b
lank line""" | 177 """test that when we merge a comment that has a blank line we keep the b
lank line""" |
| 179 potsource = '''#: someline.c\nmsgid "About"\nmsgstr ""\n''' | 178 potsource = '''#: someline.c:1\nmsgid "About"\nmsgstr ""\n''' |
| 180 posource = '''# comment1\n#\n# comment2\n#: someline.c\nmsgid "About"\nm
sgstr "Omtrent"\n''' | 179 posource = '''# comment1\n#\n# comment2\n#: someline.c:1\nmsgid "About"\
nmsgstr "Omtrent"\n''' |
| 181 poexpected = posource | 180 poexpected = posource |
| 182 newpo = self.convertpot(potsource, posource) | 181 newpo = self.convertpot(potsource, posource) |
| 183 newpounit = self.singleunit(newpo) | 182 newpounit = self.singleunit(newpo) |
| 184 assert str(newpounit) == poexpected | 183 assert str(newpounit) == poexpected |
| 185 | 184 |
| 186 def test_empty_commentlines(self): | 185 def test_empty_commentlines(self): |
| 187 potsource = '''#: paneSecurity.title | 186 potsource = '''#: paneSecurity.title:1 |
| 188 msgid "Security" | 187 msgid "Security" |
| 189 msgstr "" | 188 msgstr "" |
| 190 ''' | 189 ''' |
| 191 posource = '''# - Contributor(s): | 190 posource = '''# - Contributor(s): |
| 192 # - | 191 # - |
| 193 # - Alternatively, the | 192 # - Alternatively, the |
| 194 # - | 193 # - |
| 195 #: paneSecurity.title | 194 #: paneSecurity.title:1 |
| 196 msgid "Security" | 195 msgid "Security" |
| 197 msgstr "Sekuriteit" | 196 msgstr "Sekuriteit" |
| 198 ''' | 197 ''' |
| 199 poexpected = posource | 198 poexpected = posource |
| 200 newpo = self.convertpot(potsource, posource) | 199 newpo = self.convertpot(potsource, posource) |
| 201 newpounit = self.singleunit(newpo) | 200 newpounit = self.singleunit(newpo) |
| 202 print "expected" | 201 print "expected" |
| 203 print poexpected | 202 print poexpected |
| 204 print "got:" | 203 print "got:" |
| 205 print str(newpounit) | 204 print str(newpounit) |
| 206 assert str(newpounit) == poexpected | 205 assert str(newpounit) == poexpected |
| 207 | 206 |
| 208 def test_merging_msgidcomments(self): | 207 def test_merging_msgidcomments(self): |
| 209 """ensure that we can merge msgidcomments messages""" | 208 """ensure that we can merge msgidcomments messages""" |
| 210 potsource = r'''#: window.width | 209 potsource = r'''#: window.width:1 |
| 211 msgid "" | 210 msgid "" |
| 212 "_: Do not translate this.\n" | 211 "_: Do not translate this.\n" |
| 213 "36em" | 212 "36em" |
| 214 msgstr "" | 213 msgstr "" |
| 215 ''' | 214 ''' |
| 216 posource = r'''#: window.width | 215 posource = r'''#: window.width:1 |
| 217 msgid "" | 216 msgid "" |
| 218 "_: Do not translate this.\n" | 217 "_: Do not translate this.\n" |
| 219 "36em" | 218 "36em" |
| 220 msgstr "36em" | 219 msgstr "36em" |
| 221 ''' | 220 ''' |
| 222 newpo = self.convertpot(potsource, posource) | 221 newpo = self.convertpot(potsource, posource) |
| 223 newpounit = self.singleunit(newpo) | 222 newpounit = self.singleunit(newpo) |
| 224 assert str(newpounit) == posource | 223 assert str(newpounit) == posource |
| 225 | 224 |
| 226 def test_merging_msgid_with_msgidcomment(self): | 225 def test_merging_msgid_with_msgidcomment(self): |
| 227 """test that we can merge an otherwise identical string that has a diffe
rent msgid""" | 226 """test that we can merge an otherwise identical string that has a diffe
rent msgid""" |
| 228 potsource = r'''#: pref.certs.title | 227 potsource = r'''#: pref.certs.title:1 |
| 229 msgid "" | 228 msgid "" |
| 230 "_: pref.certs.title\n" | 229 "_: pref.certs.title\n" |
| 231 "Certificates" | 230 "Certificates" |
| 232 msgstr "" | 231 msgstr "" |
| 233 | 232 |
| 234 #: certs.label | 233 #: certs.label:1 |
| 235 msgid "" | 234 msgid "" |
| 236 "_: certs.label\n" | 235 "_: certs.label\n" |
| 237 "Certificates" | 236 "Certificates" |
| 238 msgstr "" | 237 msgstr "" |
| 239 ''' | 238 ''' |
| 240 posource = r'''#: pref.certs.title | 239 posource = r'''#: pref.certs.title:1 |
| 241 msgid "" | 240 msgid "" |
| 242 "_: pref.certs.title\n" | 241 "_: pref.certs.title\n" |
| 243 "Certificates" | 242 "Certificates" |
| 244 msgstr "" | 243 msgstr "" |
| 245 | 244 |
| 246 #: certs.label | 245 #: certs.label:1 |
| 247 msgid "" | 246 msgid "" |
| 248 "_: certs.label\n" | 247 "_: certs.label\n" |
| 249 "Certificates" | 248 "Certificates" |
| 250 msgstr "Sertifikate" | 249 msgstr "Sertifikate" |
| 251 ''' | 250 ''' |
| 252 expected = r'''#: pref.certs.title | 251 expected = r'''#: pref.certs.title:1 |
| 253 msgid "" | 252 msgid "" |
| 254 "_: pref.certs.title\n" | 253 "_: pref.certs.title\n" |
| 255 "Certificates" | 254 "Certificates" |
| 256 msgstr "Sertifikate" | 255 msgstr "Sertifikate" |
| 257 ''' | 256 ''' |
| 258 newpo = self.convertpot(potsource, posource) | 257 newpo = self.convertpot(potsource, posource) |
| 259 newpounit = newpo.units[1] | 258 newpounit = newpo.units[1] |
| 260 assert str(newpounit) == expected | 259 assert str(newpounit) == expected |
| 261 | 260 |
| 262 def test_merging_plurals(self): | 261 def test_merging_plurals(self): |
| 263 """ensure that we can merge plural messages""" | 262 """ensure that we can merge plural messages""" |
| 264 potsource = '''msgid "One"\nmsgid_plural "Two"\nmsgstr[0] ""\nmsgstr[1]
""\n''' | 263 potsource = '''msgid "One"\nmsgid_plural "Two"\nmsgstr[0] ""\nmsgstr[1]
""\n''' |
| 265 posource = '''msgid "One"\nmsgid_plural "Two"\nmsgstr[0] "Een"\nmsgstr[1
] "Twee"\nmsgstr[2] "Drie"\n''' | 264 posource = '''msgid "One"\nmsgid_plural "Two"\nmsgstr[0] "Een"\nmsgstr[1
] "Twee"\nmsgstr[2] "Drie"\n''' |
| 266 newpo = self.convertpot(potsource, posource) | 265 newpo = self.convertpot(potsource, posource) |
| 267 print newpo | 266 print newpo |
| 268 newpounit = self.singleunit(newpo) | 267 newpounit = self.singleunit(newpo) |
| 269 assert str(newpounit) == posource | 268 assert str(newpounit) == posource |
| 270 | 269 |
| 271 def test_merging_obsoleting_messages(self): | 270 def test_merging_obsoleting_messages(self): |
| 272 """check that we obsolete messages no longer present in the new file""" | 271 """check that we obsolete messages no longer present in the new file""" |
| 273 potsource = '' | 272 potsource = '' |
| 274 posource = '# Some comment\n#. Extracted comment\n#: obsoleteme:10\nmsgi
d "One"\nmsgstr "Een"\n' | 273 posource = '# Some comment\n#. Extracted comment\n#: obsoleteme:10\nmsgi
d "One"\nmsgstr "Een"\n' |
| 275 expected = '# Some comment\n#~ msgid "One"\n#~ msgstr "Een"\n' | 274 expected = '# Some comment\n#~ msgid "One"\n#~ msgstr "Een"\n' |
| 276 newpo = self.convertpot(potsource, posource) | 275 newpo = self.convertpot(potsource, posource) |
| 277 print str(newpo) | 276 print str(newpo) |
| 278 newpounit = self.singleunit(newpo) | 277 newpounit = self.singleunit(newpo) |
| 279 assert str(newpounit) == expected | 278 assert str(newpounit) == expected |
| 280 | 279 |
| 281 def test_not_obsoleting_empty_messages(self): | 280 def test_not_obsoleting_empty_messages(self): |
| 282 """check that we don't obsolete (and keep) untranslated messages""" | 281 """check that we don't obsolete (and keep) untranslated messages""" |
| 283 potsource = '' | 282 potsource = '' |
| 284 posource = '#: obsoleteme:10\nmsgid "One"\nmsgstr ""\n' | 283 posource = '#: obsoleteme:10\nmsgid "One"\nmsgstr ""\n' |
| 285 newpo = self.convertpot(potsource, posource) | 284 newpo = self.convertpot(potsource, posource) |
| 286 print str(newpo) | 285 print str(newpo) |
| 287 # We should only have the header | 286 # We should only have the header |
| 288 assert len(newpo.units) == 1 | 287 assert len(newpo.units) == 1 |
| 289 | 288 |
| 290 def test_merging_new_before_obsolete(self): | 289 def test_merging_new_before_obsolete(self): |
| 291 """test to check that we place new blank message before obsolete message
s""" | 290 """test to check that we place new blank message before obsolete message
s""" |
| 292 potsource = '''#: newline.c\nmsgid "&About"\nmsgstr ""\n''' | 291 potsource = '''#: newline.c:1\nmsgid "&About"\nmsgstr ""\n''' |
| 293 posource = '''#~ msgid "Old"\n#~ msgstr "Oud"\n''' | 292 posource = '''#~ msgid "Old"\n#~ msgstr "Oud"\n''' |
| 294 newpo = self.convertpot(potsource, posource) | 293 newpo = self.convertpot(potsource, posource) |
| 295 assert len(newpo.units) == 3 | 294 assert len(newpo.units) == 3 |
| 296 assert newpo.units[0].isheader() | 295 assert newpo.units[0].isheader() |
| 297 assert newpo.units[2].isobsolete() | 296 assert newpo.units[2].isobsolete() |
| 298 assert str(newpo.units[1]) == potsource | 297 assert str(newpo.units[1]) == potsource |
| 299 assert str(newpo.units[2]) == posource | 298 assert str(newpo.units[2]) == posource |
| 300 | 299 |
| 301 # Now test with real units present in posource | 300 # Now test with real units present in posource |
| 302 posource2 = '''msgid "Old"\nmsgstr "Oud"\n''' | 301 posource2 = '''msgid "Old"\nmsgstr "Oud"\n''' |
| 303 newpo = self.convertpot(potsource, posource) | 302 newpo = self.convertpot(potsource, posource) |
| 304 assert len(newpo.units) == 3 | 303 assert len(newpo.units) == 3 |
| 305 assert newpo.units[0].isheader() | 304 assert newpo.units[0].isheader() |
| 306 assert newpo.units[2].isobsolete() | 305 assert newpo.units[2].isobsolete() |
| 307 assert str(newpo.units[1]) == potsource | 306 assert str(newpo.units[1]) == potsource |
| 308 assert str(newpo.units[2]) == posource | 307 assert str(newpo.units[2]) == posource |
| 309 | 308 |
| 310 def test_merging_resurect_obsolete_messages(self): | 309 def test_merging_resurect_obsolete_messages(self): |
| 311 """check that we can reuse old obsolete messages if the message comes ba
ck""" | 310 """check that we can reuse old obsolete messages if the message comes ba
ck""" |
| 312 potsource = '''#: resurect.c\nmsgid "&About"\nmsgstr ""\n''' | 311 potsource = '''#: resurect.c:1\nmsgid "&About"\nmsgstr ""\n''' |
| 313 posource = '''#~ msgid "&About"\n#~ msgstr "&Omtrent"\n''' | 312 posource = '''#~ msgid "&About"\n#~ msgstr "&Omtrent"\n''' |
| 314 expected = '''#: resurect.c\nmsgid "&About"\nmsgstr "&Omtrent"\n''' | 313 expected = '''#: resurect.c:1\nmsgid "&About"\nmsgstr "&Omtrent"\n''' |
| 315 newpo = self.convertpot(potsource, posource) | 314 newpo = self.convertpot(potsource, posource) |
| 316 print newpo | 315 print newpo |
| 317 assert len(newpo.units) == 2 | 316 assert len(newpo.units) == 2 |
| 318 assert newpo.units[0].isheader() | 317 assert newpo.units[0].isheader() |
| 319 newpounit = self.singleunit(newpo) | 318 newpounit = self.singleunit(newpo) |
| 320 assert str(newpounit) == expected | 319 assert str(newpounit) == expected |
| 321 | 320 |
| 322 def test_merging_resurect_obsolete_messages_into_msgidcomment(self): | 321 def test_merging_resurect_obsolete_messages_into_msgidcomment(self): |
| 323 """check that we can reuse old obsolete messages even if the recipient h
as a msgidcomment""" | 322 """check that we can reuse old obsolete messages even if the recipient h
as a msgidcomment""" |
| 324 potsource = '''#: resurect1.c\nmsgid ""\n"_: resurect1.c\\n"\n"About"\nm
sgstr ""\n\n''' + \ | 323 potsource = '''#: resurect1.c:1\nmsgid ""\n"_: resurect1.c\\n"\n"About"\
nmsgstr ""\n\n''' + \ |
| 325 '''#: resurect2.c\nmsgid ""\n"_: resurect2.c\\n"\n"About"\nm
sgstr ""\n''' | 324 '''#: resurect2.c:2\nmsgid ""\n"_: resurect2.c\\n"\n"About"\
nmsgstr ""\n''' |
| 326 posource = '''#~ msgid "About"\n#~ msgstr "Omtrent"\n''' | 325 posource = '''#~ msgid "About"\n#~ msgstr "Omtrent"\n''' |
| 327 expected1 = '''#: resurect1.c\nmsgid ""\n"_: resurect1.c\\n"\n"About"\nm
sgstr "Omtrent"\n''' | 326 expected1 = '''#: resurect1.c:1\nmsgid ""\n"_: resurect1.c\\n"\n"About"\
nmsgstr "Omtrent"\n''' |
| 328 expected2 = '''#: resurect2.c\nmsgid ""\n"_: resurect2.c\\n"\n"About"\nm
sgstr "Omtrent"\n''' | 327 expected2 = '''#: resurect2.c:2\nmsgid ""\n"_: resurect2.c\\n"\n"About"\
nmsgstr "Omtrent"\n''' |
| 329 newpo = self.convertpot(potsource, posource) | 328 newpo = self.convertpot(potsource, posource) |
| 330 print newpo | 329 print newpo |
| 331 assert len(newpo.units) == 3 | 330 assert len(newpo.units) == 3 |
| 332 assert newpo.units[0].isheader() | 331 assert newpo.units[0].isheader() |
| 333 assert str(newpo.units[1]) == expected1 | 332 assert str(newpo.units[1]) == expected1 |
| 334 assert str(newpo.units[2]) == expected2 | 333 assert str(newpo.units[2]) == expected2 |
| 335 | 334 |
| 336 def test_header_initialisation(self): | 335 def test_header_initialisation(self): |
| 337 """test to check that we initialise the header correctly""" | 336 """test to check that we initialise the header correctly""" |
| 338 potsource = r'''#, fuzzy | 337 potsource = r'''#, fuzzy |
| 339 msgid "" | 338 msgid "" |
| 340 msgstr "" | 339 msgstr "" |
| 341 "Project-Id-Version: PACKAGE VERSION\n" | 340 "Project-Id-Version: PACKAGE VERSION\n" |
| 342 "Report-Msgid-Bugs-To: new@example.com\n" | 341 "Report-Msgid-Bugs-To: new@example.com\n" |
| 343 "POT-Creation-Date: 2006-11-11 11:11+0000\n" | 342 "POT-Creation-Date: 2006-11-11 11:11+0000\n" |
| 344 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" | 343 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" |
| 345 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" | 344 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" |
| 346 "Language-Team: LANGUAGE <LL@li.org>\n" | 345 "Language-Team: LANGUAGE <LL@li.org>\n" |
| 347 "MIME-Version: 1.0\n" | 346 "MIME-Version: 1.0\n" |
| 348 "Content-Type: text/plain; charset=UTF-8\n" | 347 "Content-Type: text/plain; charset=UTF-8\n" |
| 349 "Content-Transfer-Encoding: 8bit\n" | 348 "Content-Transfer-Encoding: 8bit\n" |
| 350 "Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n" | 349 "Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n" |
| 351 "X-Generator: Translate Toolkit 0.10rc2\n" | 350 "X-Generator: Translate Toolkit 0.10rc2\n" |
| 352 ''' | 351 ''' |
| 353 posource = r'''msgid "" | 352 posource = r'''msgid "" |
| 354 msgstr "" | 353 msgstr "" |
| 355 "Project-Id-Version: Pootle 0.10\n" | 354 "Project-Id-Version: Pootle 0.10\n" |
| 356 "Report-Msgid-Bugs-To: old@example.com\n" | 355 "Report-Msgid-Bugs-To: old@example.com\n" |
| 357 "POT-Creation-Date: 2006-01-01 01:01+0100\n" | 356 "POT-Creation-Date: 2006-01-01 01:01+0100\n" |
| 358 "PO-Revision-Date: 2006-09-09 09:09+0900\n" | 357 "PO-Revision-Date: 2006-09-09 09:09+0900\n" |
| 359 "Last-Translator: Joe Translate <joe@example.com>\n" | 358 "Last-Translator: Joe Translate <joe@example.com>\n" |
| 360 "Language-Team: Pig Latin <piglatin@example.com>\n" | 359 "Language-Team: Pig Latin <piglatin@example.com>\n" |
| 361 "MIME-Version: 1.0\n" | 360 "MIME-Version: 1.0\n" |
| 362 "Content-Type: text/plain; charset=UTF-8\n" | 361 "Content-Type: text/plain; charset=UTF-8\n" |
| 363 "Content-Transfer-Encoding: 8bit\n" | 362 "Content-Transfer-Encoding: 8bit\n" |
| 364 "Plural-Forms: nplurals=2; plural=(n != 1);\n" | 363 "Plural-Forms: nplurals=2; plural=(n != 1);\n" |
| 365 "X-Generator: Translate Toolkit 0.9\n" | 364 "X-Generator: Translate Toolkit 0.9\n" |
| 366 ''' | 365 ''' |
| 367 expected = r'''msgid "" | 366 expected = r'''msgid "" |
| 368 msgstr "" | 367 msgstr "" |
| 369 "Project-Id-Version: Pootle 0.10\n" | 368 "Project-Id-Version: Pootle 0.10\n" |
| 370 "Report-Msgid-Bugs-To: new@example.com\n" | 369 "Report-Msgid-Bugs-To: new@example.com\n" |
| 371 "POT-Creation-Date: 2006-11-11 11:11+0000\n" | 370 "POT-Creation-Date: 2006-11-11 11:11+0000\n" |
| 372 "PO-Revision-Date: 2006-09-09 09:09+0900\n" | 371 "PO-Revision-Date: 2006-09-09 09:09+0900\n" |
| 373 "Last-Translator: Joe Translate <joe@example.com>\n" | 372 "Last-Translator: Joe Translate <joe@example.com>\n" |
| 374 "Language-Team: Pig Latin <piglatin@example.com>\n" | 373 "Language-Team: Pig Latin <piglatin@example.com>\n" |
| 375 "MIME-Version: 1.0\n" | 374 "MIME-Version: 1.0\n" |
| 376 "Content-Type: text/plain; charset=UTF-8\n" | 375 "Content-Type: text/plain; charset=UTF-8\n" |
| 377 "Content-Transfer-Encoding: 8bit\n" | 376 "Content-Transfer-Encoding: 8bit\n" |
| 378 "Plural-Forms: nplurals=2; plural=(n != 1);\n" | 377 "Plural-Forms: nplurals=2; plural=(n != 1);\n" |
| 379 "X-Generator: Translate Toolkit 0.10rc2\n" | 378 "X-Generator: Translate Toolkit 0.10rc2\n" |
| 380 ''' | 379 ''' |
| 381 newpo = self.convertpot(potsource, posource) | 380 newpo = self.convertpot(potsource, posource) |
| 382 print 'Output Header:\n%s' % newpo | 381 print 'Output Header:\n%s' % newpo |
| 383 print 'Expected Header:\n%s' % expected | 382 print 'Expected Header:\n%s' % expected |
| 384 assert str(newpo) == expected | 383 assert str(newpo) == expected |
| 385 | 384 |
| 386 def test_merging_comments(self): | 385 def test_merging_comments(self): |
| 387 """Test that we can merge comments correctly""" | 386 """Test that we can merge comments correctly""" |
| 388 potsource = '''#. Don't do it!\n#: file.py:1\nmsgid "One"\nmsgstr ""\n''
' | 387 potsource = '''#. Don't do it!\n#: file.py:1\nmsgid "One"\nmsgstr ""\n''
' |
| 389 posource = '''#. Don't do it!\n#: file.py:2\nmsgid "One"\nmsgstr "Een"\n
''' | 388 posource = '''#. Don't do it!\n#: file.py:2\nmsgid "One"\nmsgstr "Een"\n
''' |
| 390 poexpected = '''#. Don't do it!\n#: file.py:1\nmsgid "One"\nmsgstr "Een"
\n''' | 389 poexpected = '''#. Don't do it!\n#: file.py:1\nmsgid "One"\nmsgstr "Een"
\n''' |
| 391 newpo = self.convertpot(potsource, posource) | 390 newpo = self.convertpot(potsource, posource) |
| 392 print newpo | 391 print newpo |
| 393 newpounit = self.singleunit(newpo) | 392 newpounit = self.singleunit(newpo) |
| 394 assert str(newpounit) == poexpected | 393 assert str(newpounit) == poexpected |
| 395 | 394 |
| 396 def test_merging_typecomments(self): | 395 def test_merging_typecomments(self): |
| 397 """Test that we can merge with typecomments""" | 396 """Test that we can merge with typecomments""" |
| 398 potsource = '''#: file.c:1\n#, c-format\nmsgid "%d pipes"\nmsgstr ""\n''
' | 397 potsource = '''#: file.c:1\n#, c-format\nmsgid "%d pipes"\nmsgstr ""\n''
' |
| 399 posource = '''#: file.c:2\nmsgid "%d pipes"\nmsgstr "%d pype"\n''' | 398 posource = '''#: file.c:2\nmsgid "%d pipes"\nmsgstr "%d pype"\n''' |
| 400 poexpected = '''#: file.c:1\n#, c-format\nmsgid "%d pipes"\nmsgstr "%d p
ype"\n''' | 399 poexpected = '''#: file.c:1\n#, c-format\nmsgid "%d pipes"\nmsgstr "%d p
ype"\n''' |
| 401 newpo = self.convertpot(potsource, posource) | 400 newpo = self.convertpot(potsource, posource) |
| 402 newpounit = self.singleunit(newpo) | 401 newpounit = self.singleunit(newpo) |
| 403 print newpounit | 402 print newpounit |
| 404 assert str(newpounit) == poexpected | 403 assert str(newpounit) == poexpected |
| 405 | 404 |
| 406 potsource = '''#: file.c:1\n#, c-format\nmsgid "%d computers"\nmsgstr ""
\n''' | 405 potsource = '''#: file.c:1\n#, c-format\nmsgid "%d computers"\nmsgstr ""
\n''' |
| 407 posource = '''#: file.c:2\n#, c-format\nmsgid "%s computers "\nmsgstr "%
s-rekenaars"\n''' | 406 posource = '''#: file.c:2\n#, c-format\nmsgid "%s computers "\nmsgstr "%
s-rekenaars"\n''' |
| 408 poexpected = '''#: file.c:1\n#, fuzzy, c-format\nmsgid "%d computers"\nm
sgstr "%s-rekenaars"\n''' | 407 poexpected = '''#: file.c:1\n#, fuzzy, c-format\nmsgid "%d computers"\nm
sgstr "%s-rekenaars"\n''' |
| 409 newpo = self.convertpot(potsource, posource) | 408 newpo = self.convertpot(potsource, posource) |
| 410 newpounit = self.singleunit(newpo) | 409 newpounit = self.singleunit(newpo) |
| 411 assert newpounit.isfuzzy() | 410 assert newpounit.isfuzzy() |
| 412 assert newpounit.hastypecomment("c-format") | 411 assert newpounit.hastypecomment("c-format") |
| 413 | 412 |
| 414 class TestPOT2POCommand(test_convert.TestConvertCommand, TestPOT2PO): | 413 class TestPOT2POCommand(test_convert.TestConvertCommand, TestPOT2PO): |
| 415 """Tests running actual pot2po commands on files""" | 414 """Tests running actual pot2po commands on files""" |
| 416 convertmodule = pot2po | 415 convertmodule = pot2po |
| 417 | 416 |
| 418 def test_help(self): | 417 def test_help(self): |
| 419 """tests getting help""" | 418 """tests getting help""" |
| 420 options = test_convert.TestConvertCommand.test_help(self) | 419 options = test_convert.TestConvertCommand.test_help(self) |
| 421 options = self.help_check(options, "-t TEMPLATE, --template=TEMPLATE") | 420 options = self.help_check(options, "-t TEMPLATE, --template=TEMPLATE") |
| 422 options = self.help_check(options, "-P, --pot") | 421 options = self.help_check(options, "-P, --pot") |
| 423 options = self.help_check(options, "--tm") | 422 options = self.help_check(options, "--tm") |
| 424 options = self.help_check(options, "-s MIN_SIMILARITY, --similarity=MIN_
SIMILARITY") | 423 options = self.help_check(options, "-s MIN_SIMILARITY, --similarity=MIN_
SIMILARITY") |
| 425 options = self.help_check(options, "--nofuzzymatching", last=True) | 424 options = self.help_check(options, "--nofuzzymatching", last=True) |
| 426 | 425 |
| OLD | NEW |