annotate babel/messages/tests/catalog.py @ 229:85340bec3a97

Fix tests broken by [233], and add new tests.
author cmlenz
date Fri, 20 Jul 2007 16:20:43 +0000
parents f358dd40a960
children aaf36f409166
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')
107
4b42e23644e5 `Message`, `read_po` and `write_po` now all handle user/auto comments correctly.
palgarvio
parents: 97
diff changeset
37
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
38 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
39 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
40 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
41 mess = catalog.Message('foo',
107
4b42e23644e5 `Message`, `read_po` and `write_po` now all handle user/auto comments correctly.
palgarvio
parents: 97
diff changeset
42 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
43 'Comment 2 About `foo`'])
107
4b42e23644e5 `Message`, `read_po` and `write_po` now all handle user/auto comments correctly.
palgarvio
parents: 97
diff changeset
44 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
45 '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
46
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
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
48 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
49
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
50 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
51 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
52 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
53 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
54 self.assertEqual(1, len(cat))
97
debd9ac3bb4d Fix for #11 (use local timezone in timestamps of generated POT).
cmlenz
parents: 91
diff changeset
55
229
85340bec3a97 Fix tests broken by [233], and add new tests.
cmlenz
parents: 227
diff changeset
56 def test_duplicate_auto_comment(self):
85340bec3a97 Fix tests broken by [233], and add new tests.
cmlenz
parents: 227
diff changeset
57 msg = catalog.Message('foo', auto_comments=['A comment', 'A comment'])
85340bec3a97 Fix tests broken by [233], and add new tests.
cmlenz
parents: 227
diff changeset
58 self.assertEqual(['A comment'], msg.auto_comments)
85340bec3a97 Fix tests broken by [233], and add new tests.
cmlenz
parents: 227
diff changeset
59
85340bec3a97 Fix tests broken by [233], and add new tests.
cmlenz
parents: 227
diff changeset
60 def test_duplicate_user_comment(self):
85340bec3a97 Fix tests broken by [233], and add new tests.
cmlenz
parents: 227
diff changeset
61 msg = catalog.Message('foo', user_comments=['A comment', 'A comment'])
85340bec3a97 Fix tests broken by [233], and add new tests.
cmlenz
parents: 227
diff changeset
62 self.assertEqual(['A comment'], msg.user_comments)
85340bec3a97 Fix tests broken by [233], and add new tests.
cmlenz
parents: 227
diff changeset
63
91
f517ad70d8fc Unittest for the problem reported by pjenvey fixed on [88].
palgarvio
parents: 82
diff changeset
64 def test_update_message_updates_comments(self):
f517ad70d8fc Unittest for the problem reported by pjenvey fixed on [88].
palgarvio
parents: 82
diff changeset
65 cat = catalog.Catalog()
f517ad70d8fc Unittest for the problem reported by pjenvey fixed on [88].
palgarvio
parents: 82
diff changeset
66 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
67 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
68 self.assertEqual(cat[u'foo'].user_comments, [])
91
f517ad70d8fc Unittest for the problem reported by pjenvey fixed on [88].
palgarvio
parents: 82
diff changeset
69 # 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
70 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
71 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
72 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
73 # now add yet another location with another comment
f517ad70d8fc Unittest for the problem reported by pjenvey fixed on [88].
palgarvio
parents: 82
diff changeset
74 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
75 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
76 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
77
167
533baef258bb Implement fuzzy matching to catalog updates. No frontend yet.
cmlenz
parents: 113
diff changeset
78 def test_update_fuzzy_matching_with_case_change(self):
533baef258bb Implement fuzzy matching to catalog updates. No frontend yet.
cmlenz
parents: 113
diff changeset
79 cat = catalog.Catalog()
533baef258bb Implement fuzzy matching to catalog updates. No frontend yet.
cmlenz
parents: 113
diff changeset
80 cat.add('foo', 'Voh')
533baef258bb Implement fuzzy matching to catalog updates. No frontend yet.
cmlenz
parents: 113
diff changeset
81 cat.add('bar', 'Bahr')
533baef258bb Implement fuzzy matching to catalog updates. No frontend yet.
cmlenz
parents: 113
diff changeset
82 tmpl = catalog.Catalog()
533baef258bb Implement fuzzy matching to catalog updates. No frontend yet.
cmlenz
parents: 113
diff changeset
83 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
84 cat.update(tmpl)
e927dffc9ab4 The frontends now provide ways to update existing translations catalogs from a template. Closes #22.
cmlenz
parents: 167
diff changeset
85 self.assertEqual(1, len(cat.obsolete))
167
533baef258bb Implement fuzzy matching to catalog updates. No frontend yet.
cmlenz
parents: 113
diff changeset
86 assert 'foo' not in cat
533baef258bb Implement fuzzy matching to catalog updates. No frontend yet.
cmlenz
parents: 113
diff changeset
87
533baef258bb Implement fuzzy matching to catalog updates. No frontend yet.
cmlenz
parents: 113
diff changeset
88 self.assertEqual('Voh', cat['Foo'].string)
533baef258bb Implement fuzzy matching to catalog updates. No frontend yet.
cmlenz
parents: 113
diff changeset
89 self.assertEqual(True, cat['Foo'].fuzzy)
533baef258bb Implement fuzzy matching to catalog updates. No frontend yet.
cmlenz
parents: 113
diff changeset
90
533baef258bb Implement fuzzy matching to catalog updates. No frontend yet.
cmlenz
parents: 113
diff changeset
91 def test_update_fuzzy_matching_with_char_change(self):
533baef258bb Implement fuzzy matching to catalog updates. No frontend yet.
cmlenz
parents: 113
diff changeset
92 cat = catalog.Catalog()
533baef258bb Implement fuzzy matching to catalog updates. No frontend yet.
cmlenz
parents: 113
diff changeset
93 cat.add('fo', 'Voh')
533baef258bb Implement fuzzy matching to catalog updates. No frontend yet.
cmlenz
parents: 113
diff changeset
94 cat.add('bar', 'Bahr')
533baef258bb Implement fuzzy matching to catalog updates. No frontend yet.
cmlenz
parents: 113
diff changeset
95 tmpl = catalog.Catalog()
533baef258bb Implement fuzzy matching to catalog updates. No frontend yet.
cmlenz
parents: 113
diff changeset
96 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
97 cat.update(tmpl)
e927dffc9ab4 The frontends now provide ways to update existing translations catalogs from a template. Closes #22.
cmlenz
parents: 167
diff changeset
98 self.assertEqual(1, len(cat.obsolete))
167
533baef258bb Implement fuzzy matching to catalog updates. No frontend yet.
cmlenz
parents: 113
diff changeset
99 assert 'fo' not in cat
533baef258bb Implement fuzzy matching to catalog updates. No frontend yet.
cmlenz
parents: 113
diff changeset
100
533baef258bb Implement fuzzy matching to catalog updates. No frontend yet.
cmlenz
parents: 113
diff changeset
101 self.assertEqual('Voh', cat['foo'].string)
533baef258bb Implement fuzzy matching to catalog updates. No frontend yet.
cmlenz
parents: 113
diff changeset
102 self.assertEqual(True, cat['foo'].fuzzy)
533baef258bb Implement fuzzy matching to catalog updates. No frontend yet.
cmlenz
parents: 113
diff changeset
103
533baef258bb Implement fuzzy matching to catalog updates. No frontend yet.
cmlenz
parents: 113
diff changeset
104 def test_update_without_fuzzy_matching(self):
533baef258bb Implement fuzzy matching to catalog updates. No frontend yet.
cmlenz
parents: 113
diff changeset
105 cat = catalog.Catalog()
533baef258bb Implement fuzzy matching to catalog updates. No frontend yet.
cmlenz
parents: 113
diff changeset
106 cat.add('fo', 'Voh')
533baef258bb Implement fuzzy matching to catalog updates. No frontend yet.
cmlenz
parents: 113
diff changeset
107 cat.add('bar', 'Bahr')
533baef258bb Implement fuzzy matching to catalog updates. No frontend yet.
cmlenz
parents: 113
diff changeset
108 tmpl = catalog.Catalog()
533baef258bb Implement fuzzy matching to catalog updates. No frontend yet.
cmlenz
parents: 113
diff changeset
109 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
110 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
111 self.assertEqual(2, len(cat.obsolete))
167
533baef258bb Implement fuzzy matching to catalog updates. No frontend yet.
cmlenz
parents: 113
diff changeset
112
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
113
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
114 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
115 suite = unittest.TestSuite()
69
1d8e81bfedf9 Enhance catalog to also manage the MIME headers.
cmlenz
parents: 58
diff changeset
116 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
117 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
118 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
119 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
120
068952b4d4c0 Add actual data structures for handling message catalogs, so that more code can be reused here between the frontends.
cmlenz
parents:
diff changeset
121 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
122 unittest.main(defaultTest='suite')
Copyright (C) 2012-2017 Edgewall Software