]> git.ipfire.org Git - thirdparty/babel.git/commitdiff
Add test for frontend update_command 311/head
authorAarni Koskela <akx@iki.fi>
Thu, 31 Dec 2015 00:46:08 +0000 (02:46 +0200)
committerAarni Koskela <akx@iki.fi>
Mon, 4 Jan 2016 21:18:32 +0000 (23:18 +0200)
.gitignore
tests/messages/test_frontend.py

index 67ba223aa4350eb3cf5057bcb15a5f02fe298301..d8f8bc164274c763f8176bf21e3c004151b79626 100644 (file)
@@ -16,6 +16,6 @@ test-env
 babel/global.dat
 babel/global.dat.json
 tests/messages/data/project/i18n/long_messages.pot
-tests/messages/data/project/i18n/temp.pot
+tests/messages/data/project/i18n/temp*
 tests/messages/data/project/i18n/en_US
 /venv*
index 4676adc14363bd1922c6ff3c9d758ac6ffa03a71..f958b8050d44cb0eac47ec7c5d943006bd509cb4 100644 (file)
@@ -24,9 +24,9 @@ import unittest
 
 from babel import __version__ as VERSION
 from babel.dates import format_datetime
-from babel.messages import frontend
+from babel.messages import frontend, Catalog
 from babel.util import LOCALTZ
-from babel.messages.pofile import read_po
+from babel.messages.pofile import read_po, write_po
 from babel._compat import StringIO
 
 
@@ -1059,6 +1059,39 @@ compiling catalog %r to %r
             if os.path.isfile(mo_file):
                 os.unlink(mo_file)
 
+    def test_update(self):
+        template = Catalog()
+        template.add("1")
+        template.add("2")
+        template.add("3")
+        tmpl_file = os.path.join(self._i18n_dir(), 'temp-template.pot')
+        with open(tmpl_file, "wb") as outfp:
+            write_po(outfp, template)
+        po_file = os.path.join(self._i18n_dir(), 'temp1.po')
+        self.cli.run(sys.argv + ['init',
+            '-l', 'fi',
+            '-o', po_file,
+            '-i', tmpl_file
+        ])
+        with open(po_file, "r") as infp:
+            catalog = read_po(infp)
+            assert len(catalog) == 3
+
+        # Add another entry to the template
+
+        template.add("4")
+
+        with open(tmpl_file, "wb") as outfp:
+            write_po(outfp, template)
+
+        self.cli.run(sys.argv + ['update',
+            '-l', 'fi_FI',
+            '-o', po_file,
+            '-i', tmpl_file])
+
+        with open(po_file, "r") as infp:
+            catalog = read_po(infp)
+            assert len(catalog) == 4  # Catalog was updated
 
 def test_parse_mapping():
     buf = StringIO(