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

Delta Between Two Patch Sets: translate/storage/test_cpo.py

Issue 65: xliff2po & po2xliff should handle context SVN Base: https://translate.svn.sourceforge.net/svnroot/translate/src/trunk/
Left Patch Set: Created 1 year, 4 months ago
Right Patch Set: A more complete patch, supporting CPO and pypo Created 1 year, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: View regular side by side diff
Right: View regular side by side diff
LEFTRIGHT
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 cpo 5 from translate.storage import cpo
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 TestCPOUnit(test_po.TestPOUnit): 10 class TestCPOUnit(test_po.TestPOUnit):
11 UnitClass = cpo.pounit 11 UnitClass = cpo.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 93 matching lines...) Show 10 above Show 10 below
144 # # check we don't add msgidcomments 144 # # check we don't add msgidcomments
145 # assert po.unquotefrompo(pofile.units[0].msgidcomments) == "" 145 # assert po.unquotefrompo(pofile.units[0].msgidcomments) == ""
146 # assert po.unquotefrompo(pofile.units[1].msgidcomments) == "" 146 # assert po.unquotefrompo(pofile.units[1].msgidcomments) == ""
147 147
148 def test_output_str_unicode(self): 148 def test_output_str_unicode(self):
149 """checks that we can str(pofile) which is in unicode""" 149 """checks that we can str(pofile) which is in unicode"""
150 posource = u'''#: nb\nmsgid "Norwegian Bokm\xe5l"\nmsgstr ""\n''' 150 posource = u'''#: nb\nmsgid "Norwegian Bokm\xe5l"\nmsgstr ""\n'''
151 pofile = self.StoreClass(wStringIO.StringIO(posource.encode("UTF-8")), e ncoding="UTF-8") 151 pofile = self.StoreClass(wStringIO.StringIO(posource.encode("UTF-8")), e ncoding="UTF-8")
152 assert len(pofile.units) == 1 152 assert len(pofile.units) == 1
153 print str(pofile) 153 print str(pofile)
154 thepo = pofile.units[0] 154 thepo = pofile.units[0]
155 # assert str(pofile) == posource.encode("UTF-8") 155 # assert str(pofile) == posource.encode("UTF-8")
156 # extra test: what if we set the msgid to a unicode? this happens in pro p2po etc 156 # extra test: what if we set the msgid to a unicode? this happens in pro p2po etc
157 thepo.source = u"Norwegian Bokm\xe5l" 157 thepo.source = u"Norwegian Bokm\xe5l"
158 # assert str(thepo) == posource.encode("UTF-8") 158 # assert str(thepo) == posource.encode("UTF-8")
159 # Now if we set the msgstr to Unicode 159 # Now if we set the msgstr to Unicode
160 # this is an escaped half character (1/2) 160 # this is an escaped half character (1/2)
161 halfstr = "\xbd ...".decode("latin-1") 161 halfstr = "\xbd ...".decode("latin-1")
162 thepo.target = halfstr 162 thepo.target = halfstr
163 # assert halfstr in str(pofile).decode("UTF-8") 163 # assert halfstr in str(pofile).decode("UTF-8")
164 thepo.target = halfstr.encode("UTF-8") 164 thepo.target = halfstr.encode("UTF-8")
165 # assert halfstr.encode("UTF-8") in str(pofile) 165 # assert halfstr.encode("UTF-8") in str(pofile)
166 166
167 def test_posections(self): 167 def test_posections(self):
168 """checks the content of all the expected sections of a PO message""" 168 """checks the content of all the expected sections of a PO message"""
169 posource = '# other comment\n#. automatic comment\n#: source comment\n#, fuzzy\nmsgid "One"\nmsgstr "Een"\n' 169 posource = '# other comment\n#. automatic comment\n#: source comment\n#, fuzzy\nmsgid "One"\nmsgstr "Een"\n'
170 pofile = self.poparse(posource) 170 pofile = self.poparse(posource)
171 print pofile 171 print pofile
172 assert len(pofile.units) == 1 172 assert len(pofile.units) == 1
173 assert str(pofile) == posource 173 assert str(pofile) == posource
174 174
175 def test_multiline_obsolete(self): 175 def test_multiline_obsolete(self):
176 """Tests for correct output of mulitline obsolete messages""" 176 """Tests for correct output of mulitline obsolete messages"""
177 posource = '#~ msgid ""\n#~ "Old thing\\n"\n#~ "Second old thing"\n#~ ms gstr ""\n#~ "Ou ding\\n"\n#~ "Tweede ou ding"\n' 177 posource = '#~ msgid ""\n#~ "Old thing\\n"\n#~ "Second old thing"\n#~ ms gstr ""\n#~ "Ou ding\\n"\n#~ "Tweede ou ding"\n'
178 pofile = self.poparse(posource) 178 pofile = self.poparse(posource)
179 print "Source:\n%s" % posource 179 print "Source:\n%s" % posource
180 print "Output:\n%s" % str(pofile) 180 print "Output:\n%s" % str(pofile)
181 assert len(pofile.units) == 1 181 assert len(pofile.units) == 1
182 assert pofile.units[0].isobsolete() 182 assert pofile.units[0].isobsolete()
183 assert not pofile.units[0].istranslatable() 183 assert not pofile.units[0].istranslatable()
184 assert str(pofile) == posource 184 assert str(pofile) == posource
185 185
186 def test_unassociated_comments(self): 186 def test_unassociated_comments(self):
187 """tests behaviour of unassociated comments.""" 187 """tests behaviour of unassociated comments."""
188 oldsource = '# old lonesome comment\n\nmsgid "one"\nmsgstr "een"\n' 188 oldsource = '# old lonesome comment\n\nmsgid "one"\nmsgstr "een"\n'
189 oldfile = self.poparse(oldsource) 189 oldfile = self.poparse(oldsource)
190 print "__str__", str(oldfile) 190 print "__str__", str(oldfile)
191 assert len(oldfile.units) == 1 191 assert len(oldfile.units) == 1
192 assert str(oldfile).find("# old lonesome comment\nmsgid") >= 0 192 assert str(oldfile).find("# old lonesome comment\nmsgid") >= 0
193 193
LEFTRIGHT

Powered by Google App Engine
This is Rietveld r159