]> git.ipfire.org Git - thirdparty/babel.git/commitdiff
pybabel compile: exit with code 1 if errors were encountered 647/head
authorAarni Koskela <akx@iki.fi>
Mon, 27 May 2019 09:30:01 +0000 (12:30 +0300)
committerAarni Koskela <akx@iki.fi>
Mon, 27 May 2019 10:09:57 +0000 (13:09 +0300)
Fixes #627

.gitignore
babel/messages/frontend.py
tests/messages/data/project/i18n/fi_BUGGY/LC_MESSAGES/messages.po [new file with mode: 0644]
tests/messages/test_frontend.py

index 50e5838f6d804814573b98c77e616979254d3dd3..2886dec528b3c6e77c0109045a748bf4f7dfc6bb 100644 (file)
@@ -19,4 +19,5 @@ docs/_build
 test-env
 tests/messages/data/project/i18n/en_US
 tests/messages/data/project/i18n/long_messages.pot
-tests/messages/data/project/i18n/temp*
\ No newline at end of file
+tests/messages/data/project/i18n/temp*
+tests/messages/data/project/i18n/fi_BUGGY/LC_MESSAGES/*.mo
index f673f900ccebef99657238d58c12b815491b26e1..9e7c68ca18acae72983e216e8354cb92f1ebefd3 100644 (file)
@@ -182,8 +182,13 @@ class compile_catalog(Command):
                                        'or the base directory')
 
     def run(self):
+        n_errors = 0
         for domain in self.domain:
-            self._run_domain(domain)
+            for catalog, errors in self._run_domain(domain).items():
+                n_errors += len(errors)
+        if n_errors:
+            self.log.error('%d errors encountered.' % n_errors)
+        return (1 if n_errors else 0)
 
     def _run_domain(self, domain):
         po_files = []
@@ -219,6 +224,8 @@ class compile_catalog(Command):
         if not po_files:
             raise DistutilsOptionError('no message catalogs found')
 
+        catalogs_and_errors = {}
+
         for idx, (locale, po_file) in enumerate(po_files):
             mo_file = mo_files[idx]
             with open(po_file, 'rb') as infile:
@@ -241,7 +248,8 @@ class compile_catalog(Command):
                 self.log.info('catalog %s is marked as fuzzy, skipping', po_file)
                 continue
 
-            for message, errors in catalog.check():
+            catalogs_and_errors[catalog] = catalog_errors = list(catalog.check())
+            for message, errors in catalog_errors:
                 for error in errors:
                     self.log.error(
                         'error: %s:%d: %s', po_file, message.lineno, error
@@ -252,6 +260,8 @@ class compile_catalog(Command):
             with open(mo_file, 'wb') as outfile:
                 write_mo(outfile, catalog, use_fuzzy=self.use_fuzzy)
 
+        return catalogs_and_errors
+
 
 class extract_messages(Command):
     """Message extraction command for use in ``setup.py`` scripts.
diff --git a/tests/messages/data/project/i18n/fi_BUGGY/LC_MESSAGES/messages.po b/tests/messages/data/project/i18n/fi_BUGGY/LC_MESSAGES/messages.po
new file mode 100644 (file)
index 0000000..0a0745b
--- /dev/null
@@ -0,0 +1,5 @@
+msgid ""
+msgstr ""
+
+msgid "bar %(sign)s"
+msgstr "tanko %(merkki)s"
index fa0112c2eb1bbd8a6cf9a583c1ed46a243c9f88f..deaa66025f972cde13eb262538fe1fbf6b41c276 100644 (file)
@@ -1383,3 +1383,12 @@ def test_extract_add_location():
     assert isinstance(cmdinst, extract_messages)
     assert cmdinst.add_location == 'never'
     assert cmdinst.no_location
+
+
+def test_extract_error_code(monkeypatch, capsys):
+    monkeypatch.chdir(project_dir)
+    cmdinst = configure_cli_command("compile --domain=messages --directory i18n --locale fi_BUGGY")
+    assert cmdinst.run() == 1
+    out, err = capsys.readouterr()
+    # replace hack below for py2/py3 compatibility
+    assert "unknown named placeholder 'merkki'" in err.replace("u'", "'")