summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAarni Koskela <akx@iki.fi>2019-05-27 12:30:01 +0300
committerAarni Koskela <akx@iki.fi>2019-05-27 13:09:57 +0300
commitceb074a8f94e4a0d33bdab3ba54803488c0ce682 (patch)
tree721d5be8cb4976c88dd4ceae77d64a0f78ab0025
parent665c2ac12b95267383e726722d861e54f2d04fee (diff)
downloadbabel-ceb074a8f94e4a0d33bdab3ba54803488c0ce682.tar.gz
pybabel compile: exit with code 1 if errors were encountered
Fixes #627
-rw-r--r--.gitignore3
-rw-r--r--babel/messages/frontend.py14
-rw-r--r--tests/messages/data/project/i18n/fi_BUGGY/LC_MESSAGES/messages.po5
-rw-r--r--tests/messages/test_frontend.py9
4 files changed, 28 insertions, 3 deletions
diff --git a/.gitignore b/.gitignore
index 50e5838..2886dec 100644
--- a/.gitignore
+++ b/.gitignore
@@ -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
diff --git a/babel/messages/frontend.py b/babel/messages/frontend.py
index f673f90..9e7c68c 100644
--- a/babel/messages/frontend.py
+++ b/babel/messages/frontend.py
@@ -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
index 0000000..0a0745b
--- /dev/null
+++ b/tests/messages/data/project/i18n/fi_BUGGY/LC_MESSAGES/messages.po
@@ -0,0 +1,5 @@
+msgid ""
+msgstr ""
+
+msgid "bar %(sign)s"
+msgstr "tanko %(merkki)s"
diff --git a/tests/messages/test_frontend.py b/tests/messages/test_frontend.py
index fa0112c..deaa660 100644
--- a/tests/messages/test_frontend.py
+++ b/tests/messages/test_frontend.py
@@ -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'", "'")