[test] Add a test ensuring new cube built from skeleton is flake8-compliant
authorDenis Laxalde <denis.laxalde@logilab.fr>
Fri, 29 Jan 2016 17:11:17 +0100
changeset 11176 4a43193ce7b0
parent 11175 df979f327e3f
child 11179 104d41c99180
[test] Add a test ensuring new cube built from skeleton is flake8-compliant And make skeleton files actually flake8-compliant henceforth.
cubicweb/devtools/test/requirements.txt
cubicweb/devtools/test/unittest_devctl.py
cubicweb/skeleton/__pkginfo__.py.tmpl
--- a/cubicweb/devtools/test/requirements.txt	Mon Jan 25 08:28:16 2016 +0100
+++ b/cubicweb/devtools/test/requirements.txt	Fri Jan 29 17:11:17 2016 +0100
@@ -1,2 +1,3 @@
 Twisted
 webtest
+flake8
--- a/cubicweb/devtools/test/unittest_devctl.py	Mon Jan 25 08:28:16 2016 +0100
+++ b/cubicweb/devtools/test/unittest_devctl.py	Fri Jan 29 17:11:17 2016 +0100
@@ -1,4 +1,4 @@
-# copyright 2003-2015 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
+# copyright 2003-2016 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
 #
 # This file is part of CubicWeb.
@@ -26,6 +26,14 @@
 from unittest import TestCase
 
 
+def newcube(directory, name):
+    cmd = [sys.executable, '-m' 'cubicweb', 'newcube',
+           '--directory', directory, name]
+    proc = Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=STDOUT)
+    stdout, _ = proc.communicate(b'short_desc\n')
+    return proc.returncode, stdout
+
+
 class CubicWebCtlTC(TestCase):
     """test case for devtools commands"""
 
@@ -39,15 +47,23 @@
                     '__pkginfo__.py', 'README', 'tox.ini']
         tmpdir = tempfile.mkdtemp(prefix="temp-cwctl-newcube")
         try:
-            cmd = [sys.executable, '-m', 'cubicweb', 'newcube',
-                   '--directory', tmpdir, 'foo']
-            proc = Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=STDOUT)
-            stdout, _ = proc.communicate(b'short_desc\n')
-            self.assertItemsEqual(os.listdir(osp.join(tmpdir, 'foo')),
-                                  expected)
+            retcode, stdout = newcube(tmpdir, 'foo')
+            self.assertItemsEqual(os.listdir(osp.join(tmpdir, 'foo')), expected)
         finally:
             shutil.rmtree(tmpdir, ignore_errors=True)
-        self.assertEqual(proc.returncode, 0, msg=stdout)
+        self.assertEqual(retcode, 0, msg=stdout)
+
+    def test_flake8(self):
+        """Ensure newcube built from skeleton is flake8-compliant"""
+        tmpdir = tempfile.mkdtemp(prefix="temp-cwctl-newcube-flake8")
+        try:
+            newcube(tmpdir, 'foo')
+            cmd = [sys.executable, '-m', 'flake8', osp.join(tmpdir, 'foo')]
+            proc = Popen(cmd, stdout=PIPE, stderr=STDOUT)
+            retcode = proc.wait()
+        finally:
+            shutil.rmtree(tmpdir, ignore_errors=True)
+        self.assertEqual(retcode, 0, proc.stdout.read())
 
 
 if __name__ == '__main__':
--- a/cubicweb/skeleton/__pkginfo__.py.tmpl	Mon Jan 25 08:28:16 2016 +0100
+++ b/cubicweb/skeleton/__pkginfo__.py.tmpl	Fri Jan 29 17:11:17 2016 +0100
@@ -1,6 +1,11 @@
 # pylint: disable=W0622
 """%(distname)s application packaging information"""
 
+from os import listdir as _listdir
+from os.path import join, isdir
+from glob import glob
+
+
 modname = '%(cubename)s'
 distname = '%(distname)s'
 
@@ -21,25 +26,21 @@
     'Framework :: CubicWeb',
     'Programming Language :: Python',
     'Programming Language :: JavaScript',
-    ]
-
-from os import listdir as _listdir
-from os.path import join, isdir
-from glob import glob
+]
 
 THIS_CUBE_DIR = join('share', 'cubicweb', 'cubes', modname)
 
 
 def listdir(dirpath):
     return [join(dirpath, fname) for fname in _listdir(dirpath)
-            if fname[0] != '.' and not fname.endswith('.pyc')
-            and not fname.endswith('~')
-            and not isdir(join(dirpath, fname))]
+            if fname[0] != '.' and not fname.endswith('.pyc') and
+            not fname.endswith('~') and
+            not isdir(join(dirpath, fname))]
 
 data_files = [
     # common files
     [THIS_CUBE_DIR, [fname for fname in glob('*.py') if fname != 'setup.py']],
-    ]
+]
 # check for possible extended cube layout
 for dname in ('entities', 'views', 'sobjects', 'hooks', 'schema', 'data',
               'wdoc', 'i18n', 'migration'):