Mercurial > babel > old > mirror
annotate babel/messages/tests/extract.py @ 85:e10f82c1d4c4
Add unit tests for extracting translator comments from python sources.
author | cmlenz |
---|---|
date | Sun, 10 Jun 2007 17:37:50 +0000 |
parents | f421e5576d26 |
children | f140be344563 |
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]) |
e10f82c1d4c4
Add unit tests for extracting translator comments from python sources.
cmlenz
parents:
82
diff
changeset
|
47 |
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
|
48 |
3 | 49 def suite(): |
50 suite = unittest.TestSuite() | |
51 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
|
52 suite.addTest(unittest.makeSuite(ExtractPythonTestCase)) |
3 | 53 return suite |
54 | |
55 if __name__ == '__main__': | |
56 unittest.main(defaultTest='suite') |