From bdc597ddb53f902eb53daa887d1d62da46fab90c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Bidoul?= Date: Tue, 18 Oct 2022 16:37:22 +0200 Subject: [PATCH 1/2] Use version_info instead of parse_version --- click_odoo_contrib/initdb.py | 9 ++------- click_odoo_contrib/update.py | 6 +----- tests/test_manifest.py | 4 ++-- tests/test_update.py | 2 +- 4 files changed, 6 insertions(+), 15 deletions(-) diff --git a/click_odoo_contrib/initdb.py b/click_odoo_contrib/initdb.py index 0875b67..c3c8ed1 100644 --- a/click_odoo_contrib/initdb.py +++ b/click_odoo_contrib/initdb.py @@ -18,7 +18,6 @@ from .update import _save_installed_checksums _logger = logging.getLogger(__name__) -_odoo_version = odoo.tools.parse_version(odoo.release.version) EXCLUDE_PATTERNS = ("*.pyc", "*.pyo") @@ -48,7 +47,7 @@ def _db_storage(self): # make sure attachments created during db initialization # are stored in database, so we get something consistent # when recreating the db by copying the cached template - if _odoo_version >= odoo.tools.parse_version("12"): + if odoo.release.version_info >= (12, 0): from odoo.addons.base.models.ir_attachment import IrAttachment else: from odoo.addons.base.ir.ir_attachment import IrAttachment @@ -65,11 +64,7 @@ def odoo_createdb(dbname, demo, module_names, force_db_storage): odoo.service.db._create_empty_database(dbname) odoo.tools.config["init"] = dict.fromkeys(module_names, 1) odoo.tools.config["without_demo"] = not demo - if _odoo_version < odoo.tools.parse_version("10"): - Registry = odoo.modules.registry.RegistryManager - else: - Registry = odoo.modules.registry.Registry - Registry.new(dbname, force_demo=demo, update_module=True) + odoo.modules.registry.Registry.new(dbname, force_demo=demo, update_module=True) _logger.info( click.style( "Created new Odoo database {dbname}.".format(**locals()), fg="green" diff --git a/click_odoo_contrib/update.py b/click_odoo_contrib/update.py index c31bdaf..31b1ebb 100644 --- a/click_odoo_contrib/update.py +++ b/click_odoo_contrib/update.py @@ -227,11 +227,7 @@ def _update_db_nolock( return if i18n_overwrite: odoo.tools.config["overwrite_existing_translations"] = True - if odoo.tools.parse_version(odoo.release.version) < odoo.tools.parse_version("10"): - Registry = odoo.modules.registry.RegistryManager - else: - Registry = odoo.modules.registry.Registry - Registry.new(database, update_module=True) + odoo.modules.registry.Registry.new(database, update_module=True) if watcher and watcher.aborted: # If you get here, the updating session has been terminated and it # somehow has recovered by opening a new cursor and continuing; diff --git a/tests/test_manifest.py b/tests/test_manifest.py index 3adf958..2d1ba44 100644 --- a/tests/test_manifest.py +++ b/tests/test_manifest.py @@ -32,7 +32,7 @@ def test_manifest_expand_dependencies(): assert "base_import" in res assert "base" in res # obviously assert "web" in res # base_import depends on web - if odoo.tools.parse_version(odoo.release.version) < odoo.tools.parse_version("12"): + if odoo.release.version_info < (12, 0): assert "auth_crypt" not in res else: assert "iap" not in res # iap is auto_install @@ -42,7 +42,7 @@ def test_manifest_expand_dependencies_auto_install(): res = manifest.expand_dependencies(["auth_signup"], include_auto_install=True) assert "auth_signup" in res assert "base" in res # obviously - if odoo.tools.parse_version(odoo.release.version) < odoo.tools.parse_version("12"): + if odoo.release.version_info < (12, 0): assert "auth_crypt" in res # auth_crypt is autoinstall else: assert "iap" in res # iap is auto_install diff --git a/tests/test_update.py b/tests/test_update.py index d3ea332..34b0f13 100644 --- a/tests/test_update.py +++ b/tests/test_update.py @@ -130,7 +130,7 @@ def test_update(odoodb): assert "base" not in checksums # because ignore_Core_addons=True with pytest.raises(subprocess.CalledProcessError): _update_one(odoodb, "v7") - if odoo.tools.parse_version(odoo.release.version) >= odoo.tools.parse_version("12"): + if odoo.release.version_info >= (12, 0): # Odoo >= 12 does -u in a transaction _check_expected(odoodb, "v6") From bdf53dc89bf502e27ffcc9382b266be8f487d06e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Bidoul?= Date: Tue, 18 Oct 2022 16:42:48 +0200 Subject: [PATCH 2/2] Fix mock import for python 3.10 --- tests/test_initdb.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_initdb.py b/tests/test_initdb.py index 94528c3..d4b7038 100644 --- a/tests/test_initdb.py +++ b/tests/test_initdb.py @@ -6,9 +6,9 @@ import sys import textwrap from datetime import datetime, timedelta +from unittest import mock import click_odoo -import mock import pytest from click.testing import CliRunner