diff --git a/src/doblib/__init__.py b/src/doblib/__init__.py index c130786..3bc471b 100644 --- a/src/doblib/__init__.py +++ b/src/doblib/__init__.py @@ -1 +1 @@ -VERSION = "0.19.2" +VERSION = "0.19.4" diff --git a/src/doblib/ci.py b/src/doblib/ci.py index 6ac11f6..15a095e 100644 --- a/src/doblib/ci.py +++ b/src/doblib/ci.py @@ -107,17 +107,22 @@ def _ci_isort(self, options, args, paths, ignores): return utils.call(*cmd, *args, *paths, pipe=False) def _ci_prettier(self, options, args, paths, ignores): - """ """ + """Run prettier on supported files""" executable = shutil.which("prettier") if not executable: utils.error("prettier is not installed") return 1 - files = [] + files = set() + + extensions = self.get( + base.SECTION, "prettier", "extension", default=["js", "xml"] + ) for path in paths: - files.extend(glob.glob(f"{path}/**/*.js", recursive=True)) + for ext in extensions: + files.update(glob.glob(f"{path}/**/*.{ext}", recursive=True)) - files = list( + files = sorted( filter( lambda path: not any( fnmatch(path, f"*/{pattern}") @@ -132,21 +137,30 @@ def _ci_prettier(self, options, args, paths, ignores): if not files: return 0 - cmd = ["prettier"] + cmd = ["prettier", "--check"] if options.fix: cmd.append("--write") + config_path = self.get( + base.SECTION, "prettier", "config", default=".prettierrc.yml" + ) + if os.path.isfile(config_path): + cmd.append(f"--config {config_path}") + return utils.call(*cmd, *args, *files, pipe=False) def _ci_pylint(self, options, args, paths, ignores): """Run pylint tests for Odoo""" - files = [] + files = set() + + extensions = self.get( + base.SECTION, "pylint", "extension", default=["csv", "py", "xml"] + ) for path in paths: - files.extend(glob.glob(f"{path}/**/*.csv", recursive=True)) - files.extend(glob.glob(f"{path}/**/*.py", recursive=True)) - files.extend(glob.glob(f"{path}/**/*.xml", recursive=True)) + for ext in extensions: + files.update(glob.glob(f"{path}/**/*.{ext}", recursive=True)) - files = list( + files = sorted( filter( lambda path: not any( fnmatch(path, f"*/{pattern}") @@ -162,15 +176,15 @@ def _ci_pylint(self, options, args, paths, ignores): return 0 cmd = [sys.executable, "-m", "pylint"] - if os.path.isfile(".pylintrc"): - cmd.append("--rcfile=.pylintrc") + config_path = self.get(base.SECTION, "pylint", "config", default=".pylintrc") + if os.path.isfile(config_path): + cmd.append(f"--rcfile={config_path}") return utils.call(*cmd, *args, *files, pipe=False) def _ci_paths(self): - return ( - self.get("odoo", "addons_path", default=[]) - + self.get("bootstrap", "ci_path", default=[]) + return self.get("odoo", "addons_path", default=[]) + self.get( + base.SECTION, "ci_path", default=[] ) def ci(self, ci, args=None): @@ -178,7 +192,7 @@ def ci(self, ci, args=None): args, left = load_ci_arguments(args or []) # Always include this script in the tests - ignores = self.get("bootstrap", "blacklist", default=[]) + ignores = self.get(base.SECTION, "blacklist", default=[]) func = getattr(self, f"_ci_{ci}", None) if ci in CI and callable(func): return func(args, left, self._ci_paths(), ignores) diff --git a/tests/test_action.py b/tests/test_action.py index 5b3450c..e1d9f08 100644 --- a/tests/test_action.py +++ b/tests/test_action.py @@ -426,6 +426,8 @@ def test_apply_action(env): odoo = sys.modules["odoo"] = mock.MagicMock() sys.modules["odoo.tools"] = mock.MagicMock() + sys.modules["odoo.modules"] = mock.MagicMock() + sys.modules["odoo.modules.registry"] = mock.MagicMock() sys.modules["odoo.release"] = odoo.release odoo.release.version_info = (14, 0) env._init_odoo.return_value = True diff --git a/tests/test_ci.py b/tests/test_ci.py index a64c51d..8ab3372 100644 --- a/tests/test_ci.py +++ b/tests/test_ci.py @@ -26,6 +26,8 @@ def env(): def test_test(pytest_mock, env): odoo = sys.modules["odoo"] = mock.MagicMock() tools = sys.modules["odoo.tools"] = mock.MagicMock() + sys.modules["odoo.modules"] = mock.MagicMock() + sys.modules["odoo.modules.registry"] = mock.MagicMock() sys.modules["odoo.release"] = odoo.release odoo.release.version_info = (14, 0) @@ -143,15 +145,16 @@ def test_ci_prettier(which, call, env): with mock.patch( "glob.glob", return_value=[ - "test15/path/file.py", - "folder/test123/file.py", "folder/path/test196.py", + "folder/test123/file.py", + "test15/path/file.py", "test2/path/file.py", ], ): assert env.ci("prettier", ["--fix"]) == 42 call.assert_called_once_with( "prettier", + "--check", "--write", "test2/path/file.py", pipe=False, @@ -176,8 +179,6 @@ def test_ci_pylint(call, glob, env): "pylint", "--rcfile=.pylintrc", "test2/path/file.py", - "test2/path/file.py", - "test2/path/file.py", pipe=False, ) @@ -189,8 +190,6 @@ def test_ci_pylint(call, glob, env): "pylint", "--rcfile=.pylintrc", "test2/path/file.py", - "test2/path/file.py", - "test2/path/file.py", pipe=False, ) diff --git a/tests/test_environment.py b/tests/test_environment.py index 2391d9e..92e7144 100644 --- a/tests/test_environment.py +++ b/tests/test_environment.py @@ -110,13 +110,15 @@ def test_env(env): with env.env("odoo"): pass - odoo = sys.modules["odoo"] = mock.MagicMock() - reg = odoo.registry.return_value = mock.MagicMock() + sys.modules["odoo"] = mock.MagicMock() + sys.modules["odoo.modules"] = mock.MagicMock() + registry = sys.modules["odoo.modules.registry"] = mock.MagicMock() + reg = registry.Registry.return_value = mock.MagicMock() cr = reg.cursor.return_value = mock.MagicMock() # Test the normal commit with env.env("odoo"): - odoo.registry.assert_called_once_with("odoo") + registry.Registry.assert_called_once_with("odoo") cr.commit.assert_not_called() cr.commit.assert_called_once() diff --git a/tests/test_migrate.py b/tests/test_migrate.py index 129082a..ad4acfe 100644 --- a/tests/test_migrate.py +++ b/tests/test_migrate.py @@ -24,6 +24,8 @@ def env(): def test_migrate(repos, env): odoo = sys.modules["odoo"] = mock.MagicMock() tools = sys.modules["odoo.tools"] = mock.MagicMock() + sys.modules["odoo.modules"] = mock.MagicMock() + sys.modules["odoo.modules.registry"] = mock.MagicMock() tools.config.__getitem__.return_value = "odoo" sys.modules["odoo.release"] = odoo.release odoo.release.version_info = (14, 0) diff --git a/tests/test_module.py b/tests/test_module.py index 369a6f1..3d2c8b9 100644 --- a/tests/test_module.py +++ b/tests/test_module.py @@ -86,6 +86,8 @@ def test_get_installed_modules(env): def test_install_all(env): odoo = sys.modules["odoo"] = mock.MagicMock() sys.modules["odoo.tools"] = mock.MagicMock() + sys.modules["odoo.modules"] = mock.MagicMock() + sys.modules["odoo.modules.registry"] = mock.MagicMock() env.install_all("odoo", ["module"]) odoo.modules.registry.Registry.new.assert_called_once_with( @@ -101,6 +103,8 @@ def test_install_all(env): def test_update_all(env): odoo = sys.modules["odoo"] = mock.MagicMock() sys.modules["odoo.tools"] = mock.MagicMock() + sys.modules["odoo.modules"] = mock.MagicMock() + sys.modules["odoo.modules.registry"] = mock.MagicMock() env.update_specific("odoo", installed=True) odoo.modules.registry.Registry.new.assert_called_once_with( @@ -112,6 +116,8 @@ def test_update_all(env): def test_update_listed(env): odoo = sys.modules["odoo"] = mock.MagicMock() sys.modules["odoo.tools"] = mock.MagicMock() + sys.modules["odoo.modules"] = mock.MagicMock() + sys.modules["odoo.modules.registry"] = mock.MagicMock() env._get_modules = mock.MagicMock() env.update_specific("odoo", listed=True) @@ -143,6 +149,8 @@ def test_update(env): # Quite complex and we have to mock plenty of stuff odoo = sys.modules["odoo"] = mock.MagicMock() tools = sys.modules["odoo.tools"] = mock.MagicMock() + sys.modules["odoo.modules"] = mock.MagicMock() + sys.modules["odoo.modules.registry"] = mock.MagicMock() sys.modules["odoo.release"] = odoo.release tools.config.__getitem__.return_value = "odoo" odoo.release.version_info = (14, 0)