changeset 85:e10f82c1d4c4

Add unit tests for extracting translator comments from python sources.
author cmlenz
date Sun, 10 Jun 2007 17:37:50 +0000
parents 3c6421bca777
children 8a703ecdba91
files babel/messages/tests/extract.py doc/catalogs.txt
diffstat 2 files changed, 27 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/babel/messages/tests/extract.py
+++ b/babel/messages/tests/extract.py
@@ -22,9 +22,29 @@
 
     def test_unicode_string_arg(self):
         buf = StringIO("msg = _(u'Foo Bar')")
-        messages = list(extract.extract_python(buf, ('_',), {}, []))
+        messages = list(extract.extract_python(buf, ('_',), [], {}))
         self.assertEqual('Foo Bar', messages[0][2])
 
+    def test_comment_tag(self):
+        buf = StringIO("""
+# NOTE: A translation comment
+msg = _(u'Foo Bar')
+""")
+        messages = list(extract.extract_python(buf, ('_',), ['NOTE'], {}))
+        self.assertEqual('Foo Bar', messages[0][2])
+        self.assertEqual(['NOTE: A translation comment'], messages[0][3])
+
+    def test_comment_tag_multiline(self):
+        buf = StringIO("""
+# NOTE: A translation comment
+# with a second line
+msg = _(u'Foo Bar')
+""")
+        messages = list(extract.extract_python(buf, ('_',), ['NOTE'], {}))
+        self.assertEqual('Foo Bar', messages[0][2])
+        self.assertEqual(['NOTE: A translation comment', 'with a second line'],
+                         messages[0][3])
+
 
 def suite():
     suite = unittest.TestSuite()
--- a/doc/catalogs.txt
+++ b/doc/catalogs.txt
@@ -185,6 +185,12 @@
         :rtype: ``iterator``
         """
 
+.. note:: Any strings in the tuples produced by this function must be either
+          ``unicode`` objects, or ``str`` objects using plain ASCII characters.
+          That means that if sources contain strings using other encodings, it
+          is the job of the extractor implementation to do the decoding to
+          ``unicode`` objects.
+
 Next, you should register that function as an entry point. This requires your
 ``setup.py`` script to use `setuptools`_, and your package to be installed with
 the necessary metadata. If that's taken care of, add something like the
Copyright (C) 2012-2017 Edgewall Software