Mercurial > babel > old > babel-test
annotate babel/messages/tests/catalog.py @ 508:dbb70d75718a stable-0.9.x
Fix Python 2.3 compatibility for 0.9 branch (closes #233)
author | fschwarz |
---|---|
date | Fri, 04 Mar 2011 14:16:15 +0000 |
parents | 540e6652b785 |
children |
rev | line source |
---|---|
56
27fba894d3ca
Add actual data structures for handling message catalogs, so that more code can be reused here between the frontends.
cmlenz
parents:
diff
changeset
|
1 # -*- coding: utf-8 -*- |
27fba894d3ca
Add actual data structures for handling message catalogs, so that more code can be reused here between the frontends.
cmlenz
parents:
diff
changeset
|
2 # |
27fba894d3ca
Add actual data structures for handling message catalogs, so that more code can be reused here between the frontends.
cmlenz
parents:
diff
changeset
|
3 # Copyright (C) 2007 Edgewall Software |
27fba894d3ca
Add actual data structures for handling message catalogs, so that more code can be reused here between the frontends.
cmlenz
parents:
diff
changeset
|
4 # All rights reserved. |
27fba894d3ca
Add actual data structures for handling message catalogs, so that more code can be reused here between the frontends.
cmlenz
parents:
diff
changeset
|
5 # |
27fba894d3ca
Add actual data structures for handling message catalogs, so that more code can be reused here between the frontends.
cmlenz
parents:
diff
changeset
|
6 # This software is licensed as described in the file COPYING, which |
27fba894d3ca
Add actual data structures for handling message catalogs, so that more code can be reused here between the frontends.
cmlenz
parents:
diff
changeset
|
7 # you should have received as part of this distribution. The terms |
27fba894d3ca
Add actual data structures for handling message catalogs, so that more code can be reused here between the frontends.
cmlenz
parents:
diff
changeset
|
8 # are also available at http://babel.edgewall.org/wiki/License. |
27fba894d3ca
Add actual data structures for handling message catalogs, so that more code can be reused here between the frontends.
cmlenz
parents:
diff
changeset
|
9 # |
27fba894d3ca
Add actual data structures for handling message catalogs, so that more code can be reused here between the frontends.
cmlenz
parents:
diff
changeset
|
10 # This software consists of voluntary contributions made by many |
27fba894d3ca
Add actual data structures for handling message catalogs, so that more code can be reused here between the frontends.
cmlenz
parents:
diff
changeset
|
11 # individuals. For the exact contribution history, see the revision |
27fba894d3ca
Add actual data structures for handling message catalogs, so that more code can be reused here between the frontends.
cmlenz
parents:
diff
changeset
|
12 # history and logs, available at http://babel.edgewall.org/log/. |
27fba894d3ca
Add actual data structures for handling message catalogs, so that more code can be reused here between the frontends.
cmlenz
parents:
diff
changeset
|
13 |
452 | 14 import copy |
472 | 15 import datetime |
56
27fba894d3ca
Add actual data structures for handling message catalogs, so that more code can be reused here between the frontends.
cmlenz
parents:
diff
changeset
|
16 import doctest |
27fba894d3ca
Add actual data structures for handling message catalogs, so that more code can be reused here between the frontends.
cmlenz
parents:
diff
changeset
|
17 import unittest |
27fba894d3ca
Add actual data structures for handling message catalogs, so that more code can be reused here between the frontends.
cmlenz
parents:
diff
changeset
|
18 |
27fba894d3ca
Add actual data structures for handling message catalogs, so that more code can be reused here between the frontends.
cmlenz
parents:
diff
changeset
|
19 from babel.messages import catalog |
27fba894d3ca
Add actual data structures for handling message catalogs, so that more code can be reused here between the frontends.
cmlenz
parents:
diff
changeset
|
20 |
27fba894d3ca
Add actual data structures for handling message catalogs, so that more code can be reused here between the frontends.
cmlenz
parents:
diff
changeset
|
21 |
27fba894d3ca
Add actual data structures for handling message catalogs, so that more code can be reused here between the frontends.
cmlenz
parents:
diff
changeset
|
22 class MessageTestCase(unittest.TestCase): |
27fba894d3ca
Add actual data structures for handling message catalogs, so that more code can be reused here between the frontends.
cmlenz
parents:
diff
changeset
|
23 |
27fba894d3ca
Add actual data structures for handling message catalogs, so that more code can be reused here between the frontends.
cmlenz
parents:
diff
changeset
|
24 def test_python_format(self): |
220
677147547e2d
Added infrastructure for adding catalog checkers, and implement a checker that validations Python format parameters in translations, closing #19.
cmlenz
parents:
200
diff
changeset
|
25 assert catalog.PYTHON_FORMAT.search('foo %d bar') |
677147547e2d
Added infrastructure for adding catalog checkers, and implement a checker that validations Python format parameters in translations, closing #19.
cmlenz
parents:
200
diff
changeset
|
26 assert catalog.PYTHON_FORMAT.search('foo %s bar') |
677147547e2d
Added infrastructure for adding catalog checkers, and implement a checker that validations Python format parameters in translations, closing #19.
cmlenz
parents:
200
diff
changeset
|
27 assert catalog.PYTHON_FORMAT.search('foo %r bar') |
225
3703ded648ab
Applied patch by Ramiro Morales for more extensive detection of Python string formatting specifiers. Closes #57.
cmlenz
parents:
220
diff
changeset
|
28 assert catalog.PYTHON_FORMAT.search('foo %(name).1f') |
3703ded648ab
Applied patch by Ramiro Morales for more extensive detection of Python string formatting specifiers. Closes #57.
cmlenz
parents:
220
diff
changeset
|
29 assert catalog.PYTHON_FORMAT.search('foo %(name)3.3f') |
3703ded648ab
Applied patch by Ramiro Morales for more extensive detection of Python string formatting specifiers. Closes #57.
cmlenz
parents:
220
diff
changeset
|
30 assert catalog.PYTHON_FORMAT.search('foo %(name)3f') |
3703ded648ab
Applied patch by Ramiro Morales for more extensive detection of Python string formatting specifiers. Closes #57.
cmlenz
parents:
220
diff
changeset
|
31 assert catalog.PYTHON_FORMAT.search('foo %(name)06d') |
3703ded648ab
Applied patch by Ramiro Morales for more extensive detection of Python string formatting specifiers. Closes #57.
cmlenz
parents:
220
diff
changeset
|
32 assert catalog.PYTHON_FORMAT.search('foo %(name)Li') |
3703ded648ab
Applied patch by Ramiro Morales for more extensive detection of Python string formatting specifiers. Closes #57.
cmlenz
parents:
220
diff
changeset
|
33 assert catalog.PYTHON_FORMAT.search('foo %(name)#d') |
3703ded648ab
Applied patch by Ramiro Morales for more extensive detection of Python string formatting specifiers. Closes #57.
cmlenz
parents:
220
diff
changeset
|
34 assert catalog.PYTHON_FORMAT.search('foo %(name)-4.4hs') |
3703ded648ab
Applied patch by Ramiro Morales for more extensive detection of Python string formatting specifiers. Closes #57.
cmlenz
parents:
220
diff
changeset
|
35 assert catalog.PYTHON_FORMAT.search('foo %(name)*.3f') |
3703ded648ab
Applied patch by Ramiro Morales for more extensive detection of Python string formatting specifiers. Closes #57.
cmlenz
parents:
220
diff
changeset
|
36 assert catalog.PYTHON_FORMAT.search('foo %(name).*f') |
3703ded648ab
Applied patch by Ramiro Morales for more extensive detection of Python string formatting specifiers. Closes #57.
cmlenz
parents:
220
diff
changeset
|
37 assert catalog.PYTHON_FORMAT.search('foo %(name)3.*f') |
3703ded648ab
Applied patch by Ramiro Morales for more extensive detection of Python string formatting specifiers. Closes #57.
cmlenz
parents:
220
diff
changeset
|
38 assert catalog.PYTHON_FORMAT.search('foo %(name)*.*f') |
369 | 39 assert catalog.PYTHON_FORMAT.search('foo %()s') |
105
f744dd56573d
`Message`, `read_po` and `write_po` now all handle user/auto comments correctly.
palgarvio
parents:
95
diff
changeset
|
40 |
80
9c84b9fa5d30
Added support for translator comments at the API and frontends levels.(See #12, item 1). Updated docs and tests accordingly.
palgarvio
parents:
69
diff
changeset
|
41 def test_translator_comments(self): |
105
f744dd56573d
`Message`, `read_po` and `write_po` now all handle user/auto comments correctly.
palgarvio
parents:
95
diff
changeset
|
42 mess = catalog.Message('foo', user_comments=['Comment About `foo`']) |
200
2983c718f6e2
Added `--no-fuzzy-matching` to the frontends and also `--previous` which adds the old msgid's as comments. The latest closes #31.
palgarvio
parents:
181
diff
changeset
|
43 self.assertEqual(mess.user_comments, ['Comment About `foo`']) |
80
9c84b9fa5d30
Added support for translator comments at the API and frontends levels.(See #12, item 1). Updated docs and tests accordingly.
palgarvio
parents:
69
diff
changeset
|
44 mess = catalog.Message('foo', |
105
f744dd56573d
`Message`, `read_po` and `write_po` now all handle user/auto comments correctly.
palgarvio
parents:
95
diff
changeset
|
45 auto_comments=['Comment 1 About `foo`', |
80
9c84b9fa5d30
Added support for translator comments at the API and frontends levels.(See #12, item 1). Updated docs and tests accordingly.
palgarvio
parents:
69
diff
changeset
|
46 'Comment 2 About `foo`']) |
105
f744dd56573d
`Message`, `read_po` and `write_po` now all handle user/auto comments correctly.
palgarvio
parents:
95
diff
changeset
|
47 self.assertEqual(mess.auto_comments, ['Comment 1 About `foo`', |
80
9c84b9fa5d30
Added support for translator comments at the API and frontends levels.(See #12, item 1). Updated docs and tests accordingly.
palgarvio
parents:
69
diff
changeset
|
48 'Comment 2 About `foo`']) |
56
27fba894d3ca
Add actual data structures for handling message catalogs, so that more code can be reused here between the frontends.
cmlenz
parents:
diff
changeset
|
49 |
369 | 50 def test_clone_message_object(self): |
51 msg = catalog.Message('foo', locations=[('foo.py', 42)]) | |
52 clone = msg.clone() | |
53 clone.locations.append(('bar.py', 42)) | |
54 self.assertEqual(msg.locations, [('foo.py', 42)]) | |
55 msg.flags.add('fuzzy') | |
56 assert not clone.fuzzy and msg.fuzzy | |
57 | |
56
27fba894d3ca
Add actual data structures for handling message catalogs, so that more code can be reused here between the frontends.
cmlenz
parents:
diff
changeset
|
58 |
69
9b8079807245
Message catalogs can have multiple messages with the same ID, where some of them have plural strings, and others don't. Still the same message.
cmlenz
parents:
67
diff
changeset
|
59 class CatalogTestCase(unittest.TestCase): |
9b8079807245
Message catalogs can have multiple messages with the same ID, where some of them have plural strings, and others don't. Still the same message.
cmlenz
parents:
67
diff
changeset
|
60 |
9b8079807245
Message catalogs can have multiple messages with the same ID, where some of them have plural strings, and others don't. Still the same message.
cmlenz
parents:
67
diff
changeset
|
61 def test_two_messages_with_same_singular(self): |
9b8079807245
Message catalogs can have multiple messages with the same ID, where some of them have plural strings, and others don't. Still the same message.
cmlenz
parents:
67
diff
changeset
|
62 cat = catalog.Catalog() |
9b8079807245
Message catalogs can have multiple messages with the same ID, where some of them have plural strings, and others don't. Still the same message.
cmlenz
parents:
67
diff
changeset
|
63 cat.add('foo') |
9b8079807245
Message catalogs can have multiple messages with the same ID, where some of them have plural strings, and others don't. Still the same message.
cmlenz
parents:
67
diff
changeset
|
64 cat.add(('foo', 'foos')) |
9b8079807245
Message catalogs can have multiple messages with the same ID, where some of them have plural strings, and others don't. Still the same message.
cmlenz
parents:
67
diff
changeset
|
65 self.assertEqual(1, len(cat)) |
95
008cd3f7d485
Fix for #11 (use local timezone in timestamps of generated POT).
cmlenz
parents:
89
diff
changeset
|
66 |
227 | 67 def test_duplicate_auto_comment(self): |
228
fd29fabdc986
Follow-up to [239]: also combine duplicate comments when writing PO files.
cmlenz
parents:
227
diff
changeset
|
68 cat = catalog.Catalog() |
fd29fabdc986
Follow-up to [239]: also combine duplicate comments when writing PO files.
cmlenz
parents:
227
diff
changeset
|
69 cat.add('foo', auto_comments=['A comment']) |
fd29fabdc986
Follow-up to [239]: also combine duplicate comments when writing PO files.
cmlenz
parents:
227
diff
changeset
|
70 cat.add('foo', auto_comments=['A comment', 'Another comment']) |
fd29fabdc986
Follow-up to [239]: also combine duplicate comments when writing PO files.
cmlenz
parents:
227
diff
changeset
|
71 self.assertEqual(['A comment', 'Another comment'], |
fd29fabdc986
Follow-up to [239]: also combine duplicate comments when writing PO files.
cmlenz
parents:
227
diff
changeset
|
72 cat['foo'].auto_comments) |
227 | 73 |
74 def test_duplicate_user_comment(self): | |
228
fd29fabdc986
Follow-up to [239]: also combine duplicate comments when writing PO files.
cmlenz
parents:
227
diff
changeset
|
75 cat = catalog.Catalog() |
fd29fabdc986
Follow-up to [239]: also combine duplicate comments when writing PO files.
cmlenz
parents:
227
diff
changeset
|
76 cat.add('foo', user_comments=['A comment']) |
fd29fabdc986
Follow-up to [239]: also combine duplicate comments when writing PO files.
cmlenz
parents:
227
diff
changeset
|
77 cat.add('foo', user_comments=['A comment', 'Another comment']) |
fd29fabdc986
Follow-up to [239]: also combine duplicate comments when writing PO files.
cmlenz
parents:
227
diff
changeset
|
78 self.assertEqual(['A comment', 'Another comment'], |
fd29fabdc986
Follow-up to [239]: also combine duplicate comments when writing PO files.
cmlenz
parents:
227
diff
changeset
|
79 cat['foo'].user_comments) |
227 | 80 |
230 | 81 def test_duplicate_location(self): |
229 | 82 cat = catalog.Catalog() |
83 cat.add('foo', locations=[('foo.py', 1)]) | |
84 cat.add('foo', locations=[('foo.py', 1)]) | |
85 self.assertEqual([('foo.py', 1)], cat['foo'].locations) | |
86 | |
278 | 87 def test_update_message_changed_to_plural(self): |
88 cat = catalog.Catalog() | |
89 cat.add(u'foo', u'Voh') | |
90 tmpl = catalog.Catalog() | |
91 tmpl.add((u'foo', u'foos')) | |
92 cat.update(tmpl) | |
93 self.assertEqual((u'Voh', ''), cat['foo'].string) | |
94 assert cat['foo'].fuzzy | |
95 | |
96 def test_update_message_changed_to_simple(self): | |
97 cat = catalog.Catalog() | |
98 cat.add((u'foo' u'foos'), (u'Voh', u'Vöhs')) | |
99 tmpl = catalog.Catalog() | |
100 tmpl.add(u'foo') | |
101 cat.update(tmpl) | |
102 self.assertEqual(u'Voh', cat['foo'].string) | |
103 assert cat['foo'].fuzzy | |
104 | |
89
5a456b7ebc0a
Unittest for the problem reported by pjenvey fixed on [88].
palgarvio
parents:
80
diff
changeset
|
105 def test_update_message_updates_comments(self): |
5a456b7ebc0a
Unittest for the problem reported by pjenvey fixed on [88].
palgarvio
parents:
80
diff
changeset
|
106 cat = catalog.Catalog() |
5a456b7ebc0a
Unittest for the problem reported by pjenvey fixed on [88].
palgarvio
parents:
80
diff
changeset
|
107 cat[u'foo'] = catalog.Message('foo', locations=[('main.py', 5)]) |
105
f744dd56573d
`Message`, `read_po` and `write_po` now all handle user/auto comments correctly.
palgarvio
parents:
95
diff
changeset
|
108 self.assertEqual(cat[u'foo'].auto_comments, []) |
f744dd56573d
`Message`, `read_po` and `write_po` now all handle user/auto comments correctly.
palgarvio
parents:
95
diff
changeset
|
109 self.assertEqual(cat[u'foo'].user_comments, []) |
89
5a456b7ebc0a
Unittest for the problem reported by pjenvey fixed on [88].
palgarvio
parents:
80
diff
changeset
|
110 # Update cat[u'foo'] with a new location and a comment |
5a456b7ebc0a
Unittest for the problem reported by pjenvey fixed on [88].
palgarvio
parents:
80
diff
changeset
|
111 cat[u'foo'] = catalog.Message('foo', locations=[('main.py', 7)], |
105
f744dd56573d
`Message`, `read_po` and `write_po` now all handle user/auto comments correctly.
palgarvio
parents:
95
diff
changeset
|
112 user_comments=['Foo Bar comment 1']) |
f744dd56573d
`Message`, `read_po` and `write_po` now all handle user/auto comments correctly.
palgarvio
parents:
95
diff
changeset
|
113 self.assertEqual(cat[u'foo'].user_comments, ['Foo Bar comment 1']) |
89
5a456b7ebc0a
Unittest for the problem reported by pjenvey fixed on [88].
palgarvio
parents:
80
diff
changeset
|
114 # now add yet another location with another comment |
5a456b7ebc0a
Unittest for the problem reported by pjenvey fixed on [88].
palgarvio
parents:
80
diff
changeset
|
115 cat[u'foo'] = catalog.Message('foo', locations=[('main.py', 9)], |
200
2983c718f6e2
Added `--no-fuzzy-matching` to the frontends and also `--previous` which adds the old msgid's as comments. The latest closes #31.
palgarvio
parents:
181
diff
changeset
|
116 auto_comments=['Foo Bar comment 2']) |
105
f744dd56573d
`Message`, `read_po` and `write_po` now all handle user/auto comments correctly.
palgarvio
parents:
95
diff
changeset
|
117 self.assertEqual(cat[u'foo'].auto_comments, ['Foo Bar comment 2']) |
69
9b8079807245
Message catalogs can have multiple messages with the same ID, where some of them have plural strings, and others don't. Still the same message.
cmlenz
parents:
67
diff
changeset
|
118 |
165
650a6e996ede
Implement fuzzy matching to catalog updates. No frontend yet.
cmlenz
parents:
111
diff
changeset
|
119 def test_update_fuzzy_matching_with_case_change(self): |
650a6e996ede
Implement fuzzy matching to catalog updates. No frontend yet.
cmlenz
parents:
111
diff
changeset
|
120 cat = catalog.Catalog() |
650a6e996ede
Implement fuzzy matching to catalog updates. No frontend yet.
cmlenz
parents:
111
diff
changeset
|
121 cat.add('foo', 'Voh') |
650a6e996ede
Implement fuzzy matching to catalog updates. No frontend yet.
cmlenz
parents:
111
diff
changeset
|
122 cat.add('bar', 'Bahr') |
650a6e996ede
Implement fuzzy matching to catalog updates. No frontend yet.
cmlenz
parents:
111
diff
changeset
|
123 tmpl = catalog.Catalog() |
650a6e996ede
Implement fuzzy matching to catalog updates. No frontend yet.
cmlenz
parents:
111
diff
changeset
|
124 tmpl.add('Foo') |
181
9a1acb41e7dd
The frontends now provide ways to update existing translations catalogs from a template. Closes #22.
cmlenz
parents:
165
diff
changeset
|
125 cat.update(tmpl) |
9a1acb41e7dd
The frontends now provide ways to update existing translations catalogs from a template. Closes #22.
cmlenz
parents:
165
diff
changeset
|
126 self.assertEqual(1, len(cat.obsolete)) |
165
650a6e996ede
Implement fuzzy matching to catalog updates. No frontend yet.
cmlenz
parents:
111
diff
changeset
|
127 assert 'foo' not in cat |
650a6e996ede
Implement fuzzy matching to catalog updates. No frontend yet.
cmlenz
parents:
111
diff
changeset
|
128 |
650a6e996ede
Implement fuzzy matching to catalog updates. No frontend yet.
cmlenz
parents:
111
diff
changeset
|
129 self.assertEqual('Voh', cat['Foo'].string) |
650a6e996ede
Implement fuzzy matching to catalog updates. No frontend yet.
cmlenz
parents:
111
diff
changeset
|
130 self.assertEqual(True, cat['Foo'].fuzzy) |
650a6e996ede
Implement fuzzy matching to catalog updates. No frontend yet.
cmlenz
parents:
111
diff
changeset
|
131 |
650a6e996ede
Implement fuzzy matching to catalog updates. No frontend yet.
cmlenz
parents:
111
diff
changeset
|
132 def test_update_fuzzy_matching_with_char_change(self): |
650a6e996ede
Implement fuzzy matching to catalog updates. No frontend yet.
cmlenz
parents:
111
diff
changeset
|
133 cat = catalog.Catalog() |
650a6e996ede
Implement fuzzy matching to catalog updates. No frontend yet.
cmlenz
parents:
111
diff
changeset
|
134 cat.add('fo', 'Voh') |
650a6e996ede
Implement fuzzy matching to catalog updates. No frontend yet.
cmlenz
parents:
111
diff
changeset
|
135 cat.add('bar', 'Bahr') |
650a6e996ede
Implement fuzzy matching to catalog updates. No frontend yet.
cmlenz
parents:
111
diff
changeset
|
136 tmpl = catalog.Catalog() |
650a6e996ede
Implement fuzzy matching to catalog updates. No frontend yet.
cmlenz
parents:
111
diff
changeset
|
137 tmpl.add('foo') |
181
9a1acb41e7dd
The frontends now provide ways to update existing translations catalogs from a template. Closes #22.
cmlenz
parents:
165
diff
changeset
|
138 cat.update(tmpl) |
9a1acb41e7dd
The frontends now provide ways to update existing translations catalogs from a template. Closes #22.
cmlenz
parents:
165
diff
changeset
|
139 self.assertEqual(1, len(cat.obsolete)) |
165
650a6e996ede
Implement fuzzy matching to catalog updates. No frontend yet.
cmlenz
parents:
111
diff
changeset
|
140 assert 'fo' not in cat |
650a6e996ede
Implement fuzzy matching to catalog updates. No frontend yet.
cmlenz
parents:
111
diff
changeset
|
141 |
650a6e996ede
Implement fuzzy matching to catalog updates. No frontend yet.
cmlenz
parents:
111
diff
changeset
|
142 self.assertEqual('Voh', cat['foo'].string) |
650a6e996ede
Implement fuzzy matching to catalog updates. No frontend yet.
cmlenz
parents:
111
diff
changeset
|
143 self.assertEqual(True, cat['foo'].fuzzy) |
650a6e996ede
Implement fuzzy matching to catalog updates. No frontend yet.
cmlenz
parents:
111
diff
changeset
|
144 |
314 | 145 def test_update_fuzzy_matching_no_msgstr(self): |
146 cat = catalog.Catalog() | |
147 cat.add('fo', '') | |
148 tmpl = catalog.Catalog() | |
149 tmpl.add('fo') | |
150 tmpl.add('foo') | |
151 cat.update(tmpl) | |
152 assert 'fo' in cat | |
153 assert 'foo' in cat | |
154 | |
155 self.assertEqual('', cat['fo'].string) | |
156 self.assertEqual(False, cat['fo'].fuzzy) | |
157 self.assertEqual(None, cat['foo'].string) | |
158 self.assertEqual(False, cat['foo'].fuzzy) | |
159 | |
160 def test_update_fuzzy_matching_no_cascading(self): | |
161 cat = catalog.Catalog() | |
162 cat.add('fo', 'Voh') | |
163 cat.add('foo', 'Vohe') | |
164 tmpl = catalog.Catalog() | |
165 tmpl.add('fo') | |
166 tmpl.add('foo') | |
167 tmpl.add('fooo') | |
168 cat.update(tmpl) | |
169 assert 'fo' in cat | |
170 assert 'foo' in cat | |
171 | |
172 self.assertEqual('Voh', cat['fo'].string) | |
173 self.assertEqual(False, cat['fo'].fuzzy) | |
174 self.assertEqual('Vohe', cat['foo'].string) | |
175 self.assertEqual(False, cat['foo'].fuzzy) | |
176 self.assertEqual('Vohe', cat['fooo'].string) | |
177 self.assertEqual(True, cat['fooo'].fuzzy) | |
178 | |
165
650a6e996ede
Implement fuzzy matching to catalog updates. No frontend yet.
cmlenz
parents:
111
diff
changeset
|
179 def test_update_without_fuzzy_matching(self): |
650a6e996ede
Implement fuzzy matching to catalog updates. No frontend yet.
cmlenz
parents:
111
diff
changeset
|
180 cat = catalog.Catalog() |
650a6e996ede
Implement fuzzy matching to catalog updates. No frontend yet.
cmlenz
parents:
111
diff
changeset
|
181 cat.add('fo', 'Voh') |
650a6e996ede
Implement fuzzy matching to catalog updates. No frontend yet.
cmlenz
parents:
111
diff
changeset
|
182 cat.add('bar', 'Bahr') |
650a6e996ede
Implement fuzzy matching to catalog updates. No frontend yet.
cmlenz
parents:
111
diff
changeset
|
183 tmpl = catalog.Catalog() |
650a6e996ede
Implement fuzzy matching to catalog updates. No frontend yet.
cmlenz
parents:
111
diff
changeset
|
184 tmpl.add('foo') |
200
2983c718f6e2
Added `--no-fuzzy-matching` to the frontends and also `--previous` which adds the old msgid's as comments. The latest closes #31.
palgarvio
parents:
181
diff
changeset
|
185 cat.update(tmpl, no_fuzzy_matching=True) |
181
9a1acb41e7dd
The frontends now provide ways to update existing translations catalogs from a template. Closes #22.
cmlenz
parents:
165
diff
changeset
|
186 self.assertEqual(2, len(cat.obsolete)) |
165
650a6e996ede
Implement fuzzy matching to catalog updates. No frontend yet.
cmlenz
parents:
111
diff
changeset
|
187 |
452 | 188 def test_fuzzy_matching_regarding_plurals(self): |
189 cat = catalog.Catalog() | |
190 cat.add(('foo', 'foh'), ('foo', 'foh')) | |
191 ru = copy.copy(cat) | |
192 ru.locale = 'ru_RU' | |
193 ru.update(cat) | |
194 self.assertEqual(True, ru['foo'].fuzzy) | |
195 ru = copy.copy(cat) | |
196 ru.locale = 'ru_RU' | |
197 ru['foo'].string = ('foh', 'fohh', 'fohhh') | |
198 ru.update(cat) | |
199 self.assertEqual(False, ru['foo'].fuzzy) | |
200 | |
314 | 201 def test_update_no_template_mutation(self): |
202 tmpl = catalog.Catalog() | |
203 tmpl.add('foo') | |
204 cat1 = catalog.Catalog() | |
205 cat1.add('foo', 'Voh') | |
206 cat1.update(tmpl) | |
207 cat2 = catalog.Catalog() | |
208 cat2.update(tmpl) | |
209 | |
210 self.assertEqual(None, cat2['foo'].string) | |
211 self.assertEqual(False, cat2['foo'].fuzzy) | |
472 | 212 |
213 def test_update_po_updates_pot_creation_date(self): | |
214 template = catalog.Catalog() | |
215 localized_catalog = copy.deepcopy(template) | |
216 localized_catalog.locale = 'de_DE' | |
217 self.assertNotEqual(template.mime_headers, | |
218 localized_catalog.mime_headers) | |
219 self.assertEqual(template.creation_date, | |
220 localized_catalog.creation_date) | |
221 template.creation_date = datetime.datetime.now() - \ | |
222 datetime.timedelta(minutes=5) | |
223 localized_catalog.update(template) | |
224 self.assertEqual(template.creation_date, | |
225 localized_catalog.creation_date) | |
475 | 226 |
227 def test_update_po_keeps_po_revision_date(self): | |
228 template = catalog.Catalog() | |
229 localized_catalog = copy.deepcopy(template) | |
230 localized_catalog.locale = 'de_DE' | |
231 fake_rev_date = datetime.datetime.now() - datetime.timedelta(days=5) | |
232 localized_catalog.revision_date = fake_rev_date | |
233 self.assertNotEqual(template.mime_headers, | |
234 localized_catalog.mime_headers) | |
235 self.assertEqual(template.creation_date, | |
236 localized_catalog.creation_date) | |
237 template.creation_date = datetime.datetime.now() - \ | |
238 datetime.timedelta(minutes=5) | |
239 localized_catalog.update(template) | |
240 self.assertEqual(localized_catalog.revision_date, fake_rev_date) | |
69
9b8079807245
Message catalogs can have multiple messages with the same ID, where some of them have plural strings, and others don't. Still the same message.
cmlenz
parents:
67
diff
changeset
|
241 |
479 | 242 def test_stores_datetime_correctly(self): |
243 localized = catalog.Catalog() | |
244 localized.locale = 'de_DE' | |
245 localized[''] = catalog.Message('', | |
246 "POT-Creation-Date: 2009-03-09 15:47-0700\n" + | |
247 "PO-Revision-Date: 2009-03-09 15:47-0700\n") | |
248 for key, value in localized.mime_headers: | |
249 if key in ('POT-Creation-Date', 'PO-Revision-Date'): | |
250 self.assertEqual(value, '2009-03-09 15:47-0700') | |
251 | |
56
27fba894d3ca
Add actual data structures for handling message catalogs, so that more code can be reused here between the frontends.
cmlenz
parents:
diff
changeset
|
252 def suite(): |
27fba894d3ca
Add actual data structures for handling message catalogs, so that more code can be reused here between the frontends.
cmlenz
parents:
diff
changeset
|
253 suite = unittest.TestSuite() |
508
dbb70d75718a
Fix Python 2.3 compatibility for 0.9 branch (closes #233)
fschwarz
parents:
479
diff
changeset
|
254 if hasattr(doctest, 'ELLIPSIS'): |
dbb70d75718a
Fix Python 2.3 compatibility for 0.9 branch (closes #233)
fschwarz
parents:
479
diff
changeset
|
255 suite.addTest(doctest.DocTestSuite(catalog, optionflags=doctest.ELLIPSIS)) |
dbb70d75718a
Fix Python 2.3 compatibility for 0.9 branch (closes #233)
fschwarz
parents:
479
diff
changeset
|
256 else: |
dbb70d75718a
Fix Python 2.3 compatibility for 0.9 branch (closes #233)
fschwarz
parents:
479
diff
changeset
|
257 # Python 2.3 has no doctest.ELLIPSIS option, it's implicit |
dbb70d75718a
Fix Python 2.3 compatibility for 0.9 branch (closes #233)
fschwarz
parents:
479
diff
changeset
|
258 suite.addTest(doctest.DocTestSuite(catalog)) |
56
27fba894d3ca
Add actual data structures for handling message catalogs, so that more code can be reused here between the frontends.
cmlenz
parents:
diff
changeset
|
259 suite.addTest(unittest.makeSuite(MessageTestCase)) |
69
9b8079807245
Message catalogs can have multiple messages with the same ID, where some of them have plural strings, and others don't. Still the same message.
cmlenz
parents:
67
diff
changeset
|
260 suite.addTest(unittest.makeSuite(CatalogTestCase)) |
56
27fba894d3ca
Add actual data structures for handling message catalogs, so that more code can be reused here between the frontends.
cmlenz
parents:
diff
changeset
|
261 return suite |
27fba894d3ca
Add actual data structures for handling message catalogs, so that more code can be reused here between the frontends.
cmlenz
parents:
diff
changeset
|
262 |
27fba894d3ca
Add actual data structures for handling message catalogs, so that more code can be reused here between the frontends.
cmlenz
parents:
diff
changeset
|
263 if __name__ == '__main__': |
27fba894d3ca
Add actual data structures for handling message catalogs, so that more code can be reused here between the frontends.
cmlenz
parents:
diff
changeset
|
264 unittest.main(defaultTest='suite') |