1
2
3
4 from translate.storage import test_po
5 from translate.storage import cpo
6 from translate.misc.multistring import multistring
7 from translate.misc import wStringIO
8 from py.test import raises
9
11 UnitClass = cpo.pounit
12
14 """Tests that plurals are handled correctly."""
15 unit = self.UnitClass("Cow")
16 unit.msgid_plural = ["Cows"]
17 assert isinstance(unit.source, multistring)
18 assert unit.source.strings == ["Cow", "Cows"]
19 assert unit.source == "Cow"
20
21 unit.target = ["Koei", "Koeie"]
22 assert isinstance(unit.target, multistring)
23 assert unit.target.strings == ["Koei", "Koeie"]
24 assert unit.target == "Koei"
25
26 unit.target = {0:"Koei", 3:"Koeie"}
27 assert isinstance(unit.target, multistring)
28 assert unit.target.strings == ["Koei", "Koeie"]
29 assert unit.target == "Koei"
30
31 unit.target = [u"Sk\u00ear", u"Sk\u00eare"]
32 assert isinstance(unit.target, multistring)
33 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"
36
38 """checks that reducing the number of plurals supplied works"""
39 unit = self.UnitClass("Tree")
40 unit.msgid_plural = ["Trees"]
41 assert isinstance(unit.source, multistring)
42 assert unit.source.strings == ["Tree", "Trees"]
43 unit.target = multistring(["Boom", "Bome", "Baie Bome"])
44 assert isinstance(unit.source, multistring)
45 assert unit.target.strings == ["Boom", "Bome", "Baie Bome"]
46 unit.target = multistring(["Boom", "Bome"])
47 assert unit.target.strings == ["Boom", "Bome"]
48 unit.target = "Boom"
49
50
51 assert unit.target.strings == ["Boom", "Bome"]
52 unit.target = "Een Boom"
53 assert unit.target.strings == ["Een Boom"]
54
56 """tests that the generic notes API works"""
57 unit = self.UnitClass("File")
58 assert unit.getnotes() == ""
59 unit.addnote("Which meaning of file?")
60 assert unit.getnotes("translator") == "Which meaning of file?"
61 assert unit.getnotes("developer") == ""
62 unit.addnote("Verb", origin="programmer")
63 assert unit.getnotes("developer") == "Verb"
64 unit.addnote("Thank you", origin="translator")
65 assert unit.getnotes("translator") == "Which meaning of file?\nThank you"
66 assert unit.getnotes() == "Which meaning of file?\nThank you\nVerb"
67 assert raises(ValueError, unit.getnotes, "devteam")
68
74
76 StoreClass = cpo.pofile
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
138 """checks that we can str(pofile) which is in unicode"""
139 posource = u'''#: nb\nmsgid "Norwegian Bokm\xe5l"\nmsgstr ""\n'''
140 pofile = self.StoreClass(wStringIO.StringIO(posource.encode("UTF-8")), encoding="UTF-8")
141 assert len(pofile.units) == 1
142 print str(pofile)
143 thepo = pofile.units[0]
144
145
146 thepo.source = u"Norwegian Bokm\xe5l"
147
148
149
150 halfstr = "\xbd ...".decode("latin-1")
151 thepo.target = halfstr
152
153 thepo.target = halfstr.encode("UTF-8")
154
155
157 """checks the content of all the expected sections of a PO message"""
158 posource = '# other comment\n#. automatic comment\n#: source comment\n#, fuzzy\nmsgid "One"\nmsgstr "Een"\n'
159 pofile = self.poparse(posource)
160 print pofile
161 assert len(pofile.units) == 1
162 assert str(pofile) == posource
163
165 """Tests for correct output of mulitline obsolete messages"""
166 posource = '#~ msgid ""\n#~ "Old thing\\n"\n#~ "Second old thing"\n#~ msgstr ""\n#~ "Ou ding\\n"\n#~ "Tweede ou ding"\n'
167 pofile = self.poparse(posource)
168 print "Source:\n%s" % posource
169 print "Output:\n%s" % str(pofile)
170 assert len(pofile.units) == 1
171 assert pofile.units[0].isobsolete()
172 assert not pofile.units[0].istranslatable()
173 assert str(pofile) == posource
174
182