Mercurial > babel > old > mirror
annotate babel/messages/tests/catalog.py @ 113:0c18f72fcb76
unused import
author | pjenvey |
---|---|
date | Thu, 14 Jun 2007 20:40:10 +0000 |
parents | 4b42e23644e5 |
children | 533baef258bb |
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): |
068952b4d4c0
Add actual data structures for handling message catalogs, so that more code can be reused here between the frontends.
cmlenz
parents:
diff
changeset
|
23 assert catalog.PYTHON_FORMAT('foo %d bar') |
068952b4d4c0
Add actual data structures for handling message catalogs, so that more code can be reused here between the frontends.
cmlenz
parents:
diff
changeset
|
24 assert catalog.PYTHON_FORMAT('foo %s bar') |
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
|
25 assert catalog.PYTHON_FORMAT('foo %r bar') |
107
4b42e23644e5
`Message`, `read_po` and `write_po` now all handle user/auto comments correctly.
palgarvio
parents:
97
diff
changeset
|
26 |
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
|
27 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
|
28 mess = catalog.Message('foo', user_comments=['Comment About `foo`']) |
4b42e23644e5
`Message`, `read_po` and `write_po` now all handle user/auto comments correctly.
palgarvio
parents:
97
diff
changeset
|
29 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
|
30 mess = catalog.Message('foo', |
107
4b42e23644e5
`Message`, `read_po` and `write_po` now all handle user/auto comments correctly.
palgarvio
parents:
97
diff
changeset
|
31 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
|
32 'Comment 2 About `foo`']) |
107
4b42e23644e5
`Message`, `read_po` and `write_po` now all handle user/auto comments correctly.
palgarvio
parents:
97
diff
changeset
|
33 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
|
34 '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
|
35 |
068952b4d4c0
Add actual data structures for handling message catalogs, so that more code can be reused here between the frontends.
cmlenz
parents:
diff
changeset
|
36 |
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
|
37 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
|
38 |
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
|
39 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
|
40 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
|
41 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
|
42 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
|
43 self.assertEqual(1, len(cat)) |
97
debd9ac3bb4d
Fix for #11 (use local timezone in timestamps of generated POT).
cmlenz
parents:
91
diff
changeset
|
44 |
91
f517ad70d8fc
Unittest for the problem reported by pjenvey fixed on [88].
palgarvio
parents:
82
diff
changeset
|
45 def test_update_message_updates_comments(self): |
f517ad70d8fc
Unittest for the problem reported by pjenvey fixed on [88].
palgarvio
parents:
82
diff
changeset
|
46 cat = catalog.Catalog() |
f517ad70d8fc
Unittest for the problem reported by pjenvey fixed on [88].
palgarvio
parents:
82
diff
changeset
|
47 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
|
48 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
|
49 self.assertEqual(cat[u'foo'].user_comments, []) |
91
f517ad70d8fc
Unittest for the problem reported by pjenvey fixed on [88].
palgarvio
parents:
82
diff
changeset
|
50 # 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
|
51 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
|
52 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
|
53 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
|
54 # now add yet another location with another comment |
f517ad70d8fc
Unittest for the problem reported by pjenvey fixed on [88].
palgarvio
parents:
82
diff
changeset
|
55 cat[u'foo'] = catalog.Message('foo', locations=[('main.py', 9)], |
107
4b42e23644e5
`Message`, `read_po` and `write_po` now all handle user/auto comments correctly.
palgarvio
parents:
97
diff
changeset
|
56 auto_comments=['Foo Bar comment 2']) |
4b42e23644e5
`Message`, `read_po` and `write_po` now all handle user/auto comments correctly.
palgarvio
parents:
97
diff
changeset
|
57 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
|
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 |
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
|
60 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
|
61 suite = unittest.TestSuite() |
69 | 62 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
|
63 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
|
64 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
|
65 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
|
66 |
068952b4d4c0
Add actual data structures for handling message catalogs, so that more code can be reused here between the frontends.
cmlenz
parents:
diff
changeset
|
67 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
|
68 unittest.main(defaultTest='suite') |