Skip to content

Commit

Permalink
fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
xmnlab committed Oct 12, 2024
1 parent 862245d commit 9c252d7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 36 deletions.
3 changes: 3 additions & 0 deletions src/sugar/extensions/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand All @@ -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] = []
Expand Down
55 changes: 19 additions & 36 deletions tests/test_containers_sugar.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

from __future__ import annotations

from copy import deepcopy
from pathlib import Path
from typing import Any

Expand All @@ -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)

0 comments on commit 9c252d7

Please sign in to comment.