142
|
1 # -*- coding: utf-8 -*-
|
|
2 #
|
|
3 # Copyright (C) 2007 Edgewall Software
|
|
4 # All rights reserved.
|
|
5 #
|
|
6 # This software is licensed as described in the file COPYING, which
|
|
7 # you should have received as part of this distribution. The terms
|
|
8 # are also available at http://babel.edgewall.org/wiki/License.
|
|
9 #
|
|
10 # This software consists of voluntary contributions made by many
|
|
11 # individuals. For the exact contribution history, see the revision
|
|
12 # history and logs, available at http://babel.edgewall.org/log/.
|
|
13
|
|
14 import doctest
|
|
15 import unittest
|
|
16
|
|
17 from babel.messages import catalog
|
|
18
|
|
19
|
|
20 class MessageTestCase(unittest.TestCase):
|
|
21
|
|
22 def test_python_format(self):
|
|
23 assert catalog.PYTHON_FORMAT('foo %d bar')
|
|
24 assert catalog.PYTHON_FORMAT('foo %s bar')
|
|
25 assert catalog.PYTHON_FORMAT('foo %r bar')
|
|
26
|
|
27 def test_translator_comments(self):
|
|
28 mess = catalog.Message('foo', user_comments=['Comment About `foo`'])
|
|
29 self.assertEqual(mess.user_comments, ['Comment About `foo`'])
|
|
30 mess = catalog.Message('foo',
|
|
31 auto_comments=['Comment 1 About `foo`',
|
|
32 'Comment 2 About `foo`'])
|
|
33 self.assertEqual(mess.auto_comments, ['Comment 1 About `foo`',
|
|
34 'Comment 2 About `foo`'])
|
|
35
|
|
36
|
|
37 class CatalogTestCase(unittest.TestCase):
|
|
38
|
|
39 def test_two_messages_with_same_singular(self):
|
|
40 cat = catalog.Catalog()
|
|
41 cat.add('foo')
|
|
42 cat.add(('foo', 'foos'))
|
|
43 self.assertEqual(1, len(cat))
|
|
44
|
|
45 def test_update_message_updates_comments(self):
|
|
46 cat = catalog.Catalog()
|
|
47 cat[u'foo'] = catalog.Message('foo', locations=[('main.py', 5)])
|
|
48 self.assertEqual(cat[u'foo'].auto_comments, [])
|
|
49 self.assertEqual(cat[u'foo'].user_comments, [])
|
|
50 # Update cat[u'foo'] with a new location and a comment
|
|
51 cat[u'foo'] = catalog.Message('foo', locations=[('main.py', 7)],
|
|
52 user_comments=['Foo Bar comment 1'])
|
|
53 self.assertEqual(cat[u'foo'].user_comments, ['Foo Bar comment 1'])
|
|
54 # now add yet another location with another comment
|
|
55 cat[u'foo'] = catalog.Message('foo', locations=[('main.py', 9)],
|
|
56 auto_comments=['Foo Bar comment 2'])
|
|
57 self.assertEqual(cat[u'foo'].auto_comments, ['Foo Bar comment 2'])
|
|
58
|
|
59
|
|
60 def suite():
|
|
61 suite = unittest.TestSuite()
|
|
62 suite.addTest(doctest.DocTestSuite(catalog, optionflags=doctest.ELLIPSIS))
|
|
63 suite.addTest(unittest.makeSuite(MessageTestCase))
|
|
64 suite.addTest(unittest.makeSuite(CatalogTestCase))
|
|
65 return suite
|
|
66
|
|
67 if __name__ == '__main__':
|
|
68 unittest.main(defaultTest='suite')
|