From 9c252d702a95e5055eea5afd6ece21a2fa24f6dc Mon Sep 17 00:00:00 2001 From: Ivan Ogasawara Date: Fri, 11 Oct 2024 21:32:47 -0400 Subject: [PATCH] fix unit tests --- src/sugar/extensions/base.py | 3 ++ tests/test_containers_sugar.py | 55 ++++++++++++---------------------- 2 files changed, 22 insertions(+), 36 deletions(-) diff --git a/src/sugar/extensions/base.py b/src/sugar/extensions/base.py index e0a79bd..4d2ce26 100644 --- a/src/sugar/extensions/base.py +++ b/src/sugar/extensions/base.py @@ -39,12 +39,14 @@ class SugarBase: backend_app: sh.Command = sh.echo backend_args: list[str] = [] defaults: dict[str, Any] = {} + dry_run: bool = False env: dict[str, str] = {} options_args: list[str] = [] cmd_args: list[str] = [] service_group: dict[str, Any] = {} service_names: list[str] = [] group_selected: str = '' + verbose: bool = False def __init_subclass__(cls, **kwargs: Any) -> None: """Initialize the actions list for all the created commands.""" @@ -62,6 +64,7 @@ def __init__(self) -> None: """Initialize SugarBase instance.""" self.file = '.sugar.yaml' self.verbose = False + self.dry_run = False self.args: dict[str, str] = {} self.options_args: list[str] = [] self.cmd_args: list[str] = [] diff --git a/tests/test_containers_sugar.py b/tests/test_containers_sugar.py index 200346b..5dbd7a9 100644 --- a/tests/test_containers_sugar.py +++ b/tests/test_containers_sugar.py @@ -2,7 +2,6 @@ from __future__ import annotations -from copy import deepcopy from pathlib import Path from typing import Any @@ -12,51 +11,35 @@ from sugar.extensions.base import SugarBase CONFIG_PATH = Path(__file__).parent.parent / '.sugar.yaml' -DEFAULT_ARGS = { - 'backend': 'docker compose', - 'action': '', - 'config_file': '', - 'service_group': '', - 'service': '', - 'services': None, - 'all': False, - 'version': False, - 'verbose': False, - 'help': False, - 'plugin': 'main', + +SUGAR_ARGS = { + 'file': str(CONFIG_PATH.absolute()), + 'group': 'group1', + 'verbose': True, } COMPOSE = extensions['compose']() COMPOSE_EXT = extensions['compose-ext']() STATS = extensions['stats']() +COMPOSE.load(**SUGAR_ARGS) # type: ignore +COMPOSE_EXT.load(**SUGAR_ARGS) # type: ignore +STATS.load(**SUGAR_ARGS) # type: ignore + @pytest.mark.parametrize( - 'args,ext,action', + 'ext,action,args', [ - COMPOSE, - 'version', - {'version': True}, - COMPOSE, - 'config', - {'service_group': 'group1'}, - COMPOSE_EXT, - 'version', - {'version': True}, - COMPOSE_EXT, - 'config', - {'service_group': 'group1'}, + (COMPOSE, 'version', {}), + (COMPOSE, 'config', {}), + (COMPOSE, 'ls', {}), + (COMPOSE, 'ps', {}), + (COMPOSE_EXT, 'version', {}), + (COMPOSE_EXT, 'config', {}), + (COMPOSE_EXT, 'ls', {}), + (COMPOSE_EXT, 'ps', {}), ], ) def test_success(ext: SugarBase, action: str, args: dict[str, Any]) -> None: """Test success cases.""" - args.update( - { - 'config_file': str(CONFIG_PATH.absolute()), - 'verbose': True, - } - ) - args_obj = deepcopy(DEFAULT_ARGS) - args_obj.update(args) - - getattr(ext, f'_cmd_{action}')(args_obj) + getattr(ext, f'_cmd_{action}')(**args)