summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristophe Monniez <moc@odoo.com>2019-05-28 14:01:23 +0000
committerChristophe Monniez <moc@odoo.com>2019-05-30 11:22:10 +0000
commitb27077bb0c3977c29597054d6206cea5e4d70265 (patch)
treeb76570fc685602c55040c33eda6323e678949cd7
parentd85451800f7b6d6404757b40400e3d5e4d25fa55 (diff)
[MOV] test_pylint, test_lint: add es-check linter
Because Odoo still supports Android Kitkat and Internet Explorer, ES5 is the highest ECMAScript allowed version. This commit adds a new test that parses each javascript file found in addons. The test fails if unsupported js code is found. As ES6 is allowed during tests, the files under a path that contains 'static/test' are just skipped. This test uses the es-check tool (https://www.npmjs.com/package/es-check). If the es-check tool cannot be found, the test is simply skipped. Also the test_pylint module is renamed to a more generic name test_lint, that way, every linter test can find a shelter here. closes odoo/odoo#33724 Signed-off-by: Christophe Monniez (moc) <moc@odoo.com>
-rw-r--r--odoo/addons/test_lint/__init__.py13
-rw-r--r--odoo/addons/test_lint/__manifest__.py (renamed from odoo/addons/test_pylint/__manifest__.py)5
-rw-r--r--odoo/addons/test_lint/tests/__init__.py2
-rw-r--r--odoo/addons/test_lint/tests/test_ecmascript.py48
-rw-r--r--odoo/addons/test_lint/tests/test_pylint.py (renamed from odoo/addons/test_pylint/tests/test_pylint.py)0
-rw-r--r--odoo/addons/test_pylint/__init__.py0
-rw-r--r--odoo/addons/test_pylint/tests/__init__.py1
7 files changed, 66 insertions, 3 deletions
diff --git a/odoo/addons/test_lint/__init__.py b/odoo/addons/test_lint/__init__.py
new file mode 100644
index 00000000000..0e68430dabe
--- /dev/null
+++ b/odoo/addons/test_lint/__init__.py
@@ -0,0 +1,13 @@
+# -*- coding: utf-8 -*-
+# Part of Odoo. See LICENSE file for full copyright and licensing details.
+
+from odoo import api, SUPERUSER_ID
+
+
+# TO REMOVE in master
+def uninstall_test_pylint(cr):
+ env = api.Environment(cr, SUPERUSER_ID, {})
+ env['ir.module.module'].search([
+ ('name', '=', 'test_pylint'),
+ ('state', '=', 'installed')
+ ]).write({'state': 'uninstalled'})
diff --git a/odoo/addons/test_pylint/__manifest__.py b/odoo/addons/test_lint/__manifest__.py
index 66f801454a5..554e20ba3b2 100644
--- a/odoo/addons/test_pylint/__manifest__.py
+++ b/odoo/addons/test_lint/__manifest__.py
@@ -1,11 +1,12 @@
# -*- coding: utf-8 -*-
{
- 'name': 'test-eval',
+ 'name': 'test-lint',
'version': '0.1',
'category': 'Tests',
- 'description': """A module to test Odoo with pylint.""",
+ 'description': """A module to test Odoo code with various linters.""",
'maintainer': 'Odoo SA',
'depends': ['base'],
'installable': True,
'auto_install': False,
+ 'pre_init_hook': 'uninstall_test_pylint'
}
diff --git a/odoo/addons/test_lint/tests/__init__.py b/odoo/addons/test_lint/tests/__init__.py
new file mode 100644
index 00000000000..03f1bd714d1
--- /dev/null
+++ b/odoo/addons/test_lint/tests/__init__.py
@@ -0,0 +1,2 @@
+import test_pylint
+import test_ecmascript
diff --git a/odoo/addons/test_lint/tests/test_ecmascript.py b/odoo/addons/test_lint/tests/test_ecmascript.py
new file mode 100644
index 00000000000..46008b0587d
--- /dev/null
+++ b/odoo/addons/test_lint/tests/test_ecmascript.py
@@ -0,0 +1,48 @@
+# -*- coding: utf-8 -*-
+# Part of Odoo. See LICENSE file for full copyright and licensing details.
+
+import logging
+import os
+import re
+import subprocess
+from unittest import skipIf
+from odoo.tests.common import TransactionCase
+from odoo import tools
+from odoo.modules import get_modules, get_module_path
+
+MAX_ES_VERSION = 'es5'
+
+_logger = logging.getLogger(__name__)
+
+try:
+ es_check = tools.misc.find_in_path('es-check')
+except IOError:
+ es_check = None
+
+
+@skipIf(es_check is None, "es-check tool not found on this system")
+class TestECMAScriptVersion(TransactionCase):
+
+ longMessage = True
+
+ def test_ecmascript_version(self):
+ """ Test that there is no unsupported ecmascript in javascript files """
+
+ black_re = re.compile(r'summernote.+(intro\.js|outro.js)$')
+
+ mod_paths = [get_module_path(m) for m in get_modules()]
+ files_to_check = []
+ for p in mod_paths:
+ for dp, _, file_names in os.walk(p):
+ if 'static/test' in dp:
+ continue
+ for fn in file_names:
+ fullpath_name = os.path.join(dp, fn)
+ if fullpath_name.endswith('.js') and not black_re.search(fullpath_name):
+ files_to_check.append(fullpath_name)
+
+ _logger.info('Testing %s js files', len(files_to_check))
+ cmd = [es_check, MAX_ES_VERSION] + files_to_check
+ process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+ out, err = process.communicate()
+ self.assertEqual(process.returncode, 0, msg=out)
diff --git a/odoo/addons/test_pylint/tests/test_pylint.py b/odoo/addons/test_lint/tests/test_pylint.py
index fd31bafe161..fd31bafe161 100644
--- a/odoo/addons/test_pylint/tests/test_pylint.py
+++ b/odoo/addons/test_lint/tests/test_pylint.py
diff --git a/odoo/addons/test_pylint/__init__.py b/odoo/addons/test_pylint/__init__.py
deleted file mode 100644
index e69de29bb2d..00000000000
--- a/odoo/addons/test_pylint/__init__.py
+++ /dev/null
diff --git a/odoo/addons/test_pylint/tests/__init__.py b/odoo/addons/test_pylint/tests/__init__.py
deleted file mode 100644
index c102da5600e..00000000000
--- a/odoo/addons/test_pylint/tests/__init__.py
+++ /dev/null
@@ -1 +0,0 @@
-import test_pylint