diff babel/messages/tests/extract.py @ 93:30ed605cff51

Changed translator comments extraction behaviour in python source code. Match is now true only if the TAG is on the start of the comment. The TAG will also be stripped from the comment. Added a unittest which tests this.
author palgarvio
date Mon, 11 Jun 2007 22:27:24 +0000
parents f140be344563
children 655b03680d84
line wrap: on
line diff
--- a/babel/messages/tests/extract.py
+++ b/babel/messages/tests/extract.py
@@ -30,9 +30,9 @@
 # NOTE: A translation comment
 msg = _(u'Foo Bar')
 """)
-        messages = list(extract.extract_python(buf, ('_',), ['NOTE'], {}))
+        messages = list(extract.extract_python(buf, ('_',), ['NOTE:'], {}))
         self.assertEqual('Foo Bar', messages[0][2])
-        self.assertEqual(['NOTE: A translation comment'], messages[0][3])
+        self.assertEqual(['A translation comment'], messages[0][3])
 
     def test_comment_tag_multiline(self):
         buf = StringIO("""
@@ -40,9 +40,9 @@
 # with a second line
 msg = _(u'Foo Bar')
 """)
-        messages = list(extract.extract_python(buf, ('_',), ['NOTE'], {}))
+        messages = list(extract.extract_python(buf, ('_',), ['NOTE:'], {}))
         self.assertEqual('Foo Bar', messages[0][2])
-        self.assertEqual(['NOTE: A translation comment', 'with a second line'],
+        self.assertEqual(['A translation comment', 'with a second line'],
                          messages[0][3])
         
     def test_translator_comments_with_previous_non_translator_comments(self):
@@ -53,12 +53,23 @@
 # with a second line
 msg = _(u'Foo Bar')
 """)
-        messages = list(extract.extract_python(buf, ('_',), ['NOTE'], {}))
+        messages = list(extract.extract_python(buf, ('_',), ['NOTE:'], {}))
         self.assertEqual('Foo Bar', messages[0][2])
-        self.assertEqual(['NOTE: A translation comment', 'with a second line'],
+        self.assertEqual(['A translation comment', 'with a second line'],
                          messages[0][3])
 
-
+    def test_comment_tags_not_on_start_of_comment(self):
+        buf = StringIO("""
+# This shouldn't be in the output
+# because it didn't start with a comment tag
+# do NOTE: this will no be a translation comment
+# NOTE: This one will be
+msg = _(u'Foo Bar')
+""")
+        messages = list(extract.extract_python(buf, ('_',), ['NOTE:'], {}))
+        self.assertEqual('Foo Bar', messages[0][2])
+        self.assertEqual(['This one will be'], messages[0][3])
+        
 def suite():
     suite = unittest.TestSuite()
     suite.addTest(doctest.DocTestSuite(extract))
Copyright (C) 2012-2017 Edgewall Software