Mercurial > babel > old > mirror
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 | 1 # -*- coding: utf-8 -*- |
2 # | |
14
29ef15a6fd75
* Removed pkg_resources/setuptools requirement from various places.
cmlenz
parents:
3
diff
changeset
|
3 # Copyright (C) 2007 Edgewall Software |
3 | 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 | |
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 | 16 import unittest |
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 | 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 | 62 def suite(): |
63 suite = unittest.TestSuite() | |
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 | 66 return suite |
67 | |
68 if __name__ == '__main__': | |
69 unittest.main(defaultTest='suite') |