annotate babel/messages/tests/catalog.py @ 606:c5dd3752bf2a trunk

ensure .mo file header contains the same information as the source .po file (#199)
author fschwarz
date Mon, 27 Aug 2012 21:15:27 +0000
parents a661a0360248
children
rev   line source
56
f40fc143439c 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 -*-
f40fc143439c Add actual data structures for handling message catalogs, so that more code can be reused here between the frontends.
cmlenz
parents:
diff changeset
2 #
530
ca203b2af83c Update the copyright line.
jruigrok
parents: 466
diff changeset
3 # Copyright (C) 2007-2011 Edgewall Software
56
f40fc143439c 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.
f40fc143439c Add actual data structures for handling message catalogs, so that more code can be reused here between the frontends.
cmlenz
parents:
diff changeset
5 #
f40fc143439c 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
f40fc143439c 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
f40fc143439c 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.
f40fc143439c Add actual data structures for handling message catalogs, so that more code can be reused here between the frontends.
cmlenz
parents:
diff changeset
9 #
f40fc143439c 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
f40fc143439c 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
f40fc143439c 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/.
f40fc143439c Add actual data structures for handling message catalogs, so that more code can be reused here between the frontends.
cmlenz
parents:
diff changeset
13
419
3109e9d5f30f Testcase for fix of #148.
palgarvio
parents: 359
diff changeset
14 import copy
3109e9d5f30f Testcase for fix of #148.
palgarvio
parents: 359
diff changeset
15 import datetime
56
f40fc143439c 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
f40fc143439c 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
f40fc143439c Add actual data structures for handling message catalogs, so that more code can be reused here between the frontends.
cmlenz
parents:
diff changeset
18
606
c5dd3752bf2a ensure .mo file header contains the same information as the source .po file (#199)
fschwarz
parents: 570
diff changeset
19 from babel.dates import format_datetime
56
f40fc143439c Add actual data structures for handling message catalogs, so that more code can be reused here between the frontends.
cmlenz
parents:
diff changeset
20 from babel.messages import catalog
606
c5dd3752bf2a ensure .mo file header contains the same information as the source .po file (#199)
fschwarz
parents: 570
diff changeset
21 from babel.util import FixedOffsetTimezone
56
f40fc143439c Add actual data structures for handling message catalogs, so that more code can be reused here between the frontends.
cmlenz
parents:
diff changeset
22
f40fc143439c Add actual data structures for handling message catalogs, so that more code can be reused here between the frontends.
cmlenz
parents:
diff changeset
23
f40fc143439c Add actual data structures for handling message catalogs, so that more code can be reused here between the frontends.
cmlenz
parents:
diff changeset
24 class MessageTestCase(unittest.TestCase):
f40fc143439c Add actual data structures for handling message catalogs, so that more code can be reused here between the frontends.
cmlenz
parents:
diff changeset
25
f40fc143439c Add actual data structures for handling message catalogs, so that more code can be reused here between the frontends.
cmlenz
parents:
diff changeset
26 def test_python_format(self):
220
97b4b289e792 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 %d bar')
97b4b289e792 Added infrastructure for adding catalog checkers, and implement a checker that validations Python format parameters in translations, closing #19.
cmlenz
parents: 200
diff changeset
28 assert catalog.PYTHON_FORMAT.search('foo %s bar')
97b4b289e792 Added infrastructure for adding catalog checkers, and implement a checker that validations Python format parameters in translations, closing #19.
cmlenz
parents: 200
diff changeset
29 assert catalog.PYTHON_FORMAT.search('foo %r bar')
225
4f7f1f0e3b30 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).1f')
4f7f1f0e3b30 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)3.3f')
4f7f1f0e3b30 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)3f')
4f7f1f0e3b30 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)06d')
4f7f1f0e3b30 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)Li')
4f7f1f0e3b30 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)#d')
4f7f1f0e3b30 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)-4.4hs')
4f7f1f0e3b30 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)*.3f')
4f7f1f0e3b30 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')
4f7f1f0e3b30 Applied patch by Ramiro Morales for more extensive detection of Python string formatting specifiers. Closes #57.
cmlenz
parents: 220
diff changeset
39 assert catalog.PYTHON_FORMAT.search('foo %(name)3.*f')
4f7f1f0e3b30 Applied patch by Ramiro Morales for more extensive detection of Python string formatting specifiers. Closes #57.
cmlenz
parents: 220
diff changeset
40 assert catalog.PYTHON_FORMAT.search('foo %(name)*.*f')
358
8f06f485a0f1 Message.clone doesn't return a shallow copy any longer. This fixes a bug with update where flags where shared.
aronacher
parents: 350
diff changeset
41 assert catalog.PYTHON_FORMAT.search('foo %()s')
105
c62b68a0b65e `Message`, `read_po` and `write_po` now all handle user/auto comments correctly.
palgarvio
parents: 95
diff changeset
42
80
116e34b8cefa 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
43 def test_translator_comments(self):
105
c62b68a0b65e `Message`, `read_po` and `write_po` now all handle user/auto comments correctly.
palgarvio
parents: 95
diff changeset
44 mess = catalog.Message('foo', user_comments=['Comment About `foo`'])
200
1c778cccd330 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
45 self.assertEqual(mess.user_comments, ['Comment About `foo`'])
80
116e34b8cefa 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 mess = catalog.Message('foo',
105
c62b68a0b65e `Message`, `read_po` and `write_po` now all handle user/auto comments correctly.
palgarvio
parents: 95
diff changeset
47 auto_comments=['Comment 1 About `foo`',
80
116e34b8cefa 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`'])
105
c62b68a0b65e `Message`, `read_po` and `write_po` now all handle user/auto comments correctly.
palgarvio
parents: 95
diff changeset
49 self.assertEqual(mess.auto_comments, ['Comment 1 About `foo`',
80
116e34b8cefa 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
50 'Comment 2 About `foo`'])
56
f40fc143439c Add actual data structures for handling message catalogs, so that more code can be reused here between the frontends.
cmlenz
parents:
diff changeset
51
358
8f06f485a0f1 Message.clone doesn't return a shallow copy any longer. This fixes a bug with update where flags where shared.
aronacher
parents: 350
diff changeset
52 def test_clone_message_object(self):
8f06f485a0f1 Message.clone doesn't return a shallow copy any longer. This fixes a bug with update where flags where shared.
aronacher
parents: 350
diff changeset
53 msg = catalog.Message('foo', locations=[('foo.py', 42)])
8f06f485a0f1 Message.clone doesn't return a shallow copy any longer. This fixes a bug with update where flags where shared.
aronacher
parents: 350
diff changeset
54 clone = msg.clone()
8f06f485a0f1 Message.clone doesn't return a shallow copy any longer. This fixes a bug with update where flags where shared.
aronacher
parents: 350
diff changeset
55 clone.locations.append(('bar.py', 42))
8f06f485a0f1 Message.clone doesn't return a shallow copy any longer. This fixes a bug with update where flags where shared.
aronacher
parents: 350
diff changeset
56 self.assertEqual(msg.locations, [('foo.py', 42)])
359
5b587612cb45 Updated catalog test case for last commit, flags are now tested too in the clone test case.
aronacher
parents: 358
diff changeset
57 msg.flags.add('fuzzy')
5b587612cb45 Updated catalog test case for last commit, flags are now tested too in the clone test case.
aronacher
parents: 358
diff changeset
58 assert not clone.fuzzy and msg.fuzzy
358
8f06f485a0f1 Message.clone doesn't return a shallow copy any longer. This fixes a bug with update where flags where shared.
aronacher
parents: 350
diff changeset
59
56
f40fc143439c Add actual data structures for handling message catalogs, so that more code can be reused here between the frontends.
cmlenz
parents:
diff changeset
60
69
af75520471ed 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 class CatalogTestCase(unittest.TestCase):
544
ea0254950175 catalog.add() now returns the message instance (closes #245)
fschwarz
parents: 530
diff changeset
62 def test_add_returns_message_instance(self):
ea0254950175 catalog.add() now returns the message instance (closes #245)
fschwarz
parents: 530
diff changeset
63 cat = catalog.Catalog()
ea0254950175 catalog.add() now returns the message instance (closes #245)
fschwarz
parents: 530
diff changeset
64 message = cat.add('foo')
ea0254950175 catalog.add() now returns the message instance (closes #245)
fschwarz
parents: 530
diff changeset
65 self.assertEquals('foo', message.id)
69
af75520471ed 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
66
af75520471ed 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
67 def test_two_messages_with_same_singular(self):
af75520471ed 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
68 cat = catalog.Catalog()
af75520471ed 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
69 cat.add('foo')
af75520471ed 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
70 cat.add(('foo', 'foos'))
af75520471ed 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
71 self.assertEqual(1, len(cat))
95
f9007588a860 Fix for #11 (use local timezone in timestamps of generated POT).
cmlenz
parents: 89
diff changeset
72
227
b6927ec68261 Fix tests broken by [233], and add new tests.
cmlenz
parents: 225
diff changeset
73 def test_duplicate_auto_comment(self):
228
6582494abc36 Follow-up to [239]: also combine duplicate comments when writing PO files.
cmlenz
parents: 227
diff changeset
74 cat = catalog.Catalog()
6582494abc36 Follow-up to [239]: also combine duplicate comments when writing PO files.
cmlenz
parents: 227
diff changeset
75 cat.add('foo', auto_comments=['A comment'])
6582494abc36 Follow-up to [239]: also combine duplicate comments when writing PO files.
cmlenz
parents: 227
diff changeset
76 cat.add('foo', auto_comments=['A comment', 'Another comment'])
6582494abc36 Follow-up to [239]: also combine duplicate comments when writing PO files.
cmlenz
parents: 227
diff changeset
77 self.assertEqual(['A comment', 'Another comment'],
6582494abc36 Follow-up to [239]: also combine duplicate comments when writing PO files.
cmlenz
parents: 227
diff changeset
78 cat['foo'].auto_comments)
227
b6927ec68261 Fix tests broken by [233], and add new tests.
cmlenz
parents: 225
diff changeset
79
b6927ec68261 Fix tests broken by [233], and add new tests.
cmlenz
parents: 225
diff changeset
80 def test_duplicate_user_comment(self):
228
6582494abc36 Follow-up to [239]: also combine duplicate comments when writing PO files.
cmlenz
parents: 227
diff changeset
81 cat = catalog.Catalog()
6582494abc36 Follow-up to [239]: also combine duplicate comments when writing PO files.
cmlenz
parents: 227
diff changeset
82 cat.add('foo', user_comments=['A comment'])
6582494abc36 Follow-up to [239]: also combine duplicate comments when writing PO files.
cmlenz
parents: 227
diff changeset
83 cat.add('foo', user_comments=['A comment', 'Another comment'])
6582494abc36 Follow-up to [239]: also combine duplicate comments when writing PO files.
cmlenz
parents: 227
diff changeset
84 self.assertEqual(['A comment', 'Another comment'],
6582494abc36 Follow-up to [239]: also combine duplicate comments when writing PO files.
cmlenz
parents: 227
diff changeset
85 cat['foo'].user_comments)
227
b6927ec68261 Fix tests broken by [233], and add new tests.
cmlenz
parents: 225
diff changeset
86
230
28f6d855476f Forgot to update test method name after copy/paste.
cmlenz
parents: 229
diff changeset
87 def test_duplicate_location(self):
229
0c390005e92d Remove duplicate locations of catalog messages.
cmlenz
parents: 228
diff changeset
88 cat = catalog.Catalog()
0c390005e92d Remove duplicate locations of catalog messages.
cmlenz
parents: 228
diff changeset
89 cat.add('foo', locations=[('foo.py', 1)])
0c390005e92d Remove duplicate locations of catalog messages.
cmlenz
parents: 228
diff changeset
90 cat.add('foo', locations=[('foo.py', 1)])
0c390005e92d Remove duplicate locations of catalog messages.
cmlenz
parents: 228
diff changeset
91 self.assertEqual([('foo.py', 1)], cat['foo'].locations)
0c390005e92d Remove duplicate locations of catalog messages.
cmlenz
parents: 228
diff changeset
92
277
9886bf6f2d15 Fix for updating catalog messages that changed from gettext to ngettext or vice versa.
cmlenz
parents: 230
diff changeset
93 def test_update_message_changed_to_plural(self):
9886bf6f2d15 Fix for updating catalog messages that changed from gettext to ngettext or vice versa.
cmlenz
parents: 230
diff changeset
94 cat = catalog.Catalog()
9886bf6f2d15 Fix for updating catalog messages that changed from gettext to ngettext or vice versa.
cmlenz
parents: 230
diff changeset
95 cat.add(u'foo', u'Voh')
9886bf6f2d15 Fix for updating catalog messages that changed from gettext to ngettext or vice versa.
cmlenz
parents: 230
diff changeset
96 tmpl = catalog.Catalog()
9886bf6f2d15 Fix for updating catalog messages that changed from gettext to ngettext or vice versa.
cmlenz
parents: 230
diff changeset
97 tmpl.add((u'foo', u'foos'))
9886bf6f2d15 Fix for updating catalog messages that changed from gettext to ngettext or vice versa.
cmlenz
parents: 230
diff changeset
98 cat.update(tmpl)
9886bf6f2d15 Fix for updating catalog messages that changed from gettext to ngettext or vice versa.
cmlenz
parents: 230
diff changeset
99 self.assertEqual((u'Voh', ''), cat['foo'].string)
9886bf6f2d15 Fix for updating catalog messages that changed from gettext to ngettext or vice versa.
cmlenz
parents: 230
diff changeset
100 assert cat['foo'].fuzzy
9886bf6f2d15 Fix for updating catalog messages that changed from gettext to ngettext or vice versa.
cmlenz
parents: 230
diff changeset
101
9886bf6f2d15 Fix for updating catalog messages that changed from gettext to ngettext or vice versa.
cmlenz
parents: 230
diff changeset
102 def test_update_message_changed_to_simple(self):
9886bf6f2d15 Fix for updating catalog messages that changed from gettext to ngettext or vice versa.
cmlenz
parents: 230
diff changeset
103 cat = catalog.Catalog()
9886bf6f2d15 Fix for updating catalog messages that changed from gettext to ngettext or vice versa.
cmlenz
parents: 230
diff changeset
104 cat.add((u'foo' u'foos'), (u'Voh', u'Vöhs'))
9886bf6f2d15 Fix for updating catalog messages that changed from gettext to ngettext or vice versa.
cmlenz
parents: 230
diff changeset
105 tmpl = catalog.Catalog()
9886bf6f2d15 Fix for updating catalog messages that changed from gettext to ngettext or vice versa.
cmlenz
parents: 230
diff changeset
106 tmpl.add(u'foo')
9886bf6f2d15 Fix for updating catalog messages that changed from gettext to ngettext or vice versa.
cmlenz
parents: 230
diff changeset
107 cat.update(tmpl)
9886bf6f2d15 Fix for updating catalog messages that changed from gettext to ngettext or vice versa.
cmlenz
parents: 230
diff changeset
108 self.assertEqual(u'Voh', cat['foo'].string)
9886bf6f2d15 Fix for updating catalog messages that changed from gettext to ngettext or vice versa.
cmlenz
parents: 230
diff changeset
109 assert cat['foo'].fuzzy
9886bf6f2d15 Fix for updating catalog messages that changed from gettext to ngettext or vice versa.
cmlenz
parents: 230
diff changeset
110
89
eb4fea16aea5 Unittest for the problem reported by pjenvey fixed on [88].
palgarvio
parents: 80
diff changeset
111 def test_update_message_updates_comments(self):
eb4fea16aea5 Unittest for the problem reported by pjenvey fixed on [88].
palgarvio
parents: 80
diff changeset
112 cat = catalog.Catalog()
eb4fea16aea5 Unittest for the problem reported by pjenvey fixed on [88].
palgarvio
parents: 80
diff changeset
113 cat[u'foo'] = catalog.Message('foo', locations=[('main.py', 5)])
105
c62b68a0b65e `Message`, `read_po` and `write_po` now all handle user/auto comments correctly.
palgarvio
parents: 95
diff changeset
114 self.assertEqual(cat[u'foo'].auto_comments, [])
c62b68a0b65e `Message`, `read_po` and `write_po` now all handle user/auto comments correctly.
palgarvio
parents: 95
diff changeset
115 self.assertEqual(cat[u'foo'].user_comments, [])
89
eb4fea16aea5 Unittest for the problem reported by pjenvey fixed on [88].
palgarvio
parents: 80
diff changeset
116 # Update cat[u'foo'] with a new location and a comment
eb4fea16aea5 Unittest for the problem reported by pjenvey fixed on [88].
palgarvio
parents: 80
diff changeset
117 cat[u'foo'] = catalog.Message('foo', locations=[('main.py', 7)],
105
c62b68a0b65e `Message`, `read_po` and `write_po` now all handle user/auto comments correctly.
palgarvio
parents: 95
diff changeset
118 user_comments=['Foo Bar comment 1'])
c62b68a0b65e `Message`, `read_po` and `write_po` now all handle user/auto comments correctly.
palgarvio
parents: 95
diff changeset
119 self.assertEqual(cat[u'foo'].user_comments, ['Foo Bar comment 1'])
89
eb4fea16aea5 Unittest for the problem reported by pjenvey fixed on [88].
palgarvio
parents: 80
diff changeset
120 # now add yet another location with another comment
eb4fea16aea5 Unittest for the problem reported by pjenvey fixed on [88].
palgarvio
parents: 80
diff changeset
121 cat[u'foo'] = catalog.Message('foo', locations=[('main.py', 9)],
200
1c778cccd330 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
122 auto_comments=['Foo Bar comment 2'])
105
c62b68a0b65e `Message`, `read_po` and `write_po` now all handle user/auto comments correctly.
palgarvio
parents: 95
diff changeset
123 self.assertEqual(cat[u'foo'].auto_comments, ['Foo Bar comment 2'])
69
af75520471ed 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
124
165
628bc271ece4 Implement fuzzy matching to catalog updates. No frontend yet.
cmlenz
parents: 111
diff changeset
125 def test_update_fuzzy_matching_with_case_change(self):
628bc271ece4 Implement fuzzy matching to catalog updates. No frontend yet.
cmlenz
parents: 111
diff changeset
126 cat = catalog.Catalog()
628bc271ece4 Implement fuzzy matching to catalog updates. No frontend yet.
cmlenz
parents: 111
diff changeset
127 cat.add('foo', 'Voh')
628bc271ece4 Implement fuzzy matching to catalog updates. No frontend yet.
cmlenz
parents: 111
diff changeset
128 cat.add('bar', 'Bahr')
628bc271ece4 Implement fuzzy matching to catalog updates. No frontend yet.
cmlenz
parents: 111
diff changeset
129 tmpl = catalog.Catalog()
628bc271ece4 Implement fuzzy matching to catalog updates. No frontend yet.
cmlenz
parents: 111
diff changeset
130 tmpl.add('Foo')
181
8a762ce37bf7 The frontends now provide ways to update existing translations catalogs from a template. Closes #22.
cmlenz
parents: 165
diff changeset
131 cat.update(tmpl)
8a762ce37bf7 The frontends now provide ways to update existing translations catalogs from a template. Closes #22.
cmlenz
parents: 165
diff changeset
132 self.assertEqual(1, len(cat.obsolete))
165
628bc271ece4 Implement fuzzy matching to catalog updates. No frontend yet.
cmlenz
parents: 111
diff changeset
133 assert 'foo' not in cat
628bc271ece4 Implement fuzzy matching to catalog updates. No frontend yet.
cmlenz
parents: 111
diff changeset
134
628bc271ece4 Implement fuzzy matching to catalog updates. No frontend yet.
cmlenz
parents: 111
diff changeset
135 self.assertEqual('Voh', cat['Foo'].string)
628bc271ece4 Implement fuzzy matching to catalog updates. No frontend yet.
cmlenz
parents: 111
diff changeset
136 self.assertEqual(True, cat['Foo'].fuzzy)
628bc271ece4 Implement fuzzy matching to catalog updates. No frontend yet.
cmlenz
parents: 111
diff changeset
137
628bc271ece4 Implement fuzzy matching to catalog updates. No frontend yet.
cmlenz
parents: 111
diff changeset
138 def test_update_fuzzy_matching_with_char_change(self):
628bc271ece4 Implement fuzzy matching to catalog updates. No frontend yet.
cmlenz
parents: 111
diff changeset
139 cat = catalog.Catalog()
628bc271ece4 Implement fuzzy matching to catalog updates. No frontend yet.
cmlenz
parents: 111
diff changeset
140 cat.add('fo', 'Voh')
628bc271ece4 Implement fuzzy matching to catalog updates. No frontend yet.
cmlenz
parents: 111
diff changeset
141 cat.add('bar', 'Bahr')
628bc271ece4 Implement fuzzy matching to catalog updates. No frontend yet.
cmlenz
parents: 111
diff changeset
142 tmpl = catalog.Catalog()
628bc271ece4 Implement fuzzy matching to catalog updates. No frontend yet.
cmlenz
parents: 111
diff changeset
143 tmpl.add('foo')
181
8a762ce37bf7 The frontends now provide ways to update existing translations catalogs from a template. Closes #22.
cmlenz
parents: 165
diff changeset
144 cat.update(tmpl)
8a762ce37bf7 The frontends now provide ways to update existing translations catalogs from a template. Closes #22.
cmlenz
parents: 165
diff changeset
145 self.assertEqual(1, len(cat.obsolete))
165
628bc271ece4 Implement fuzzy matching to catalog updates. No frontend yet.
cmlenz
parents: 111
diff changeset
146 assert 'fo' not in cat
628bc271ece4 Implement fuzzy matching to catalog updates. No frontend yet.
cmlenz
parents: 111
diff changeset
147
628bc271ece4 Implement fuzzy matching to catalog updates. No frontend yet.
cmlenz
parents: 111
diff changeset
148 self.assertEqual('Voh', cat['foo'].string)
628bc271ece4 Implement fuzzy matching to catalog updates. No frontend yet.
cmlenz
parents: 111
diff changeset
149 self.assertEqual(True, cat['foo'].fuzzy)
628bc271ece4 Implement fuzzy matching to catalog updates. No frontend yet.
cmlenz
parents: 111
diff changeset
150
312
25b883553910 Fix catalog updating with fuzzy matches. Closes #82.
cmlenz
parents: 277
diff changeset
151 def test_update_fuzzy_matching_no_msgstr(self):
25b883553910 Fix catalog updating with fuzzy matches. Closes #82.
cmlenz
parents: 277
diff changeset
152 cat = catalog.Catalog()
25b883553910 Fix catalog updating with fuzzy matches. Closes #82.
cmlenz
parents: 277
diff changeset
153 cat.add('fo', '')
25b883553910 Fix catalog updating with fuzzy matches. Closes #82.
cmlenz
parents: 277
diff changeset
154 tmpl = catalog.Catalog()
25b883553910 Fix catalog updating with fuzzy matches. Closes #82.
cmlenz
parents: 277
diff changeset
155 tmpl.add('fo')
25b883553910 Fix catalog updating with fuzzy matches. Closes #82.
cmlenz
parents: 277
diff changeset
156 tmpl.add('foo')
25b883553910 Fix catalog updating with fuzzy matches. Closes #82.
cmlenz
parents: 277
diff changeset
157 cat.update(tmpl)
25b883553910 Fix catalog updating with fuzzy matches. Closes #82.
cmlenz
parents: 277
diff changeset
158 assert 'fo' in cat
25b883553910 Fix catalog updating with fuzzy matches. Closes #82.
cmlenz
parents: 277
diff changeset
159 assert 'foo' in cat
25b883553910 Fix catalog updating with fuzzy matches. Closes #82.
cmlenz
parents: 277
diff changeset
160
25b883553910 Fix catalog updating with fuzzy matches. Closes #82.
cmlenz
parents: 277
diff changeset
161 self.assertEqual('', cat['fo'].string)
25b883553910 Fix catalog updating with fuzzy matches. Closes #82.
cmlenz
parents: 277
diff changeset
162 self.assertEqual(False, cat['fo'].fuzzy)
25b883553910 Fix catalog updating with fuzzy matches. Closes #82.
cmlenz
parents: 277
diff changeset
163 self.assertEqual(None, cat['foo'].string)
25b883553910 Fix catalog updating with fuzzy matches. Closes #82.
cmlenz
parents: 277
diff changeset
164 self.assertEqual(False, cat['foo'].fuzzy)
25b883553910 Fix catalog updating with fuzzy matches. Closes #82.
cmlenz
parents: 277
diff changeset
165
350
9166eab61e29 More work on msgctxt support (#54).
cmlenz
parents: 313
diff changeset
166 def test_update_fuzzy_matching_with_new_context(self):
9166eab61e29 More work on msgctxt support (#54).
cmlenz
parents: 313
diff changeset
167 cat = catalog.Catalog()
9166eab61e29 More work on msgctxt support (#54).
cmlenz
parents: 313
diff changeset
168 cat.add('foo', 'Voh')
9166eab61e29 More work on msgctxt support (#54).
cmlenz
parents: 313
diff changeset
169 cat.add('bar', 'Bahr')
9166eab61e29 More work on msgctxt support (#54).
cmlenz
parents: 313
diff changeset
170 tmpl = catalog.Catalog()
9166eab61e29 More work on msgctxt support (#54).
cmlenz
parents: 313
diff changeset
171 tmpl.add('Foo', context='Menu')
9166eab61e29 More work on msgctxt support (#54).
cmlenz
parents: 313
diff changeset
172 cat.update(tmpl)
9166eab61e29 More work on msgctxt support (#54).
cmlenz
parents: 313
diff changeset
173 self.assertEqual(1, len(cat.obsolete))
9166eab61e29 More work on msgctxt support (#54).
cmlenz
parents: 313
diff changeset
174 assert 'foo' not in cat
9166eab61e29 More work on msgctxt support (#54).
cmlenz
parents: 313
diff changeset
175
9166eab61e29 More work on msgctxt support (#54).
cmlenz
parents: 313
diff changeset
176 message = cat.get('Foo', 'Menu')
9166eab61e29 More work on msgctxt support (#54).
cmlenz
parents: 313
diff changeset
177 self.assertEqual('Voh', message.string)
9166eab61e29 More work on msgctxt support (#54).
cmlenz
parents: 313
diff changeset
178 self.assertEqual(True, message.fuzzy)
9166eab61e29 More work on msgctxt support (#54).
cmlenz
parents: 313
diff changeset
179 self.assertEqual('Menu', message.context)
9166eab61e29 More work on msgctxt support (#54).
cmlenz
parents: 313
diff changeset
180
9166eab61e29 More work on msgctxt support (#54).
cmlenz
parents: 313
diff changeset
181 def test_update_fuzzy_matching_with_changed_context(self):
9166eab61e29 More work on msgctxt support (#54).
cmlenz
parents: 313
diff changeset
182 cat = catalog.Catalog()
9166eab61e29 More work on msgctxt support (#54).
cmlenz
parents: 313
diff changeset
183 cat.add('foo', 'Voh', context='Menu|File')
9166eab61e29 More work on msgctxt support (#54).
cmlenz
parents: 313
diff changeset
184 cat.add('bar', 'Bahr', context='Menu|File')
9166eab61e29 More work on msgctxt support (#54).
cmlenz
parents: 313
diff changeset
185 tmpl = catalog.Catalog()
9166eab61e29 More work on msgctxt support (#54).
cmlenz
parents: 313
diff changeset
186 tmpl.add('Foo', context='Menu|Edit')
9166eab61e29 More work on msgctxt support (#54).
cmlenz
parents: 313
diff changeset
187 cat.update(tmpl)
9166eab61e29 More work on msgctxt support (#54).
cmlenz
parents: 313
diff changeset
188 self.assertEqual(1, len(cat.obsolete))
9166eab61e29 More work on msgctxt support (#54).
cmlenz
parents: 313
diff changeset
189 assert cat.get('Foo', 'Menu|File') is None
9166eab61e29 More work on msgctxt support (#54).
cmlenz
parents: 313
diff changeset
190
9166eab61e29 More work on msgctxt support (#54).
cmlenz
parents: 313
diff changeset
191 message = cat.get('Foo', 'Menu|Edit')
9166eab61e29 More work on msgctxt support (#54).
cmlenz
parents: 313
diff changeset
192 self.assertEqual('Voh', message.string)
9166eab61e29 More work on msgctxt support (#54).
cmlenz
parents: 313
diff changeset
193 self.assertEqual(True, message.fuzzy)
9166eab61e29 More work on msgctxt support (#54).
cmlenz
parents: 313
diff changeset
194 self.assertEqual('Menu|Edit', message.context)
9166eab61e29 More work on msgctxt support (#54).
cmlenz
parents: 313
diff changeset
195
312
25b883553910 Fix catalog updating with fuzzy matches. Closes #82.
cmlenz
parents: 277
diff changeset
196 def test_update_fuzzy_matching_no_cascading(self):
25b883553910 Fix catalog updating with fuzzy matches. Closes #82.
cmlenz
parents: 277
diff changeset
197 cat = catalog.Catalog()
25b883553910 Fix catalog updating with fuzzy matches. Closes #82.
cmlenz
parents: 277
diff changeset
198 cat.add('fo', 'Voh')
25b883553910 Fix catalog updating with fuzzy matches. Closes #82.
cmlenz
parents: 277
diff changeset
199 cat.add('foo', 'Vohe')
25b883553910 Fix catalog updating with fuzzy matches. Closes #82.
cmlenz
parents: 277
diff changeset
200 tmpl = catalog.Catalog()
25b883553910 Fix catalog updating with fuzzy matches. Closes #82.
cmlenz
parents: 277
diff changeset
201 tmpl.add('fo')
25b883553910 Fix catalog updating with fuzzy matches. Closes #82.
cmlenz
parents: 277
diff changeset
202 tmpl.add('foo')
25b883553910 Fix catalog updating with fuzzy matches. Closes #82.
cmlenz
parents: 277
diff changeset
203 tmpl.add('fooo')
25b883553910 Fix catalog updating with fuzzy matches. Closes #82.
cmlenz
parents: 277
diff changeset
204 cat.update(tmpl)
25b883553910 Fix catalog updating with fuzzy matches. Closes #82.
cmlenz
parents: 277
diff changeset
205 assert 'fo' in cat
25b883553910 Fix catalog updating with fuzzy matches. Closes #82.
cmlenz
parents: 277
diff changeset
206 assert 'foo' in cat
25b883553910 Fix catalog updating with fuzzy matches. Closes #82.
cmlenz
parents: 277
diff changeset
207
25b883553910 Fix catalog updating with fuzzy matches. Closes #82.
cmlenz
parents: 277
diff changeset
208 self.assertEqual('Voh', cat['fo'].string)
25b883553910 Fix catalog updating with fuzzy matches. Closes #82.
cmlenz
parents: 277
diff changeset
209 self.assertEqual(False, cat['fo'].fuzzy)
25b883553910 Fix catalog updating with fuzzy matches. Closes #82.
cmlenz
parents: 277
diff changeset
210 self.assertEqual('Vohe', cat['foo'].string)
25b883553910 Fix catalog updating with fuzzy matches. Closes #82.
cmlenz
parents: 277
diff changeset
211 self.assertEqual(False, cat['foo'].fuzzy)
25b883553910 Fix catalog updating with fuzzy matches. Closes #82.
cmlenz
parents: 277
diff changeset
212 self.assertEqual('Vohe', cat['fooo'].string)
25b883553910 Fix catalog updating with fuzzy matches. Closes #82.
cmlenz
parents: 277
diff changeset
213 self.assertEqual(True, cat['fooo'].fuzzy)
25b883553910 Fix catalog updating with fuzzy matches. Closes #82.
cmlenz
parents: 277
diff changeset
214
165
628bc271ece4 Implement fuzzy matching to catalog updates. No frontend yet.
cmlenz
parents: 111
diff changeset
215 def test_update_without_fuzzy_matching(self):
628bc271ece4 Implement fuzzy matching to catalog updates. No frontend yet.
cmlenz
parents: 111
diff changeset
216 cat = catalog.Catalog()
628bc271ece4 Implement fuzzy matching to catalog updates. No frontend yet.
cmlenz
parents: 111
diff changeset
217 cat.add('fo', 'Voh')
628bc271ece4 Implement fuzzy matching to catalog updates. No frontend yet.
cmlenz
parents: 111
diff changeset
218 cat.add('bar', 'Bahr')
628bc271ece4 Implement fuzzy matching to catalog updates. No frontend yet.
cmlenz
parents: 111
diff changeset
219 tmpl = catalog.Catalog()
628bc271ece4 Implement fuzzy matching to catalog updates. No frontend yet.
cmlenz
parents: 111
diff changeset
220 tmpl.add('foo')
200
1c778cccd330 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
221 cat.update(tmpl, no_fuzzy_matching=True)
181
8a762ce37bf7 The frontends now provide ways to update existing translations catalogs from a template. Closes #22.
cmlenz
parents: 165
diff changeset
222 self.assertEqual(2, len(cat.obsolete))
165
628bc271ece4 Implement fuzzy matching to catalog updates. No frontend yet.
cmlenz
parents: 111
diff changeset
223
425
135950ca346c Fuzzy matching regarding plurals should *NOT* be checked against `len(message.id)` because this is always 2, instead, it's should be checked against `catalog.num_plurals`.
palgarvio
parents: 422
diff changeset
224 def test_fuzzy_matching_regarding_plurals(self):
135950ca346c Fuzzy matching regarding plurals should *NOT* be checked against `len(message.id)` because this is always 2, instead, it's should be checked against `catalog.num_plurals`.
palgarvio
parents: 422
diff changeset
225 cat = catalog.Catalog()
135950ca346c Fuzzy matching regarding plurals should *NOT* be checked against `len(message.id)` because this is always 2, instead, it's should be checked against `catalog.num_plurals`.
palgarvio
parents: 422
diff changeset
226 cat.add(('foo', 'foh'), ('foo', 'foh'))
135950ca346c Fuzzy matching regarding plurals should *NOT* be checked against `len(message.id)` because this is always 2, instead, it's should be checked against `catalog.num_plurals`.
palgarvio
parents: 422
diff changeset
227 ru = copy.copy(cat)
135950ca346c Fuzzy matching regarding plurals should *NOT* be checked against `len(message.id)` because this is always 2, instead, it's should be checked against `catalog.num_plurals`.
palgarvio
parents: 422
diff changeset
228 ru.locale = 'ru_RU'
135950ca346c Fuzzy matching regarding plurals should *NOT* be checked against `len(message.id)` because this is always 2, instead, it's should be checked against `catalog.num_plurals`.
palgarvio
parents: 422
diff changeset
229 ru.update(cat)
135950ca346c Fuzzy matching regarding plurals should *NOT* be checked against `len(message.id)` because this is always 2, instead, it's should be checked against `catalog.num_plurals`.
palgarvio
parents: 422
diff changeset
230 self.assertEqual(True, ru['foo'].fuzzy)
135950ca346c Fuzzy matching regarding plurals should *NOT* be checked against `len(message.id)` because this is always 2, instead, it's should be checked against `catalog.num_plurals`.
palgarvio
parents: 422
diff changeset
231 ru = copy.copy(cat)
135950ca346c Fuzzy matching regarding plurals should *NOT* be checked against `len(message.id)` because this is always 2, instead, it's should be checked against `catalog.num_plurals`.
palgarvio
parents: 422
diff changeset
232 ru.locale = 'ru_RU'
135950ca346c Fuzzy matching regarding plurals should *NOT* be checked against `len(message.id)` because this is always 2, instead, it's should be checked against `catalog.num_plurals`.
palgarvio
parents: 422
diff changeset
233 ru['foo'].string = ('foh', 'fohh', 'fohhh')
135950ca346c Fuzzy matching regarding plurals should *NOT* be checked against `len(message.id)` because this is always 2, instead, it's should be checked against `catalog.num_plurals`.
palgarvio
parents: 422
diff changeset
234 ru.update(cat)
135950ca346c Fuzzy matching regarding plurals should *NOT* be checked against `len(message.id)` because this is always 2, instead, it's should be checked against `catalog.num_plurals`.
palgarvio
parents: 422
diff changeset
235 self.assertEqual(False, ru['foo'].fuzzy)
135950ca346c Fuzzy matching regarding plurals should *NOT* be checked against `len(message.id)` because this is always 2, instead, it's should be checked against `catalog.num_plurals`.
palgarvio
parents: 422
diff changeset
236
313
ac8450a20e32 Merging catalogs would sometimes mix translations from different runs.
cmlenz
parents: 312
diff changeset
237 def test_update_no_template_mutation(self):
ac8450a20e32 Merging catalogs would sometimes mix translations from different runs.
cmlenz
parents: 312
diff changeset
238 tmpl = catalog.Catalog()
ac8450a20e32 Merging catalogs would sometimes mix translations from different runs.
cmlenz
parents: 312
diff changeset
239 tmpl.add('foo')
ac8450a20e32 Merging catalogs would sometimes mix translations from different runs.
cmlenz
parents: 312
diff changeset
240 cat1 = catalog.Catalog()
ac8450a20e32 Merging catalogs would sometimes mix translations from different runs.
cmlenz
parents: 312
diff changeset
241 cat1.add('foo', 'Voh')
ac8450a20e32 Merging catalogs would sometimes mix translations from different runs.
cmlenz
parents: 312
diff changeset
242 cat1.update(tmpl)
ac8450a20e32 Merging catalogs would sometimes mix translations from different runs.
cmlenz
parents: 312
diff changeset
243 cat2 = catalog.Catalog()
ac8450a20e32 Merging catalogs would sometimes mix translations from different runs.
cmlenz
parents: 312
diff changeset
244 cat2.update(tmpl)
ac8450a20e32 Merging catalogs would sometimes mix translations from different runs.
cmlenz
parents: 312
diff changeset
245
ac8450a20e32 Merging catalogs would sometimes mix translations from different runs.
cmlenz
parents: 312
diff changeset
246 self.assertEqual(None, cat2['foo'].string)
ac8450a20e32 Merging catalogs would sometimes mix translations from different runs.
cmlenz
parents: 312
diff changeset
247 self.assertEqual(False, cat2['foo'].fuzzy)
419
3109e9d5f30f Testcase for fix of #148.
palgarvio
parents: 359
diff changeset
248
3109e9d5f30f Testcase for fix of #148.
palgarvio
parents: 359
diff changeset
249 def test_update_po_updates_pot_creation_date(self):
3109e9d5f30f Testcase for fix of #148.
palgarvio
parents: 359
diff changeset
250 template = catalog.Catalog()
3109e9d5f30f Testcase for fix of #148.
palgarvio
parents: 359
diff changeset
251 localized_catalog = copy.deepcopy(template)
3109e9d5f30f Testcase for fix of #148.
palgarvio
parents: 359
diff changeset
252 localized_catalog.locale = 'de_DE'
3109e9d5f30f Testcase for fix of #148.
palgarvio
parents: 359
diff changeset
253 self.assertNotEqual(template.mime_headers,
3109e9d5f30f Testcase for fix of #148.
palgarvio
parents: 359
diff changeset
254 localized_catalog.mime_headers)
3109e9d5f30f Testcase for fix of #148.
palgarvio
parents: 359
diff changeset
255 self.assertEqual(template.creation_date,
3109e9d5f30f Testcase for fix of #148.
palgarvio
parents: 359
diff changeset
256 localized_catalog.creation_date)
3109e9d5f30f Testcase for fix of #148.
palgarvio
parents: 359
diff changeset
257 template.creation_date = datetime.datetime.now() - \
3109e9d5f30f Testcase for fix of #148.
palgarvio
parents: 359
diff changeset
258 datetime.timedelta(minutes=5)
3109e9d5f30f Testcase for fix of #148.
palgarvio
parents: 359
diff changeset
259 localized_catalog.update(template)
3109e9d5f30f Testcase for fix of #148.
palgarvio
parents: 359
diff changeset
260 self.assertEqual(template.creation_date,
3109e9d5f30f Testcase for fix of #148.
palgarvio
parents: 359
diff changeset
261 localized_catalog.creation_date)
422
2e98bb31626d Final and complete fix for #148.
palgarvio
parents: 419
diff changeset
262
2e98bb31626d Final and complete fix for #148.
palgarvio
parents: 419
diff changeset
263 def test_update_po_keeps_po_revision_date(self):
2e98bb31626d Final and complete fix for #148.
palgarvio
parents: 419
diff changeset
264 template = catalog.Catalog()
2e98bb31626d Final and complete fix for #148.
palgarvio
parents: 419
diff changeset
265 localized_catalog = copy.deepcopy(template)
2e98bb31626d Final and complete fix for #148.
palgarvio
parents: 419
diff changeset
266 localized_catalog.locale = 'de_DE'
2e98bb31626d Final and complete fix for #148.
palgarvio
parents: 419
diff changeset
267 fake_rev_date = datetime.datetime.now() - datetime.timedelta(days=5)
2e98bb31626d Final and complete fix for #148.
palgarvio
parents: 419
diff changeset
268 localized_catalog.revision_date = fake_rev_date
2e98bb31626d Final and complete fix for #148.
palgarvio
parents: 419
diff changeset
269 self.assertNotEqual(template.mime_headers,
2e98bb31626d Final and complete fix for #148.
palgarvio
parents: 419
diff changeset
270 localized_catalog.mime_headers)
2e98bb31626d Final and complete fix for #148.
palgarvio
parents: 419
diff changeset
271 self.assertEqual(template.creation_date,
2e98bb31626d Final and complete fix for #148.
palgarvio
parents: 419
diff changeset
272 localized_catalog.creation_date)
2e98bb31626d Final and complete fix for #148.
palgarvio
parents: 419
diff changeset
273 template.creation_date = datetime.datetime.now() - \
2e98bb31626d Final and complete fix for #148.
palgarvio
parents: 419
diff changeset
274 datetime.timedelta(minutes=5)
2e98bb31626d Final and complete fix for #148.
palgarvio
parents: 419
diff changeset
275 localized_catalog.update(template)
2e98bb31626d Final and complete fix for #148.
palgarvio
parents: 419
diff changeset
276 self.assertEqual(localized_catalog.revision_date, fake_rev_date)
69
af75520471ed 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
277
427
de2b8a211501 Fix Catalog._set_mime_headers' handing of negative offsets.
jruigrok
parents: 425
diff changeset
278 def test_stores_datetime_correctly(self):
de2b8a211501 Fix Catalog._set_mime_headers' handing of negative offsets.
jruigrok
parents: 425
diff changeset
279 localized = catalog.Catalog()
de2b8a211501 Fix Catalog._set_mime_headers' handing of negative offsets.
jruigrok
parents: 425
diff changeset
280 localized.locale = 'de_DE'
de2b8a211501 Fix Catalog._set_mime_headers' handing of negative offsets.
jruigrok
parents: 425
diff changeset
281 localized[''] = catalog.Message('',
de2b8a211501 Fix Catalog._set_mime_headers' handing of negative offsets.
jruigrok
parents: 425
diff changeset
282 "POT-Creation-Date: 2009-03-09 15:47-0700\n" +
de2b8a211501 Fix Catalog._set_mime_headers' handing of negative offsets.
jruigrok
parents: 425
diff changeset
283 "PO-Revision-Date: 2009-03-09 15:47-0700\n")
de2b8a211501 Fix Catalog._set_mime_headers' handing of negative offsets.
jruigrok
parents: 425
diff changeset
284 for key, value in localized.mime_headers:
de2b8a211501 Fix Catalog._set_mime_headers' handing of negative offsets.
jruigrok
parents: 425
diff changeset
285 if key in ('POT-Creation-Date', 'PO-Revision-Date'):
de2b8a211501 Fix Catalog._set_mime_headers' handing of negative offsets.
jruigrok
parents: 425
diff changeset
286 self.assertEqual(value, '2009-03-09 15:47-0700')
606
c5dd3752bf2a ensure .mo file header contains the same information as the source .po file (#199)
fschwarz
parents: 570
diff changeset
287
c5dd3752bf2a ensure .mo file header contains the same information as the source .po file (#199)
fschwarz
parents: 570
diff changeset
288 def test_mime_headers_contain_same_information_as_attributes(self):
c5dd3752bf2a ensure .mo file header contains the same information as the source .po file (#199)
fschwarz
parents: 570
diff changeset
289 cat = catalog.Catalog()
c5dd3752bf2a ensure .mo file header contains the same information as the source .po file (#199)
fschwarz
parents: 570
diff changeset
290 cat[''] = catalog.Message('',
c5dd3752bf2a ensure .mo file header contains the same information as the source .po file (#199)
fschwarz
parents: 570
diff changeset
291 "Last-Translator: Foo Bar <foo.bar@example.com>\n" +
c5dd3752bf2a ensure .mo file header contains the same information as the source .po file (#199)
fschwarz
parents: 570
diff changeset
292 "Language-Team: de <de@example.com>\n" +
c5dd3752bf2a ensure .mo file header contains the same information as the source .po file (#199)
fschwarz
parents: 570
diff changeset
293 "POT-Creation-Date: 2009-03-01 11:20+0200\n" +
c5dd3752bf2a ensure .mo file header contains the same information as the source .po file (#199)
fschwarz
parents: 570
diff changeset
294 "PO-Revision-Date: 2009-03-09 15:47-0700\n")
c5dd3752bf2a ensure .mo file header contains the same information as the source .po file (#199)
fschwarz
parents: 570
diff changeset
295 self.assertEqual(None, cat.locale)
c5dd3752bf2a ensure .mo file header contains the same information as the source .po file (#199)
fschwarz
parents: 570
diff changeset
296 mime_headers = dict(cat.mime_headers)
c5dd3752bf2a ensure .mo file header contains the same information as the source .po file (#199)
fschwarz
parents: 570
diff changeset
297
c5dd3752bf2a ensure .mo file header contains the same information as the source .po file (#199)
fschwarz
parents: 570
diff changeset
298 self.assertEqual('Foo Bar <foo.bar@example.com>', cat.last_translator)
c5dd3752bf2a ensure .mo file header contains the same information as the source .po file (#199)
fschwarz
parents: 570
diff changeset
299 self.assertEqual('Foo Bar <foo.bar@example.com>',
c5dd3752bf2a ensure .mo file header contains the same information as the source .po file (#199)
fschwarz
parents: 570
diff changeset
300 mime_headers['Last-Translator'])
c5dd3752bf2a ensure .mo file header contains the same information as the source .po file (#199)
fschwarz
parents: 570
diff changeset
301
c5dd3752bf2a ensure .mo file header contains the same information as the source .po file (#199)
fschwarz
parents: 570
diff changeset
302 self.assertEqual('de <de@example.com>', cat.language_team)
c5dd3752bf2a ensure .mo file header contains the same information as the source .po file (#199)
fschwarz
parents: 570
diff changeset
303 self.assertEqual('de <de@example.com>', mime_headers['Language-Team'])
c5dd3752bf2a ensure .mo file header contains the same information as the source .po file (#199)
fschwarz
parents: 570
diff changeset
304
c5dd3752bf2a ensure .mo file header contains the same information as the source .po file (#199)
fschwarz
parents: 570
diff changeset
305 dt = datetime.datetime(2009, 3, 9, 15, 47, tzinfo=FixedOffsetTimezone(-7 * 60))
c5dd3752bf2a ensure .mo file header contains the same information as the source .po file (#199)
fschwarz
parents: 570
diff changeset
306 self.assertEqual(dt, cat.revision_date)
c5dd3752bf2a ensure .mo file header contains the same information as the source .po file (#199)
fschwarz
parents: 570
diff changeset
307 formatted_dt = format_datetime(dt, 'yyyy-MM-dd HH:mmZ', locale='en')
c5dd3752bf2a ensure .mo file header contains the same information as the source .po file (#199)
fschwarz
parents: 570
diff changeset
308 self.assertEqual(formatted_dt, mime_headers['PO-Revision-Date'])
c5dd3752bf2a ensure .mo file header contains the same information as the source .po file (#199)
fschwarz
parents: 570
diff changeset
309
350
9166eab61e29 More work on msgctxt support (#54).
cmlenz
parents: 313
diff changeset
310
56
f40fc143439c Add actual data structures for handling message catalogs, so that more code can be reused here between the frontends.
cmlenz
parents:
diff changeset
311 def suite():
f40fc143439c Add actual data structures for handling message catalogs, so that more code can be reused here between the frontends.
cmlenz
parents:
diff changeset
312 suite = unittest.TestSuite()
570
a661a0360248 remove Python 2.3 conditional in test suite generation
fschwarz
parents: 544
diff changeset
313 suite.addTest(doctest.DocTestSuite(catalog, optionflags=doctest.ELLIPSIS))
56
f40fc143439c Add actual data structures for handling message catalogs, so that more code can be reused here between the frontends.
cmlenz
parents:
diff changeset
314 suite.addTest(unittest.makeSuite(MessageTestCase))
69
af75520471ed 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
315 suite.addTest(unittest.makeSuite(CatalogTestCase))
56
f40fc143439c Add actual data structures for handling message catalogs, so that more code can be reused here between the frontends.
cmlenz
parents:
diff changeset
316 return suite
f40fc143439c Add actual data structures for handling message catalogs, so that more code can be reused here between the frontends.
cmlenz
parents:
diff changeset
317
f40fc143439c Add actual data structures for handling message catalogs, so that more code can be reused here between the frontends.
cmlenz
parents:
diff changeset
318 if __name__ == '__main__':
f40fc143439c Add actual data structures for handling message catalogs, so that more code can be reused here between the frontends.
cmlenz
parents:
diff changeset
319 unittest.main(defaultTest='suite')
Copyright (C) 2012-2017 Edgewall Software