annotate babel/messages/tests/catalog.py @ 361:1b78b747b386

Updated catalog test case for last commit, flags are now tested too in the clone test case.
author aronacher
date Tue, 17 Jun 2008 21:56:50 +0000
parents 36408f068138
children cadc2f937a78
rev   line source
58
068952b4d4c0 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 -*-
068952b4d4c0 Add actual data structures for handling message catalogs, so that more code can be reused here between the frontends.
cmlenz
parents:
diff changeset
2 #
068952b4d4c0 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
068952b4d4c0 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.
068952b4d4c0 Add actual data structures for handling message catalogs, so that more code can be reused here between the frontends.
cmlenz
parents:
diff changeset
5 #
068952b4d4c0 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
068952b4d4c0 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
068952b4d4c0 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.
068952b4d4c0 Add actual data structures for handling message catalogs, so that more code can be reused here between the frontends.
cmlenz
parents:
diff changeset
9 #
068952b4d4c0 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
068952b4d4c0 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
068952b4d4c0 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/.
068952b4d4c0 Add actual data structures for handling message catalogs, so that more code can be reused here between the frontends.
cmlenz
parents:
diff changeset
13
068952b4d4c0 Add actual data structures for handling message catalogs, so that more code can be reused here between the frontends.
cmlenz
parents:
diff changeset
14 import doctest
068952b4d4c0 Add actual data structures for handling message catalogs, so that more code can be reused here between the frontends.
cmlenz
parents:
diff changeset
15 import unittest
068952b4d4c0 Add actual data structures for handling message catalogs, so that more code can be reused here between the frontends.
cmlenz
parents:
diff changeset
16
068952b4d4c0 Add actual data structures for handling message catalogs, so that more code can be reused here between the frontends.
cmlenz
parents:
diff changeset
17 from babel.messages import catalog
068952b4d4c0 Add actual data structures for handling message catalogs, so that more code can be reused here between the frontends.
cmlenz
parents:
diff changeset
18
068952b4d4c0 Add actual data structures for handling message catalogs, so that more code can be reused here between the frontends.
cmlenz
parents:
diff changeset
19
068952b4d4c0 Add actual data structures for handling message catalogs, so that more code can be reused here between the frontends.
cmlenz
parents:
diff changeset
20 class MessageTestCase(unittest.TestCase):
068952b4d4c0 Add actual data structures for handling message catalogs, so that more code can be reused here between the frontends.
cmlenz
parents:
diff changeset
21
068952b4d4c0 Add actual data structures for handling message catalogs, so that more code can be reused here between the frontends.
cmlenz
parents:
diff changeset
22 def test_python_format(self):
222
bd8b1301b27e Added infrastructure for adding catalog checkers, and implement a checker that validations Python format parameters in translations, closing #19.
cmlenz
parents: 202
diff changeset
23 assert catalog.PYTHON_FORMAT.search('foo %d bar')
bd8b1301b27e Added infrastructure for adding catalog checkers, and implement a checker that validations Python format parameters in translations, closing #19.
cmlenz
parents: 202
diff changeset
24 assert catalog.PYTHON_FORMAT.search('foo %s bar')
bd8b1301b27e Added infrastructure for adding catalog checkers, and implement a checker that validations Python format parameters in translations, closing #19.
cmlenz
parents: 202
diff changeset
25 assert catalog.PYTHON_FORMAT.search('foo %r bar')
227
f358dd40a960 Applied patch by Ramiro Morales for more extensive detection of Python string formatting specifiers. Closes #57.
cmlenz
parents: 222
diff changeset
26 assert catalog.PYTHON_FORMAT.search('foo %(name).1f')
f358dd40a960 Applied patch by Ramiro Morales for more extensive detection of Python string formatting specifiers. Closes #57.
cmlenz
parents: 222
diff changeset
27 assert catalog.PYTHON_FORMAT.search('foo %(name)3.3f')
f358dd40a960 Applied patch by Ramiro Morales for more extensive detection of Python string formatting specifiers. Closes #57.
cmlenz
parents: 222
diff changeset
28 assert catalog.PYTHON_FORMAT.search('foo %(name)3f')
f358dd40a960 Applied patch by Ramiro Morales for more extensive detection of Python string formatting specifiers. Closes #57.
cmlenz
parents: 222
diff changeset
29 assert catalog.PYTHON_FORMAT.search('foo %(name)06d')
f358dd40a960 Applied patch by Ramiro Morales for more extensive detection of Python string formatting specifiers. Closes #57.
cmlenz
parents: 222
diff changeset
30 assert catalog.PYTHON_FORMAT.search('foo %(name)Li')
f358dd40a960 Applied patch by Ramiro Morales for more extensive detection of Python string formatting specifiers. Closes #57.
cmlenz
parents: 222
diff changeset
31 assert catalog.PYTHON_FORMAT.search('foo %(name)#d')
f358dd40a960 Applied patch by Ramiro Morales for more extensive detection of Python string formatting specifiers. Closes #57.
cmlenz
parents: 222
diff changeset
32 assert catalog.PYTHON_FORMAT.search('foo %(name)-4.4hs')
f358dd40a960 Applied patch by Ramiro Morales for more extensive detection of Python string formatting specifiers. Closes #57.
cmlenz
parents: 222
diff changeset
33 assert catalog.PYTHON_FORMAT.search('foo %(name)*.3f')
f358dd40a960 Applied patch by Ramiro Morales for more extensive detection of Python string formatting specifiers. Closes #57.
cmlenz
parents: 222
diff changeset
34 assert catalog.PYTHON_FORMAT.search('foo %(name).*f')
f358dd40a960 Applied patch by Ramiro Morales for more extensive detection of Python string formatting specifiers. Closes #57.
cmlenz
parents: 222
diff changeset
35 assert catalog.PYTHON_FORMAT.search('foo %(name)3.*f')
f358dd40a960 Applied patch by Ramiro Morales for more extensive detection of Python string formatting specifiers. Closes #57.
cmlenz
parents: 222
diff changeset
36 assert catalog.PYTHON_FORMAT.search('foo %(name)*.*f')
360
36408f068138 Message.clone doesn't return a shallow copy any longer. This fixes a bug with update where flags where shared.
aronacher
parents: 352
diff changeset
37 assert catalog.PYTHON_FORMAT.search('foo %()s')
107
4b42e23644e5 `Message`, `read_po` and `write_po` now all handle user/auto comments correctly.
palgarvio
parents: 97
diff changeset
38
82
f421e5576d26 Added support for translator comments at the API and frontends levels.(See #12, item 1). Updated docs and tests accordingly.
palgarvio
parents: 71
diff changeset
39 def test_translator_comments(self):
107
4b42e23644e5 `Message`, `read_po` and `write_po` now all handle user/auto comments correctly.
palgarvio
parents: 97
diff changeset
40 mess = catalog.Message('foo', user_comments=['Comment About `foo`'])
202
d3c272492053 Added `--no-fuzzy-matching` to the frontends and also `--previous` which adds the old msgid's as comments. The latest closes #31.
palgarvio
parents: 183
diff changeset
41 self.assertEqual(mess.user_comments, ['Comment About `foo`'])
82
f421e5576d26 Added support for translator comments at the API and frontends levels.(See #12, item 1). Updated docs and tests accordingly.
palgarvio
parents: 71
diff changeset
42 mess = catalog.Message('foo',
107
4b42e23644e5 `Message`, `read_po` and `write_po` now all handle user/auto comments correctly.
palgarvio
parents: 97
diff changeset
43 auto_comments=['Comment 1 About `foo`',
82
f421e5576d26 Added support for translator comments at the API and frontends levels.(See #12, item 1). Updated docs and tests accordingly.
palgarvio
parents: 71
diff changeset
44 'Comment 2 About `foo`'])
107
4b42e23644e5 `Message`, `read_po` and `write_po` now all handle user/auto comments correctly.
palgarvio
parents: 97
diff changeset
45 self.assertEqual(mess.auto_comments, ['Comment 1 About `foo`',
82
f421e5576d26 Added support for translator comments at the API and frontends levels.(See #12, item 1). Updated docs and tests accordingly.
palgarvio
parents: 71
diff changeset
46 'Comment 2 About `foo`'])
58
068952b4d4c0 Add actual data structures for handling message catalogs, so that more code can be reused here between the frontends.
cmlenz
parents:
diff changeset
47
360
36408f068138 Message.clone doesn't return a shallow copy any longer. This fixes a bug with update where flags where shared.
aronacher
parents: 352
diff changeset
48 def test_clone_message_object(self):
36408f068138 Message.clone doesn't return a shallow copy any longer. This fixes a bug with update where flags where shared.
aronacher
parents: 352
diff changeset
49 msg = catalog.Message('foo', locations=[('foo.py', 42)])
36408f068138 Message.clone doesn't return a shallow copy any longer. This fixes a bug with update where flags where shared.
aronacher
parents: 352
diff changeset
50 clone = msg.clone()
36408f068138 Message.clone doesn't return a shallow copy any longer. This fixes a bug with update where flags where shared.
aronacher
parents: 352
diff changeset
51 clone.locations.append(('bar.py', 42))
36408f068138 Message.clone doesn't return a shallow copy any longer. This fixes a bug with update where flags where shared.
aronacher
parents: 352
diff changeset
52 self.assertEqual(msg.locations, [('foo.py', 42)])
361
1b78b747b386 Updated catalog test case for last commit, flags are now tested too in the clone test case.
aronacher
parents: 360
diff changeset
53 msg.flags.add('fuzzy')
1b78b747b386 Updated catalog test case for last commit, flags are now tested too in the clone test case.
aronacher
parents: 360
diff changeset
54 assert not clone.fuzzy and msg.fuzzy
360
36408f068138 Message.clone doesn't return a shallow copy any longer. This fixes a bug with update where flags where shared.
aronacher
parents: 352
diff changeset
55
58
068952b4d4c0 Add actual data structures for handling message catalogs, so that more code can be reused here between the frontends.
cmlenz
parents:
diff changeset
56
71
b260ffa01a2d 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: 69
diff changeset
57 class CatalogTestCase(unittest.TestCase):
b260ffa01a2d 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: 69
diff changeset
58
b260ffa01a2d 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: 69
diff changeset
59 def test_two_messages_with_same_singular(self):
b260ffa01a2d 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: 69
diff changeset
60 cat = catalog.Catalog()
b260ffa01a2d 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: 69
diff changeset
61 cat.add('foo')
b260ffa01a2d 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: 69
diff changeset
62 cat.add(('foo', 'foos'))
b260ffa01a2d 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: 69
diff changeset
63 self.assertEqual(1, len(cat))
97
debd9ac3bb4d Fix for #11 (use local timezone in timestamps of generated POT).
cmlenz
parents: 91
diff changeset
64
229
85340bec3a97 Fix tests broken by [233], and add new tests.
cmlenz
parents: 227
diff changeset
65 def test_duplicate_auto_comment(self):
230
aaf36f409166 Follow-up to [239]: also combine duplicate comments when writing PO files.
cmlenz
parents: 229
diff changeset
66 cat = catalog.Catalog()
aaf36f409166 Follow-up to [239]: also combine duplicate comments when writing PO files.
cmlenz
parents: 229
diff changeset
67 cat.add('foo', auto_comments=['A comment'])
aaf36f409166 Follow-up to [239]: also combine duplicate comments when writing PO files.
cmlenz
parents: 229
diff changeset
68 cat.add('foo', auto_comments=['A comment', 'Another comment'])
aaf36f409166 Follow-up to [239]: also combine duplicate comments when writing PO files.
cmlenz
parents: 229
diff changeset
69 self.assertEqual(['A comment', 'Another comment'],
aaf36f409166 Follow-up to [239]: also combine duplicate comments when writing PO files.
cmlenz
parents: 229
diff changeset
70 cat['foo'].auto_comments)
229
85340bec3a97 Fix tests broken by [233], and add new tests.
cmlenz
parents: 227
diff changeset
71
85340bec3a97 Fix tests broken by [233], and add new tests.
cmlenz
parents: 227
diff changeset
72 def test_duplicate_user_comment(self):
230
aaf36f409166 Follow-up to [239]: also combine duplicate comments when writing PO files.
cmlenz
parents: 229
diff changeset
73 cat = catalog.Catalog()
aaf36f409166 Follow-up to [239]: also combine duplicate comments when writing PO files.
cmlenz
parents: 229
diff changeset
74 cat.add('foo', user_comments=['A comment'])
aaf36f409166 Follow-up to [239]: also combine duplicate comments when writing PO files.
cmlenz
parents: 229
diff changeset
75 cat.add('foo', user_comments=['A comment', 'Another comment'])
aaf36f409166 Follow-up to [239]: also combine duplicate comments when writing PO files.
cmlenz
parents: 229
diff changeset
76 self.assertEqual(['A comment', 'Another comment'],
aaf36f409166 Follow-up to [239]: also combine duplicate comments when writing PO files.
cmlenz
parents: 229
diff changeset
77 cat['foo'].user_comments)
229
85340bec3a97 Fix tests broken by [233], and add new tests.
cmlenz
parents: 227
diff changeset
78
232
1448b500de40 Forgot to update test method name after copy/paste.
cmlenz
parents: 231
diff changeset
79 def test_duplicate_location(self):
231
fc8b8c2bba53 Remove duplicate locations of catalog messages.
cmlenz
parents: 230
diff changeset
80 cat = catalog.Catalog()
fc8b8c2bba53 Remove duplicate locations of catalog messages.
cmlenz
parents: 230
diff changeset
81 cat.add('foo', locations=[('foo.py', 1)])
fc8b8c2bba53 Remove duplicate locations of catalog messages.
cmlenz
parents: 230
diff changeset
82 cat.add('foo', locations=[('foo.py', 1)])
fc8b8c2bba53 Remove duplicate locations of catalog messages.
cmlenz
parents: 230
diff changeset
83 self.assertEqual([('foo.py', 1)], cat['foo'].locations)
fc8b8c2bba53 Remove duplicate locations of catalog messages.
cmlenz
parents: 230
diff changeset
84
279
3308e9971fab Fix for updating catalog messages that changed from gettext to ngettext or vice versa.
cmlenz
parents: 232
diff changeset
85 def test_update_message_changed_to_plural(self):
3308e9971fab Fix for updating catalog messages that changed from gettext to ngettext or vice versa.
cmlenz
parents: 232
diff changeset
86 cat = catalog.Catalog()
3308e9971fab Fix for updating catalog messages that changed from gettext to ngettext or vice versa.
cmlenz
parents: 232
diff changeset
87 cat.add(u'foo', u'Voh')
3308e9971fab Fix for updating catalog messages that changed from gettext to ngettext or vice versa.
cmlenz
parents: 232
diff changeset
88 tmpl = catalog.Catalog()
3308e9971fab Fix for updating catalog messages that changed from gettext to ngettext or vice versa.
cmlenz
parents: 232
diff changeset
89 tmpl.add((u'foo', u'foos'))
3308e9971fab Fix for updating catalog messages that changed from gettext to ngettext or vice versa.
cmlenz
parents: 232
diff changeset
90 cat.update(tmpl)
3308e9971fab Fix for updating catalog messages that changed from gettext to ngettext or vice versa.
cmlenz
parents: 232
diff changeset
91 self.assertEqual((u'Voh', ''), cat['foo'].string)
3308e9971fab Fix for updating catalog messages that changed from gettext to ngettext or vice versa.
cmlenz
parents: 232
diff changeset
92 assert cat['foo'].fuzzy
3308e9971fab Fix for updating catalog messages that changed from gettext to ngettext or vice versa.
cmlenz
parents: 232
diff changeset
93
3308e9971fab Fix for updating catalog messages that changed from gettext to ngettext or vice versa.
cmlenz
parents: 232
diff changeset
94 def test_update_message_changed_to_simple(self):
3308e9971fab Fix for updating catalog messages that changed from gettext to ngettext or vice versa.
cmlenz
parents: 232
diff changeset
95 cat = catalog.Catalog()
3308e9971fab Fix for updating catalog messages that changed from gettext to ngettext or vice versa.
cmlenz
parents: 232
diff changeset
96 cat.add((u'foo' u'foos'), (u'Voh', u'Vöhs'))
3308e9971fab Fix for updating catalog messages that changed from gettext to ngettext or vice versa.
cmlenz
parents: 232
diff changeset
97 tmpl = catalog.Catalog()
3308e9971fab Fix for updating catalog messages that changed from gettext to ngettext or vice versa.
cmlenz
parents: 232
diff changeset
98 tmpl.add(u'foo')
3308e9971fab Fix for updating catalog messages that changed from gettext to ngettext or vice versa.
cmlenz
parents: 232
diff changeset
99 cat.update(tmpl)
3308e9971fab Fix for updating catalog messages that changed from gettext to ngettext or vice versa.
cmlenz
parents: 232
diff changeset
100 self.assertEqual(u'Voh', cat['foo'].string)
3308e9971fab Fix for updating catalog messages that changed from gettext to ngettext or vice versa.
cmlenz
parents: 232
diff changeset
101 assert cat['foo'].fuzzy
3308e9971fab Fix for updating catalog messages that changed from gettext to ngettext or vice versa.
cmlenz
parents: 232
diff changeset
102
91
f517ad70d8fc Unittest for the problem reported by pjenvey fixed on [88].
palgarvio
parents: 82
diff changeset
103 def test_update_message_updates_comments(self):
f517ad70d8fc Unittest for the problem reported by pjenvey fixed on [88].
palgarvio
parents: 82
diff changeset
104 cat = catalog.Catalog()
f517ad70d8fc Unittest for the problem reported by pjenvey fixed on [88].
palgarvio
parents: 82
diff changeset
105 cat[u'foo'] = catalog.Message('foo', locations=[('main.py', 5)])
107
4b42e23644e5 `Message`, `read_po` and `write_po` now all handle user/auto comments correctly.
palgarvio
parents: 97
diff changeset
106 self.assertEqual(cat[u'foo'].auto_comments, [])
4b42e23644e5 `Message`, `read_po` and `write_po` now all handle user/auto comments correctly.
palgarvio
parents: 97
diff changeset
107 self.assertEqual(cat[u'foo'].user_comments, [])
91
f517ad70d8fc Unittest for the problem reported by pjenvey fixed on [88].
palgarvio
parents: 82
diff changeset
108 # Update cat[u'foo'] with a new location and a comment
f517ad70d8fc Unittest for the problem reported by pjenvey fixed on [88].
palgarvio
parents: 82
diff changeset
109 cat[u'foo'] = catalog.Message('foo', locations=[('main.py', 7)],
107
4b42e23644e5 `Message`, `read_po` and `write_po` now all handle user/auto comments correctly.
palgarvio
parents: 97
diff changeset
110 user_comments=['Foo Bar comment 1'])
4b42e23644e5 `Message`, `read_po` and `write_po` now all handle user/auto comments correctly.
palgarvio
parents: 97
diff changeset
111 self.assertEqual(cat[u'foo'].user_comments, ['Foo Bar comment 1'])
91
f517ad70d8fc Unittest for the problem reported by pjenvey fixed on [88].
palgarvio
parents: 82
diff changeset
112 # now add yet another location with another comment
f517ad70d8fc Unittest for the problem reported by pjenvey fixed on [88].
palgarvio
parents: 82
diff changeset
113 cat[u'foo'] = catalog.Message('foo', locations=[('main.py', 9)],
202
d3c272492053 Added `--no-fuzzy-matching` to the frontends and also `--previous` which adds the old msgid's as comments. The latest closes #31.
palgarvio
parents: 183
diff changeset
114 auto_comments=['Foo Bar comment 2'])
107
4b42e23644e5 `Message`, `read_po` and `write_po` now all handle user/auto comments correctly.
palgarvio
parents: 97
diff changeset
115 self.assertEqual(cat[u'foo'].auto_comments, ['Foo Bar comment 2'])
71
b260ffa01a2d 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: 69
diff changeset
116
167
533baef258bb Implement fuzzy matching to catalog updates. No frontend yet.
cmlenz
parents: 113
diff changeset
117 def test_update_fuzzy_matching_with_case_change(self):
533baef258bb Implement fuzzy matching to catalog updates. No frontend yet.
cmlenz
parents: 113
diff changeset
118 cat = catalog.Catalog()
533baef258bb Implement fuzzy matching to catalog updates. No frontend yet.
cmlenz
parents: 113
diff changeset
119 cat.add('foo', 'Voh')
533baef258bb Implement fuzzy matching to catalog updates. No frontend yet.
cmlenz
parents: 113
diff changeset
120 cat.add('bar', 'Bahr')
533baef258bb Implement fuzzy matching to catalog updates. No frontend yet.
cmlenz
parents: 113
diff changeset
121 tmpl = catalog.Catalog()
533baef258bb Implement fuzzy matching to catalog updates. No frontend yet.
cmlenz
parents: 113
diff changeset
122 tmpl.add('Foo')
183
e927dffc9ab4 The frontends now provide ways to update existing translations catalogs from a template. Closes #22.
cmlenz
parents: 167
diff changeset
123 cat.update(tmpl)
e927dffc9ab4 The frontends now provide ways to update existing translations catalogs from a template. Closes #22.
cmlenz
parents: 167
diff changeset
124 self.assertEqual(1, len(cat.obsolete))
167
533baef258bb Implement fuzzy matching to catalog updates. No frontend yet.
cmlenz
parents: 113
diff changeset
125 assert 'foo' not in cat
533baef258bb Implement fuzzy matching to catalog updates. No frontend yet.
cmlenz
parents: 113
diff changeset
126
533baef258bb Implement fuzzy matching to catalog updates. No frontend yet.
cmlenz
parents: 113
diff changeset
127 self.assertEqual('Voh', cat['Foo'].string)
533baef258bb Implement fuzzy matching to catalog updates. No frontend yet.
cmlenz
parents: 113
diff changeset
128 self.assertEqual(True, cat['Foo'].fuzzy)
533baef258bb Implement fuzzy matching to catalog updates. No frontend yet.
cmlenz
parents: 113
diff changeset
129
533baef258bb Implement fuzzy matching to catalog updates. No frontend yet.
cmlenz
parents: 113
diff changeset
130 def test_update_fuzzy_matching_with_char_change(self):
533baef258bb Implement fuzzy matching to catalog updates. No frontend yet.
cmlenz
parents: 113
diff changeset
131 cat = catalog.Catalog()
533baef258bb Implement fuzzy matching to catalog updates. No frontend yet.
cmlenz
parents: 113
diff changeset
132 cat.add('fo', 'Voh')
533baef258bb Implement fuzzy matching to catalog updates. No frontend yet.
cmlenz
parents: 113
diff changeset
133 cat.add('bar', 'Bahr')
533baef258bb Implement fuzzy matching to catalog updates. No frontend yet.
cmlenz
parents: 113
diff changeset
134 tmpl = catalog.Catalog()
533baef258bb Implement fuzzy matching to catalog updates. No frontend yet.
cmlenz
parents: 113
diff changeset
135 tmpl.add('foo')
183
e927dffc9ab4 The frontends now provide ways to update existing translations catalogs from a template. Closes #22.
cmlenz
parents: 167
diff changeset
136 cat.update(tmpl)
e927dffc9ab4 The frontends now provide ways to update existing translations catalogs from a template. Closes #22.
cmlenz
parents: 167
diff changeset
137 self.assertEqual(1, len(cat.obsolete))
167
533baef258bb Implement fuzzy matching to catalog updates. No frontend yet.
cmlenz
parents: 113
diff changeset
138 assert 'fo' not in cat
533baef258bb Implement fuzzy matching to catalog updates. No frontend yet.
cmlenz
parents: 113
diff changeset
139
533baef258bb Implement fuzzy matching to catalog updates. No frontend yet.
cmlenz
parents: 113
diff changeset
140 self.assertEqual('Voh', cat['foo'].string)
533baef258bb Implement fuzzy matching to catalog updates. No frontend yet.
cmlenz
parents: 113
diff changeset
141 self.assertEqual(True, cat['foo'].fuzzy)
533baef258bb Implement fuzzy matching to catalog updates. No frontend yet.
cmlenz
parents: 113
diff changeset
142
314
5c0bda4f20b1 Fix catalog updating with fuzzy matches. Closes #82.
cmlenz
parents: 279
diff changeset
143 def test_update_fuzzy_matching_no_msgstr(self):
5c0bda4f20b1 Fix catalog updating with fuzzy matches. Closes #82.
cmlenz
parents: 279
diff changeset
144 cat = catalog.Catalog()
5c0bda4f20b1 Fix catalog updating with fuzzy matches. Closes #82.
cmlenz
parents: 279
diff changeset
145 cat.add('fo', '')
5c0bda4f20b1 Fix catalog updating with fuzzy matches. Closes #82.
cmlenz
parents: 279
diff changeset
146 tmpl = catalog.Catalog()
5c0bda4f20b1 Fix catalog updating with fuzzy matches. Closes #82.
cmlenz
parents: 279
diff changeset
147 tmpl.add('fo')
5c0bda4f20b1 Fix catalog updating with fuzzy matches. Closes #82.
cmlenz
parents: 279
diff changeset
148 tmpl.add('foo')
5c0bda4f20b1 Fix catalog updating with fuzzy matches. Closes #82.
cmlenz
parents: 279
diff changeset
149 cat.update(tmpl)
5c0bda4f20b1 Fix catalog updating with fuzzy matches. Closes #82.
cmlenz
parents: 279
diff changeset
150 assert 'fo' in cat
5c0bda4f20b1 Fix catalog updating with fuzzy matches. Closes #82.
cmlenz
parents: 279
diff changeset
151 assert 'foo' in cat
5c0bda4f20b1 Fix catalog updating with fuzzy matches. Closes #82.
cmlenz
parents: 279
diff changeset
152
5c0bda4f20b1 Fix catalog updating with fuzzy matches. Closes #82.
cmlenz
parents: 279
diff changeset
153 self.assertEqual('', cat['fo'].string)
5c0bda4f20b1 Fix catalog updating with fuzzy matches. Closes #82.
cmlenz
parents: 279
diff changeset
154 self.assertEqual(False, cat['fo'].fuzzy)
5c0bda4f20b1 Fix catalog updating with fuzzy matches. Closes #82.
cmlenz
parents: 279
diff changeset
155 self.assertEqual(None, cat['foo'].string)
5c0bda4f20b1 Fix catalog updating with fuzzy matches. Closes #82.
cmlenz
parents: 279
diff changeset
156 self.assertEqual(False, cat['foo'].fuzzy)
5c0bda4f20b1 Fix catalog updating with fuzzy matches. Closes #82.
cmlenz
parents: 279
diff changeset
157
352
90849c44c531 More work on msgctxt support (#54).
cmlenz
parents: 315
diff changeset
158 def test_update_fuzzy_matching_with_new_context(self):
90849c44c531 More work on msgctxt support (#54).
cmlenz
parents: 315
diff changeset
159 cat = catalog.Catalog()
90849c44c531 More work on msgctxt support (#54).
cmlenz
parents: 315
diff changeset
160 cat.add('foo', 'Voh')
90849c44c531 More work on msgctxt support (#54).
cmlenz
parents: 315
diff changeset
161 cat.add('bar', 'Bahr')
90849c44c531 More work on msgctxt support (#54).
cmlenz
parents: 315
diff changeset
162 tmpl = catalog.Catalog()
90849c44c531 More work on msgctxt support (#54).
cmlenz
parents: 315
diff changeset
163 tmpl.add('Foo', context='Menu')
90849c44c531 More work on msgctxt support (#54).
cmlenz
parents: 315
diff changeset
164 cat.update(tmpl)
90849c44c531 More work on msgctxt support (#54).
cmlenz
parents: 315
diff changeset
165 self.assertEqual(1, len(cat.obsolete))
90849c44c531 More work on msgctxt support (#54).
cmlenz
parents: 315
diff changeset
166 assert 'foo' not in cat
90849c44c531 More work on msgctxt support (#54).
cmlenz
parents: 315
diff changeset
167
90849c44c531 More work on msgctxt support (#54).
cmlenz
parents: 315
diff changeset
168 message = cat.get('Foo', 'Menu')
90849c44c531 More work on msgctxt support (#54).
cmlenz
parents: 315
diff changeset
169 self.assertEqual('Voh', message.string)
90849c44c531 More work on msgctxt support (#54).
cmlenz
parents: 315
diff changeset
170 self.assertEqual(True, message.fuzzy)
90849c44c531 More work on msgctxt support (#54).
cmlenz
parents: 315
diff changeset
171 self.assertEqual('Menu', message.context)
90849c44c531 More work on msgctxt support (#54).
cmlenz
parents: 315
diff changeset
172
90849c44c531 More work on msgctxt support (#54).
cmlenz
parents: 315
diff changeset
173 def test_update_fuzzy_matching_with_changed_context(self):
90849c44c531 More work on msgctxt support (#54).
cmlenz
parents: 315
diff changeset
174 cat = catalog.Catalog()
90849c44c531 More work on msgctxt support (#54).
cmlenz
parents: 315
diff changeset
175 cat.add('foo', 'Voh', context='Menu|File')
90849c44c531 More work on msgctxt support (#54).
cmlenz
parents: 315
diff changeset
176 cat.add('bar', 'Bahr', context='Menu|File')
90849c44c531 More work on msgctxt support (#54).
cmlenz
parents: 315
diff changeset
177 tmpl = catalog.Catalog()
90849c44c531 More work on msgctxt support (#54).
cmlenz
parents: 315
diff changeset
178 tmpl.add('Foo', context='Menu|Edit')
90849c44c531 More work on msgctxt support (#54).
cmlenz
parents: 315
diff changeset
179 cat.update(tmpl)
90849c44c531 More work on msgctxt support (#54).
cmlenz
parents: 315
diff changeset
180 self.assertEqual(1, len(cat.obsolete))
90849c44c531 More work on msgctxt support (#54).
cmlenz
parents: 315
diff changeset
181 assert cat.get('Foo', 'Menu|File') is None
90849c44c531 More work on msgctxt support (#54).
cmlenz
parents: 315
diff changeset
182
90849c44c531 More work on msgctxt support (#54).
cmlenz
parents: 315
diff changeset
183 message = cat.get('Foo', 'Menu|Edit')
90849c44c531 More work on msgctxt support (#54).
cmlenz
parents: 315
diff changeset
184 self.assertEqual('Voh', message.string)
90849c44c531 More work on msgctxt support (#54).
cmlenz
parents: 315
diff changeset
185 self.assertEqual(True, message.fuzzy)
90849c44c531 More work on msgctxt support (#54).
cmlenz
parents: 315
diff changeset
186 self.assertEqual('Menu|Edit', message.context)
90849c44c531 More work on msgctxt support (#54).
cmlenz
parents: 315
diff changeset
187
314
5c0bda4f20b1 Fix catalog updating with fuzzy matches. Closes #82.
cmlenz
parents: 279
diff changeset
188 def test_update_fuzzy_matching_no_cascading(self):
5c0bda4f20b1 Fix catalog updating with fuzzy matches. Closes #82.
cmlenz
parents: 279
diff changeset
189 cat = catalog.Catalog()
5c0bda4f20b1 Fix catalog updating with fuzzy matches. Closes #82.
cmlenz
parents: 279
diff changeset
190 cat.add('fo', 'Voh')
5c0bda4f20b1 Fix catalog updating with fuzzy matches. Closes #82.
cmlenz
parents: 279
diff changeset
191 cat.add('foo', 'Vohe')
5c0bda4f20b1 Fix catalog updating with fuzzy matches. Closes #82.
cmlenz
parents: 279
diff changeset
192 tmpl = catalog.Catalog()
5c0bda4f20b1 Fix catalog updating with fuzzy matches. Closes #82.
cmlenz
parents: 279
diff changeset
193 tmpl.add('fo')
5c0bda4f20b1 Fix catalog updating with fuzzy matches. Closes #82.
cmlenz
parents: 279
diff changeset
194 tmpl.add('foo')
5c0bda4f20b1 Fix catalog updating with fuzzy matches. Closes #82.
cmlenz
parents: 279
diff changeset
195 tmpl.add('fooo')
5c0bda4f20b1 Fix catalog updating with fuzzy matches. Closes #82.
cmlenz
parents: 279
diff changeset
196 cat.update(tmpl)
5c0bda4f20b1 Fix catalog updating with fuzzy matches. Closes #82.
cmlenz
parents: 279
diff changeset
197 assert 'fo' in cat
5c0bda4f20b1 Fix catalog updating with fuzzy matches. Closes #82.
cmlenz
parents: 279
diff changeset
198 assert 'foo' in cat
5c0bda4f20b1 Fix catalog updating with fuzzy matches. Closes #82.
cmlenz
parents: 279
diff changeset
199
5c0bda4f20b1 Fix catalog updating with fuzzy matches. Closes #82.
cmlenz
parents: 279
diff changeset
200 self.assertEqual('Voh', cat['fo'].string)
5c0bda4f20b1 Fix catalog updating with fuzzy matches. Closes #82.
cmlenz
parents: 279
diff changeset
201 self.assertEqual(False, cat['fo'].fuzzy)
5c0bda4f20b1 Fix catalog updating with fuzzy matches. Closes #82.
cmlenz
parents: 279
diff changeset
202 self.assertEqual('Vohe', cat['foo'].string)
5c0bda4f20b1 Fix catalog updating with fuzzy matches. Closes #82.
cmlenz
parents: 279
diff changeset
203 self.assertEqual(False, cat['foo'].fuzzy)
5c0bda4f20b1 Fix catalog updating with fuzzy matches. Closes #82.
cmlenz
parents: 279
diff changeset
204 self.assertEqual('Vohe', cat['fooo'].string)
5c0bda4f20b1 Fix catalog updating with fuzzy matches. Closes #82.
cmlenz
parents: 279
diff changeset
205 self.assertEqual(True, cat['fooo'].fuzzy)
5c0bda4f20b1 Fix catalog updating with fuzzy matches. Closes #82.
cmlenz
parents: 279
diff changeset
206
167
533baef258bb Implement fuzzy matching to catalog updates. No frontend yet.
cmlenz
parents: 113
diff changeset
207 def test_update_without_fuzzy_matching(self):
533baef258bb Implement fuzzy matching to catalog updates. No frontend yet.
cmlenz
parents: 113
diff changeset
208 cat = catalog.Catalog()
533baef258bb Implement fuzzy matching to catalog updates. No frontend yet.
cmlenz
parents: 113
diff changeset
209 cat.add('fo', 'Voh')
533baef258bb Implement fuzzy matching to catalog updates. No frontend yet.
cmlenz
parents: 113
diff changeset
210 cat.add('bar', 'Bahr')
533baef258bb Implement fuzzy matching to catalog updates. No frontend yet.
cmlenz
parents: 113
diff changeset
211 tmpl = catalog.Catalog()
533baef258bb Implement fuzzy matching to catalog updates. No frontend yet.
cmlenz
parents: 113
diff changeset
212 tmpl.add('foo')
202
d3c272492053 Added `--no-fuzzy-matching` to the frontends and also `--previous` which adds the old msgid's as comments. The latest closes #31.
palgarvio
parents: 183
diff changeset
213 cat.update(tmpl, no_fuzzy_matching=True)
183
e927dffc9ab4 The frontends now provide ways to update existing translations catalogs from a template. Closes #22.
cmlenz
parents: 167
diff changeset
214 self.assertEqual(2, len(cat.obsolete))
167
533baef258bb Implement fuzzy matching to catalog updates. No frontend yet.
cmlenz
parents: 113
diff changeset
215
315
654b632e5482 Merging catalogs would sometimes mix translations from different runs.
cmlenz
parents: 314
diff changeset
216 def test_update_no_template_mutation(self):
654b632e5482 Merging catalogs would sometimes mix translations from different runs.
cmlenz
parents: 314
diff changeset
217 tmpl = catalog.Catalog()
654b632e5482 Merging catalogs would sometimes mix translations from different runs.
cmlenz
parents: 314
diff changeset
218 tmpl.add('foo')
654b632e5482 Merging catalogs would sometimes mix translations from different runs.
cmlenz
parents: 314
diff changeset
219 cat1 = catalog.Catalog()
654b632e5482 Merging catalogs would sometimes mix translations from different runs.
cmlenz
parents: 314
diff changeset
220 cat1.add('foo', 'Voh')
654b632e5482 Merging catalogs would sometimes mix translations from different runs.
cmlenz
parents: 314
diff changeset
221 cat1.update(tmpl)
654b632e5482 Merging catalogs would sometimes mix translations from different runs.
cmlenz
parents: 314
diff changeset
222 cat2 = catalog.Catalog()
654b632e5482 Merging catalogs would sometimes mix translations from different runs.
cmlenz
parents: 314
diff changeset
223 cat2.update(tmpl)
654b632e5482 Merging catalogs would sometimes mix translations from different runs.
cmlenz
parents: 314
diff changeset
224
654b632e5482 Merging catalogs would sometimes mix translations from different runs.
cmlenz
parents: 314
diff changeset
225 self.assertEqual(None, cat2['foo'].string)
654b632e5482 Merging catalogs would sometimes mix translations from different runs.
cmlenz
parents: 314
diff changeset
226 self.assertEqual(False, cat2['foo'].fuzzy)
71
b260ffa01a2d 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: 69
diff changeset
227
352
90849c44c531 More work on msgctxt support (#54).
cmlenz
parents: 315
diff changeset
228
58
068952b4d4c0 Add actual data structures for handling message catalogs, so that more code can be reused here between the frontends.
cmlenz
parents:
diff changeset
229 def suite():
068952b4d4c0 Add actual data structures for handling message catalogs, so that more code can be reused here between the frontends.
cmlenz
parents:
diff changeset
230 suite = unittest.TestSuite()
69
1d8e81bfedf9 Enhance catalog to also manage the MIME headers.
cmlenz
parents: 58
diff changeset
231 suite.addTest(doctest.DocTestSuite(catalog, optionflags=doctest.ELLIPSIS))
58
068952b4d4c0 Add actual data structures for handling message catalogs, so that more code can be reused here between the frontends.
cmlenz
parents:
diff changeset
232 suite.addTest(unittest.makeSuite(MessageTestCase))
71
b260ffa01a2d 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: 69
diff changeset
233 suite.addTest(unittest.makeSuite(CatalogTestCase))
58
068952b4d4c0 Add actual data structures for handling message catalogs, so that more code can be reused here between the frontends.
cmlenz
parents:
diff changeset
234 return suite
068952b4d4c0 Add actual data structures for handling message catalogs, so that more code can be reused here between the frontends.
cmlenz
parents:
diff changeset
235
068952b4d4c0 Add actual data structures for handling message catalogs, so that more code can be reused here between the frontends.
cmlenz
parents:
diff changeset
236 if __name__ == '__main__':
068952b4d4c0 Add actual data structures for handling message catalogs, so that more code can be reused here between the frontends.
cmlenz
parents:
diff changeset
237 unittest.main(defaultTest='suite')
Copyright (C) 2012-2017 Edgewall Software