From d83bcc784c143aab82ea933b74005abf2aa5bf0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Tue, 10 Sep 2024 18:01:29 +0200 Subject: [PATCH] Add setup methods to activate_modules --- trytond/CHANGELOG | 1 + trytond/doc/ref/tests.rst | 4 +++- trytond/trytond/tests/tools.py | 18 ++++++++++++++++-- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/trytond/CHANGELOG b/trytond/CHANGELOG index a7f1427b18..34b10bfea1 100644 --- a/trytond/CHANGELOG +++ b/trytond/CHANGELOG @@ -1,3 +1,4 @@ +* Add setup methods to activate_modules * Add method to the backend to estimate number of rows * Add setup indexes method to ModelSQL * Support getting many sequences at once diff --git a/trytond/doc/ref/tests.rst b/trytond/doc/ref/tests.rst index 86cbd1ff2e..86286356d4 100644 --- a/trytond/doc/ref/tests.rst +++ b/trytond/doc/ref/tests.rst @@ -184,9 +184,11 @@ doctest helpers Tools ----- -.. function:: activate_modules(modules) +.. function:: activate_modules(modules, \*setup) Activate a list of ``modules`` for scenario based on proteus doctests. + The following arguments are functions sequentially called at the end of the + activation with the proteus configuration as ``config`` keyword argument. .. function:: set_user(user, config) diff --git a/trytond/trytond/tests/tools.py b/trytond/trytond/tests/tools.py index f743e09e4d..aa8eeb0c2c 100644 --- a/trytond/trytond/tests/tools.py +++ b/trytond/trytond/tests/tools.py @@ -2,6 +2,7 @@ # this repository contains the full copyright notices and license terms. import unittest +from functools import partial from proteus import Model, Wizard from proteus import config as pconfig @@ -11,10 +12,20 @@ from .test_tryton import backup_db_cache, drop_create, restore_db_cache __all__ = ['activate_modules', 'set_user'] -def activate_modules(modules): +def _func_name(func): + if isinstance(func, partial): + return f'{func.func.__qualname__}(*{func.args}, **{func.keywords})' + else: + assert not hasattr(func, '__self__') + return func.__qualname__ + + +def activate_modules(modules, *setup): if isinstance(modules, str): modules = [modules] - cache_name = '-'.join(modules) + cache_name = '-'.join(sorted(modules)) + if setup_name := '|'.join(_func_name(f) for f in setup): + cache_name += f'--{setup_name}' if restore_db_cache(cache_name): return _get_config() drop_create() @@ -28,6 +39,9 @@ def activate_modules(modules): Module.click(records, 'activate') Wizard('ir.module.activate_upgrade').execute('upgrade') + for func in setup: + func(config=cfg) + backup_db_cache(cache_name) return cfg