Commits

Felix Schwarz  committed b43b303

catalog.add() now returns the message instance (closes #245)

  • Participants
  • Parent commits f28ce69

Comments (0)

Files changed (6)

File babel/messages/catalog.py

 
         >>> catalog = Catalog()
         >>> catalog.add(u'foo')
+        <Message ...>
         >>> catalog[u'foo']
         <Message u'foo' (flags: [])>
 
         :param lineno: the line number on which the msgid line was found in the
                        PO file, if any
         :param context: the message context
+        :return: the newly added message
+        :rtype: `Message`
         """
-        self[id] = Message(id, string, list(locations), flags, auto_comments,
-                           user_comments, previous_id, lineno=lineno,
-                           context=context)
+        message = Message(id, string, list(locations), flags, auto_comments,
+                          user_comments, previous_id, lineno=lineno,
+                          context=context)
+        self[id] = message
+        return message
 
     def check(self):
         """Run various validation checks on the translations in the catalog.
         >>> from babel.messages import Catalog
         >>> template = Catalog()
         >>> template.add('green', locations=[('main.py', 99)])
+        <Message ...>
         >>> template.add('blue', locations=[('main.py', 100)])
+        <Message ...>
         >>> template.add(('salad', 'salads'), locations=[('util.py', 42)])
+        <Message ...>
         >>> catalog = Catalog(locale='de_DE')
         >>> catalog.add('blue', u'blau', locations=[('main.py', 98)])
+        <Message ...>
         >>> catalog.add('head', u'Kopf', locations=[('util.py', 33)])
+        <Message ...>
         >>> catalog.add(('salad', 'salads'), (u'Salat', u'Salate'),
         ...             locations=[('util.py', 38)])
+        <Message ...>
 
         >>> catalog.update(template)
         >>> len(catalog)

File babel/messages/mofile.py

     
     >>> catalog = Catalog(locale='en_US')
     >>> catalog.add('foo', 'Voh')
+    <Message ...>
     >>> catalog.add((u'bar', u'baz'), (u'Bahr', u'Batz'))
+    <Message ...>
     >>> catalog.add('fuz', 'Futz', flags=['fuzzy'])
+    <Message ...>
     >>> catalog.add('Fizz', '')
+    <Message ...>
     >>> catalog.add(('Fuzz', 'Fuzzes'), ('', ''))
+    <Message ...>
     >>> buf = StringIO()
     
     >>> write_mo(buf, catalog)

File babel/messages/pofile.py

     >>> catalog = Catalog()
     >>> catalog.add(u'foo %(name)s', locations=[('main.py', 1)],
     ...             flags=('fuzzy',))
+    <Message...>
     >>> catalog.add((u'bar', u'baz'), locations=[('main.py', 3)])
+    <Message...>
     >>> from StringIO import StringIO
     >>> buf = StringIO()
     >>> write_po(buf, catalog, omit_header=True)

File babel/messages/tests/catalog.py

 
 
 class CatalogTestCase(unittest.TestCase):
+    def test_add_returns_message_instance(self):
+        cat = catalog.Catalog()
+        message = cat.add('foo')
+        self.assertEquals('foo', message.id)
 
     def test_two_messages_with_same_singular(self):
         cat = catalog.Catalog()

File babel/messages/tests/mofile.py

 
 def suite():
     suite = unittest.TestSuite()
-    suite.addTest(doctest.DocTestSuite(mofile))
+    suite.addTest(doctest.DocTestSuite(mofile, optionflags=doctest.ELLIPSIS))
     suite.addTest(unittest.makeSuite(ReadMoTestCase))
     suite.addTest(unittest.makeSuite(WriteMoTestCase))
     return suite

File babel/messages/tests/pofile.py

 
 def suite():
     suite = unittest.TestSuite()
-    suite.addTest(doctest.DocTestSuite(pofile))
+    suite.addTest(doctest.DocTestSuite(pofile, optionflags=doctest.ELLIPSIS))
     suite.addTest(unittest.makeSuite(ReadPoTestCase))
     suite.addTest(unittest.makeSuite(WritePoTestCase))
     return suite