annotate babel/messages/tests/extract.py @ 87:f140be344563

Fixed de-pluralization bug introduced in [85] regarding the extraction of translator comments. Added a unittest which tests the extraction of translator comments that have non-translator comments right before the comment tag.
author palgarvio
date Sun, 10 Jun 2007 21:14:38 +0000
parents e10f82c1d4c4
children 30ed605cff51
rev   line source
3
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
1 # -*- coding: utf-8 -*-
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
2 #
14
29ef15a6fd75 * Removed pkg_resources/setuptools requirement from various places.
cmlenz
parents: 3
diff changeset
3 # Copyright (C) 2007 Edgewall Software
3
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
4 # All rights reserved.
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
5 #
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
6 # This software is licensed as described in the file COPYING, which
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
7 # you should have received as part of this distribution. The terms
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
8 # are also available at http://babel.edgewall.org/wiki/License.
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
9 #
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
10 # This software consists of voluntary contributions made by many
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
11 # individuals. For the exact contribution history, see the revision
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
12 # history and logs, available at http://babel.edgewall.org/log/.
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
13
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
14 import doctest
38
06b876ed5501 Fix for #8: fix extraction of strings from Python source using prefixes ('u' or 'r') or triple quotes.
cmlenz
parents: 14
diff changeset
15 from StringIO import StringIO
3
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
16 import unittest
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
17
56
27d55a07c897 Rename the `babel.catalog` package to `babel.messages` for consistency with the other package names.
cmlenz
parents: 38
diff changeset
18 from babel.messages import extract
3
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
19
38
06b876ed5501 Fix for #8: fix extraction of strings from Python source using prefixes ('u' or 'r') or triple quotes.
cmlenz
parents: 14
diff changeset
20
06b876ed5501 Fix for #8: fix extraction of strings from Python source using prefixes ('u' or 'r') or triple quotes.
cmlenz
parents: 14
diff changeset
21 class ExtractPythonTestCase(unittest.TestCase):
06b876ed5501 Fix for #8: fix extraction of strings from Python source using prefixes ('u' or 'r') or triple quotes.
cmlenz
parents: 14
diff changeset
22
06b876ed5501 Fix for #8: fix extraction of strings from Python source using prefixes ('u' or 'r') or triple quotes.
cmlenz
parents: 14
diff changeset
23 def test_unicode_string_arg(self):
06b876ed5501 Fix for #8: fix extraction of strings from Python source using prefixes ('u' or 'r') or triple quotes.
cmlenz
parents: 14
diff changeset
24 buf = StringIO("msg = _(u'Foo Bar')")
85
e10f82c1d4c4 Add unit tests for extracting translator comments from python sources.
cmlenz
parents: 82
diff changeset
25 messages = list(extract.extract_python(buf, ('_',), [], {}))
38
06b876ed5501 Fix for #8: fix extraction of strings from Python source using prefixes ('u' or 'r') or triple quotes.
cmlenz
parents: 14
diff changeset
26 self.assertEqual('Foo Bar', messages[0][2])
06b876ed5501 Fix for #8: fix extraction of strings from Python source using prefixes ('u' or 'r') or triple quotes.
cmlenz
parents: 14
diff changeset
27
85
e10f82c1d4c4 Add unit tests for extracting translator comments from python sources.
cmlenz
parents: 82
diff changeset
28 def test_comment_tag(self):
e10f82c1d4c4 Add unit tests for extracting translator comments from python sources.
cmlenz
parents: 82
diff changeset
29 buf = StringIO("""
e10f82c1d4c4 Add unit tests for extracting translator comments from python sources.
cmlenz
parents: 82
diff changeset
30 # NOTE: A translation comment
e10f82c1d4c4 Add unit tests for extracting translator comments from python sources.
cmlenz
parents: 82
diff changeset
31 msg = _(u'Foo Bar')
e10f82c1d4c4 Add unit tests for extracting translator comments from python sources.
cmlenz
parents: 82
diff changeset
32 """)
e10f82c1d4c4 Add unit tests for extracting translator comments from python sources.
cmlenz
parents: 82
diff changeset
33 messages = list(extract.extract_python(buf, ('_',), ['NOTE'], {}))
e10f82c1d4c4 Add unit tests for extracting translator comments from python sources.
cmlenz
parents: 82
diff changeset
34 self.assertEqual('Foo Bar', messages[0][2])
e10f82c1d4c4 Add unit tests for extracting translator comments from python sources.
cmlenz
parents: 82
diff changeset
35 self.assertEqual(['NOTE: A translation comment'], messages[0][3])
e10f82c1d4c4 Add unit tests for extracting translator comments from python sources.
cmlenz
parents: 82
diff changeset
36
e10f82c1d4c4 Add unit tests for extracting translator comments from python sources.
cmlenz
parents: 82
diff changeset
37 def test_comment_tag_multiline(self):
e10f82c1d4c4 Add unit tests for extracting translator comments from python sources.
cmlenz
parents: 82
diff changeset
38 buf = StringIO("""
e10f82c1d4c4 Add unit tests for extracting translator comments from python sources.
cmlenz
parents: 82
diff changeset
39 # NOTE: A translation comment
e10f82c1d4c4 Add unit tests for extracting translator comments from python sources.
cmlenz
parents: 82
diff changeset
40 # with a second line
e10f82c1d4c4 Add unit tests for extracting translator comments from python sources.
cmlenz
parents: 82
diff changeset
41 msg = _(u'Foo Bar')
e10f82c1d4c4 Add unit tests for extracting translator comments from python sources.
cmlenz
parents: 82
diff changeset
42 """)
e10f82c1d4c4 Add unit tests for extracting translator comments from python sources.
cmlenz
parents: 82
diff changeset
43 messages = list(extract.extract_python(buf, ('_',), ['NOTE'], {}))
e10f82c1d4c4 Add unit tests for extracting translator comments from python sources.
cmlenz
parents: 82
diff changeset
44 self.assertEqual('Foo Bar', messages[0][2])
e10f82c1d4c4 Add unit tests for extracting translator comments from python sources.
cmlenz
parents: 82
diff changeset
45 self.assertEqual(['NOTE: A translation comment', 'with a second line'],
e10f82c1d4c4 Add unit tests for extracting translator comments from python sources.
cmlenz
parents: 82
diff changeset
46 messages[0][3])
87
f140be344563 Fixed de-pluralization bug introduced in [85] regarding the extraction of translator comments.
palgarvio
parents: 85
diff changeset
47
f140be344563 Fixed de-pluralization bug introduced in [85] regarding the extraction of translator comments.
palgarvio
parents: 85
diff changeset
48 def test_translator_comments_with_previous_non_translator_comments(self):
f140be344563 Fixed de-pluralization bug introduced in [85] regarding the extraction of translator comments.
palgarvio
parents: 85
diff changeset
49 buf = StringIO("""
f140be344563 Fixed de-pluralization bug introduced in [85] regarding the extraction of translator comments.
palgarvio
parents: 85
diff changeset
50 # This shouldn't be in the output
f140be344563 Fixed de-pluralization bug introduced in [85] regarding the extraction of translator comments.
palgarvio
parents: 85
diff changeset
51 # because it didn't start with a comment tag
f140be344563 Fixed de-pluralization bug introduced in [85] regarding the extraction of translator comments.
palgarvio
parents: 85
diff changeset
52 # NOTE: A translation comment
f140be344563 Fixed de-pluralization bug introduced in [85] regarding the extraction of translator comments.
palgarvio
parents: 85
diff changeset
53 # with a second line
f140be344563 Fixed de-pluralization bug introduced in [85] regarding the extraction of translator comments.
palgarvio
parents: 85
diff changeset
54 msg = _(u'Foo Bar')
f140be344563 Fixed de-pluralization bug introduced in [85] regarding the extraction of translator comments.
palgarvio
parents: 85
diff changeset
55 """)
f140be344563 Fixed de-pluralization bug introduced in [85] regarding the extraction of translator comments.
palgarvio
parents: 85
diff changeset
56 messages = list(extract.extract_python(buf, ('_',), ['NOTE'], {}))
f140be344563 Fixed de-pluralization bug introduced in [85] regarding the extraction of translator comments.
palgarvio
parents: 85
diff changeset
57 self.assertEqual('Foo Bar', messages[0][2])
f140be344563 Fixed de-pluralization bug introduced in [85] regarding the extraction of translator comments.
palgarvio
parents: 85
diff changeset
58 self.assertEqual(['NOTE: A translation comment', 'with a second line'],
f140be344563 Fixed de-pluralization bug introduced in [85] regarding the extraction of translator comments.
palgarvio
parents: 85
diff changeset
59 messages[0][3])
85
e10f82c1d4c4 Add unit tests for extracting translator comments from python sources.
cmlenz
parents: 82
diff changeset
60
38
06b876ed5501 Fix for #8: fix extraction of strings from Python source using prefixes ('u' or 'r') or triple quotes.
cmlenz
parents: 14
diff changeset
61
3
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
62 def suite():
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
63 suite = unittest.TestSuite()
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
64 suite.addTest(doctest.DocTestSuite(extract))
38
06b876ed5501 Fix for #8: fix extraction of strings from Python source using prefixes ('u' or 'r') or triple quotes.
cmlenz
parents: 14
diff changeset
65 suite.addTest(unittest.makeSuite(ExtractPythonTestCase))
3
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
66 return suite
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
67
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
68 if __name__ == '__main__':
e9eaddab598e Import of initial code base.
cmlenz
parents:
diff changeset
69 unittest.main(defaultTest='suite')
Copyright (C) 2012-2017 Edgewall Software