| LEFT | RIGHT |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # -*- coding: utf-8 -*- | 2 # -*- coding: utf-8 -*- |
| 3 | 3 |
| 4 from translate.storage import test_po | 4 from translate.storage import test_po |
| 5 from translate.storage import pypo | 5 from translate.storage import pypo |
| 6 from translate.misc.multistring import multistring | 6 from translate.misc.multistring import multistring |
| 7 from translate.misc import wStringIO | 7 from translate.misc import wStringIO |
| 8 from py.test import raises | 8 from py.test import raises |
| 9 | 9 |
| 10 class TestPYPOUnit(test_po.TestPOUnit): | 10 class TestPYPOUnit(test_po.TestPOUnit): |
| 11 UnitClass = pypo.pounit | 11 UnitClass = pypo.pounit |
| 12 | 12 |
| 13 def test_plurals(self): | 13 def test_plurals(self): |
| 14 """Tests that plurals are handled correctly.""" | 14 """Tests that plurals are handled correctly.""" |
| 15 unit = self.UnitClass("Cow") | 15 unit = self.UnitClass("Cow") |
| 16 unit.msgid_plural = ['"Cows"'] | 16 unit.msgid_plural = ['"Cows"'] |
| 17 assert isinstance(unit.source, multistring) | 17 assert isinstance(unit.source, multistring) |
| 18 assert unit.source.strings == ["Cow", "Cows"] | 18 assert unit.source.strings == ["Cow", "Cows"] |
| 19 assert unit.source == "Cow" | 19 assert unit.source == "Cow" |
| 20 | 20 |
| 21 unit.target = ["Koei", "Koeie"] | 21 unit.target = ["Koei", "Koeie"] |
| 22 assert isinstance(unit.target, multistring) | 22 assert isinstance(unit.target, multistring) |
| 23 assert unit.target.strings == ["Koei", "Koeie"] | 23 assert unit.target.strings == ["Koei", "Koeie"] |
| 24 assert unit.target == "Koei" | 24 assert unit.target == "Koei" |
| 25 | 25 |
| 26 unit.target = {0:"Koei", 3:"Koeie"} | 26 unit.target = {0:"Koei", 3:"Koeie"} |
| 27 assert isinstance(unit.target, multistring) | 27 assert isinstance(unit.target, multistring) |
| 28 assert unit.target.strings == ["Koei", "Koeie"] | 28 assert unit.target.strings == ["Koei", "Koeie"] |
| 29 assert unit.target == "Koei" | 29 assert unit.target == "Koei" |
| 30 | 30 |
| 31 unit.target = [u"Sk\u00ear", u"Sk\u00eare"] | 31 unit.target = [u"Sk\u00ear", u"Sk\u00eare"] |
| 32 assert isinstance(unit.target, multistring) | 32 assert isinstance(unit.target, multistring) |
| 33 assert unit.target.strings == [u"Sk\u00ear", u"Sk\u00eare"] | 33 assert unit.target.strings == [u"Sk\u00ear", u"Sk\u00eare"] |
| 34 assert unit.target.strings == [u"Sk\u00ear", u"Sk\u00eare"] | 34 assert unit.target.strings == [u"Sk\u00ear", u"Sk\u00eare"] |
| 35 assert unit.target == u"Sk\u00ear" | 35 assert unit.target == u"Sk\u00ear" |
| 36 | 36 |
| 37 def test_plural_reduction(self): | 37 def test_plural_reduction(self): |
| 38 """checks that reducing the number of plurals supplied works""" | 38 """checks that reducing the number of plurals supplied works""" |
| 39 unit = self.UnitClass("Tree") | 39 unit = self.UnitClass("Tree") |
| 40 unit.msgid_plural = ['"Trees"'] | 40 unit.msgid_plural = ['"Trees"'] |
| 41 assert isinstance(unit.source, multistring) | 41 assert isinstance(unit.source, multistring) |
| 42 assert unit.source.strings == ["Tree", "Trees"] | 42 assert unit.source.strings == ["Tree", "Trees"] |
| 43 unit.target = multistring(["Boom", "Bome", "Baie Bome"]) | 43 unit.target = multistring(["Boom", "Bome", "Baie Bome"]) |
| 44 assert isinstance(unit.source, multistring) | 44 assert isinstance(unit.source, multistring) |
| 45 assert unit.target.strings == ["Boom", "Bome", "Baie Bome"] | 45 assert unit.target.strings == ["Boom", "Bome", "Baie Bome"] |
| 46 unit.target = multistring(["Boom", "Bome"]) | 46 unit.target = multistring(["Boom", "Bome"]) |
| 47 assert unit.target.strings == ["Boom", "Bome"] | 47 assert unit.target.strings == ["Boom", "Bome"] |
| 48 unit.target = "Boom" | 48 unit.target = "Boom" |
| 49 # FIXME: currently assigning the target to the same as the first string
won't change anything | 49 # FIXME: currently assigning the target to the same as the first string
won't change anything |
| 50 # we need to verify that this is the desired behaviour... | 50 # we need to verify that this is the desired behaviour... |
| (...skipping 156 matching lines...) Show 10 above Show 10 below |
| 207 def test_keep_blanks(self): | 207 def test_keep_blanks(self): |
| 208 """checks that keeping keeps blanks and doesn't add msgid_comments""" | 208 """checks that keeping keeps blanks and doesn't add msgid_comments""" |
| 209 posource = '#: source1\nmsgid ""\nmsgstr ""\n\n#: source2\nmsgid ""\nmsg
str ""\n' | 209 posource = '#: source1\nmsgid ""\nmsgstr ""\n\n#: source2\nmsgid ""\nmsg
str ""\n' |
| 210 pofile = self.poparse(posource) | 210 pofile = self.poparse(posource) |
| 211 assert len(pofile.units) == 2 | 211 assert len(pofile.units) == 2 |
| 212 pofile.removeduplicates("keep") | 212 pofile.removeduplicates("keep") |
| 213 assert len(pofile.units) == 2 | 213 assert len(pofile.units) == 2 |
| 214 # check we don't add msgidcomments | 214 # check we don't add msgidcomments |
| 215 assert pypo.unquotefrompo(pofile.units[0].msgidcomments) == "" | 215 assert pypo.unquotefrompo(pofile.units[0].msgidcomments) == "" |
| 216 assert pypo.unquotefrompo(pofile.units[1].msgidcomments) == "" | 216 assert pypo.unquotefrompo(pofile.units[1].msgidcomments) == "" |
| 217 | 217 |
| 218 def test_output_str_unicode(self): | 218 def test_output_str_unicode(self): |
| 219 """checks that we can str(element) which is in unicode""" | 219 """checks that we can str(element) which is in unicode""" |
| 220 posource = u'''#: nb\nmsgid "Norwegian Bokm\xe5l"\nmsgstr ""\n''' | 220 posource = u'''#: nb\nmsgid "Norwegian Bokm\xe5l"\nmsgstr ""\n''' |
| 221 pofile = self.StoreClass(wStringIO.StringIO(posource.encode("UTF-8")), e
ncoding="UTF-8") | 221 pofile = self.StoreClass(wStringIO.StringIO(posource.encode("UTF-8")), e
ncoding="UTF-8") |
| 222 assert len(pofile.units) == 1 | 222 assert len(pofile.units) == 1 |
| 223 print str(pofile) | 223 print str(pofile) |
| 224 thepo = pofile.units[0] | 224 thepo = pofile.units[0] |
| 225 assert str(thepo) == posource.encode("UTF-8") | 225 assert str(thepo) == posource.encode("UTF-8") |
| 226 # extra test: what if we set the msgid to a unicode? this happens in pro
p2po etc | 226 # extra test: what if we set the msgid to a unicode? this happens in pro
p2po etc |
| 227 thepo.source = u"Norwegian Bokm\xe5l" | 227 thepo.source = u"Norwegian Bokm\xe5l" |
| 228 assert str(thepo) == posource.encode("UTF-8") | 228 assert str(thepo) == posource.encode("UTF-8") |
| 229 # Now if we set the msgstr to Unicode | 229 # Now if we set the msgstr to Unicode |
| 230 # this is an escaped half character (1/2) | 230 # this is an escaped half character (1/2) |
| 231 halfstr = "\xbd ...".decode("latin-1") | 231 halfstr = "\xbd ...".decode("latin-1") |
| 232 thepo.target = halfstr | 232 thepo.target = halfstr |
| 233 assert halfstr in str(thepo).decode("UTF-8") | 233 assert halfstr in str(thepo).decode("UTF-8") |
| 234 thepo.target = halfstr.encode("UTF-8") | 234 thepo.target = halfstr.encode("UTF-8") |
| 235 assert halfstr.encode("UTF-8") in str(thepo) | 235 assert halfstr.encode("UTF-8") in str(thepo) |
| 236 | 236 |
| 237 def test_posections(self): | 237 def test_posections(self): |
| 238 """checks the content of all the expected sections of a PO message""" | 238 """checks the content of all the expected sections of a PO message""" |
| 239 posource = '# other comment\n#. automatic comment\n#: source comment\n#,
fuzzy\nmsgid "One"\nmsgstr "Een"\n' | 239 posource = '# other comment\n#. automatic comment\n#: source comment\n#,
fuzzy\nmsgid "One"\nmsgstr "Een"\n' |
| 240 pofile = self.poparse(posource) | 240 pofile = self.poparse(posource) |
| 241 print pofile | 241 print pofile |
| 242 assert len(pofile.units) == 1 | 242 assert len(pofile.units) == 1 |
| 243 assert str(pofile) == posource | 243 assert str(pofile) == posource |
| 244 assert pofile.units[0].othercomments == ["# other comment\n"] | 244 assert pofile.units[0].othercomments == ["# other comment\n"] |
| 245 assert pofile.units[0].automaticcomments == ["#. automatic comment\n"] | 245 assert pofile.units[0].automaticcomments == ["#. automatic comment\n"] |
| 246 assert pofile.units[0].sourcecomments == ["#: source comment\n"] | 246 assert pofile.units[0].sourcecomments == ["#: source comment\n"] |
| 247 assert pofile.units[0].typecomments == ["#, fuzzy\n"] | 247 assert pofile.units[0].typecomments == ["#, fuzzy\n"] |
| 248 | 248 |
| 249 def test_unassociated_comments(self): | 249 def test_unassociated_comments(self): |
| 250 """tests behaviour of unassociated comments.""" | 250 """tests behaviour of unassociated comments.""" |
| 251 oldsource = '# old lonesome comment\n\nmsgid "one"\nmsgstr "een"\n' | 251 oldsource = '# old lonesome comment\n\nmsgid "one"\nmsgstr "een"\n' |
| 252 oldfile = self.poparse(oldsource) | 252 oldfile = self.poparse(oldsource) |
| 253 print "__str__", str(oldfile) | 253 print "__str__", str(oldfile) |
| 254 assert len(oldfile.units) == 2 | 254 assert len(oldfile.units) == 2 |
| 255 assert str(oldfile).find("# old lonesome comment\n\n") >= 0 | 255 assert str(oldfile).find("# old lonesome comment\n\n") >= 0 |
| 256 | 256 |
| LEFT | RIGHT |