mirror of
				https://github.com/arcan1s/ahriman.git
				synced 2025-11-04 07:43:42 +00:00 
			
		
		
		
	mimic parent arguments during spawn process (#99)
This commit is contained in:
		@ -6,6 +6,7 @@ from pytest_mock import MockerFixture
 | 
			
		||||
from ahriman.application.handlers import Web
 | 
			
		||||
from ahriman.core.configuration import Configuration
 | 
			
		||||
from ahriman.core.repository import Repository
 | 
			
		||||
from ahriman.models.log_handler import LogHandler
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def _default_args(args: argparse.Namespace) -> argparse.Namespace:
 | 
			
		||||
@ -19,6 +20,11 @@ def _default_args(args: argparse.Namespace) -> argparse.Namespace:
 | 
			
		||||
        argparse.Namespace: generated arguments for these test cases
 | 
			
		||||
    """
 | 
			
		||||
    args.parser = lambda: True
 | 
			
		||||
    args.force = False
 | 
			
		||||
    args.log_handler = None
 | 
			
		||||
    args.report = True
 | 
			
		||||
    args.quiet = False
 | 
			
		||||
    args.unsafe = False
 | 
			
		||||
    return args
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -43,6 +49,63 @@ def test_run(args: argparse.Namespace, configuration: Configuration, repository:
 | 
			
		||||
    join_mock.assert_called_once_with()
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def test_extract_arguments(args: argparse.Namespace, configuration: Configuration):
 | 
			
		||||
    """
 | 
			
		||||
    must extract correct args
 | 
			
		||||
    """
 | 
			
		||||
    expected = [
 | 
			
		||||
        "--architecture", "x86_64",
 | 
			
		||||
        "--configuration", str(configuration.path),
 | 
			
		||||
    ]
 | 
			
		||||
 | 
			
		||||
    probe = _default_args(args)
 | 
			
		||||
    assert list(Web.extract_arguments(probe, "x86_64", configuration)) == expected
 | 
			
		||||
 | 
			
		||||
    probe.force = True
 | 
			
		||||
    expected.extend(["--force"])
 | 
			
		||||
    assert list(Web.extract_arguments(probe, "x86_64", configuration)) == expected
 | 
			
		||||
 | 
			
		||||
    probe.log_handler = LogHandler.Console
 | 
			
		||||
    expected.extend(["--log-handler", probe.log_handler.value])
 | 
			
		||||
    assert list(Web.extract_arguments(probe, "x86_64", configuration)) == expected
 | 
			
		||||
 | 
			
		||||
    probe.quiet = True
 | 
			
		||||
    expected.extend(["--quiet"])
 | 
			
		||||
    assert list(Web.extract_arguments(probe, "x86_64", configuration)) == expected
 | 
			
		||||
 | 
			
		||||
    probe.unsafe = True
 | 
			
		||||
    expected.extend(["--unsafe"])
 | 
			
		||||
    assert list(Web.extract_arguments(probe, "x86_64", configuration)) == expected
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def test_extract_arguments_full(parser: argparse.ArgumentParser, configuration: Configuration):
 | 
			
		||||
    """
 | 
			
		||||
    must extract all available args except for blacklisted
 | 
			
		||||
    """
 | 
			
		||||
    # append all options from parser
 | 
			
		||||
    args = argparse.Namespace()
 | 
			
		||||
    for action in parser._actions:
 | 
			
		||||
        if action.default == argparse.SUPPRESS:
 | 
			
		||||
            continue
 | 
			
		||||
        # extract option from the following list
 | 
			
		||||
        value = action.const or \
 | 
			
		||||
            next(iter(action.choices or []), None) or \
 | 
			
		||||
            (not action.default if isinstance(action.default, bool) else None) or \
 | 
			
		||||
            "random string"
 | 
			
		||||
        if action.type is not None:
 | 
			
		||||
            value = action.type(value)
 | 
			
		||||
        setattr(args, action.dest, value)
 | 
			
		||||
 | 
			
		||||
    assert list(Web.extract_arguments(args, "x86_64", configuration)) == [
 | 
			
		||||
        "--architecture", "x86_64",
 | 
			
		||||
        "--configuration", str(configuration.path),
 | 
			
		||||
        "--force",
 | 
			
		||||
        "--log-handler", "console",
 | 
			
		||||
        "--quiet",
 | 
			
		||||
        "--unsafe",
 | 
			
		||||
    ]
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def test_disallow_auto_architecture_run() -> None:
 | 
			
		||||
    """
 | 
			
		||||
    must not allow auto architecture run
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user