[test] Use a Popen in i18n tests
authorDenis Laxalde <denis.laxalde@logilab.fr>
Wed, 16 Mar 2016 11:31:40 +0100
changeset 11208 fe57dc4adfea
parent 11207 d7c7423f4ea6
child 11209 631fe2751b73
[test] Use a Popen in i18n tests Instead of check_call, so that we clearly see the failure. A bit of flake8 along the way.
cubicweb/devtools/test/unittest_i18n.py
--- a/cubicweb/devtools/test/unittest_i18n.py	Tue May 06 17:45:37 2014 +0200
+++ b/cubicweb/devtools/test/unittest_i18n.py	Wed Mar 16 11:31:40 2016 +0100
@@ -18,16 +18,17 @@
 # with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
 """unit tests for i18n messages generator"""
 
-import os, os.path as osp
+import os
+import os.path as osp
 import sys
-import subprocess
+from subprocess import PIPE, Popen, STDOUT
 
 from unittest import TestCase, main
 
-from cubicweb.cwconfig import CubicWebNoAppConfiguration
 
 DATADIR = osp.join(osp.abspath(osp.dirname(__file__)), 'data')
 
+
 def load_po(fname):
     """load a po file and  return a set of encountered (msgid, msgctx)"""
     msgs = set()
@@ -38,7 +39,7 @@
                 continue
             if line.startswith('msgstr'):
                 assert not (msgid, msgctxt) in msgs
-                msgs.add( (msgid, msgctxt) )
+                msgs.add((msgid, msgctxt))
                 msgid = msgctxt = None
             elif line.startswith('msgid'):
                 msgid = line.split(' ', 1)[1][1:-1]
@@ -62,10 +63,10 @@
         else:
             env['PYTHONPATH'] = ''
         env['PYTHONPATH'] += DATADIR
-        with open(os.devnull, 'w') as devnull:
-            subprocess.check_call(
-                [sys.executable, '-m', 'cubicweb', 'i18ncube', 'i18ntestcube'],
-                env=env, stdout=devnull)
+        cmd = [sys.executable, '-m', 'cubicweb', 'i18ncube', 'i18ntestcube']
+        proc = Popen(cmd, env=env, stdout=PIPE, stderr=STDOUT)
+        stdout, _ = proc.communicate()
+        self.assertEqual(proc.returncode, 0, msg=stdout)
         cube = osp.join(DATADIR, 'cubes', 'i18ntestcube')
         msgs = load_po(osp.join(cube, 'i18n', 'en.po.ref'))
         newmsgs = load_po(osp.join(cube, 'i18n', 'en.po'))