summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Madden <jamadden@gmail.com>2017-12-18 09:37:58 -0600
committerJason Madden <jamadden@gmail.com>2017-12-18 09:59:13 -0600
commit315083fb49516a81c8dff7bab5b7d29a3ed82de4 (patch)
tree9d62b5ae5ade823d583fbbf33cb9a15de87f6c67
parent5b0ee8a60ad660039591d48e755168a87a33c921 (diff)
downloadzope-i18n-315083fb49516a81c8dff7bab5b7d29a3ed82de4.tar.gz
Remove return value for compile_mo_file and test log messages instead. Also avoid testing for presence of mo file since that could be a race condition.
-rw-r--r--src/zope/i18n/compile.py8
-rw-r--r--src/zope/i18n/tests/test_compile.py23
2 files changed, 17 insertions, 14 deletions
diff --git a/src/zope/i18n/compile.py b/src/zope/i18n/compile.py
index 2856628..b63ebc7 100644
--- a/src/zope/i18n/compile.py
+++ b/src/zope/i18n/compile.py
@@ -25,9 +25,9 @@ def compile_mo_file(domain, lc_messages_path):
mofile = str(base + '.mo')
po_mtime = _safe_mtime(pofile)
- mo_mtime = _safe_mtime(mofile) if os.path.exists(mofile) else 0
+ mo_mtime = _safe_mtime(mofile) or 0
- if po_mtime is None or mo_mtime is None:
+ if po_mtime is None:
logger.debug("Unable to access either %s (%s) or %s (%s)",
pofile, po_mtime, mofile, mo_mtime)
return
@@ -43,11 +43,7 @@ def compile_mo_file(domain, lc_messages_path):
with closing(Msgfmt(pofd, domain).getAsFile()) as mo:
with open(mofile, 'wb') as fd:
fd.write(mo.read())
- # For testing we return distinct values for each scenario
- return True
except PoSyntaxError as err:
logger.warning('Syntax error while compiling %s (%s).', pofile, err.msg)
- return 0
except (IOError, OSError) as err:
logger.warning('Error while compiling %s (%s).', pofile, err)
- return False
diff --git a/src/zope/i18n/tests/test_compile.py b/src/zope/i18n/tests/test_compile.py
index 1aa7bd9..d82c3e7 100644
--- a/src/zope/i18n/tests/test_compile.py
+++ b/src/zope/i18n/tests/test_compile.py
@@ -14,6 +14,8 @@
import unittest
+from zope.testing.loggingsupport import InstalledHandler
+
from zope.i18n import compile
@@ -21,8 +23,11 @@ from zope.i18n import compile
"Need python-gettext")
class TestCompile(unittest.TestCase):
- def test_non_existant_path(self):
+ def setUp(self):
+ self.handler = InstalledHandler('zope.i18n')
+ self.addCleanup(self.handler.uninstall)
+ def test_non_existant_path(self):
self.assertIsNone(compile.compile_mo_file('no_such_domain', ''))
def test_po_exists_but_invalid(self):
@@ -30,15 +35,16 @@ class TestCompile(unittest.TestCase):
import shutil
import os.path
- td = tempfile.mkdtemp()
+ td = tempfile.mkdtemp(suffix=".zopei18n_test_compile")
self.addCleanup(shutil.rmtree, td)
with open(os.path.join(td, "foo.po"), 'w') as f:
f.write("this should not compile")
- self.assertEqual(
- 0,
- compile.compile_mo_file('foo', td))
+ compile.compile_mo_file('foo', td)
+
+ self.assertIn("Syntax error while compiling",
+ str(self.handler))
def test_po_exists_cannot_write_mo(self):
import tempfile
@@ -60,6 +66,7 @@ class TestCompile(unittest.TestCase):
with open(os.path.join(td, "foo.po"), 'w') as f:
f.write("# A comment")
- self.assertIs(
- False,
- compile.compile_mo_file('foo', td))
+ compile.compile_mo_file('foo', td)
+
+ self.assertIn("Error while compiling",
+ str(self.handler))