From 4fdb07f81bdd0e461a168d5357ef8f05d9a897cb Mon Sep 17 00:00:00 2001 From: Christophe Monniez Date: Tue, 5 Nov 2019 14:08:38 +0000 Subject: [PATCH] [IMP] test_lint: add a test to detect git conflict markers Since the deployement of the forward-port bot, chances to merge code with conflict markers has greatly increased. With this commit, a new test is added to grep for those markers in most common code files. closes odoo/odoo#40029 X-original-commit: 19bf61c0e0c0464058064565be1051e5f43516ab Signed-off-by: Christophe Monniez (moc) --- odoo/addons/test_lint/tests/__init__.py | 1 + odoo/addons/test_lint/tests/test_markers.py | 37 +++++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 odoo/addons/test_lint/tests/test_markers.py diff --git a/odoo/addons/test_lint/tests/__init__.py b/odoo/addons/test_lint/tests/__init__.py index d085060f6bf..0b1bb8fb7bc 100644 --- a/odoo/addons/test_lint/tests/__init__.py +++ b/odoo/addons/test_lint/tests/__init__.py @@ -1,2 +1,3 @@ from . import test_pylint from . import test_ecmascript +from . import test_markers diff --git a/odoo/addons/test_lint/tests/test_markers.py b/odoo/addons/test_lint/tests/test_markers.py new file mode 100644 index 00000000000..264f0d570d7 --- /dev/null +++ b/odoo/addons/test_lint/tests/test_markers.py @@ -0,0 +1,37 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +import logging +import os +import odoo +from odoo.tests.common import TransactionCase + +_logger = logging.getLogger(__name__) +MARKERS = [b'<' * 7, b'>' * 7] +EXTENSIONS = ('.py', '.js', '.xml', '.less', '.sass') + + +class TestConflictMarkers(TransactionCase): + + def check_file(self, fullpath_name): + + with open(fullpath_name, 'rb') as f: + content = f.read() + self.assertFalse(any([m in content for m in MARKERS]), 'Conflict markers found in %s' % fullpath_name) + + def test_conflict_markers(self): + """ Test that there are no conflict markers left in Odoo files """ + + counter = 0 + + odoo_path = os.path.dirname(odoo.__file__) + paths = odoo.addons.__path__ + [odoo_path] + paths.remove(os.path.join(odoo_path, 'addons')) # avoid checking odoo/addons twice + + for p in paths: + for dp, _, file_names in os.walk(p): + for fn in file_names: + if fn.endswith(EXTENSIONS): + self.check_file(os.path.join(dp, fn)) + counter += 1 + _logger.info('%s files tested', counter)