mirror of
https://github.com/arcan1s/ahriman.git
synced 2025-04-24 15:27:17 +00:00
complete testkit
also add argument parsers test
This commit is contained in:
parent
839b241ec1
commit
c3cb14f1ed
2
Makefile
2
Makefile
@ -26,7 +26,7 @@ archlinux: archive
|
|||||||
|
|
||||||
check:
|
check:
|
||||||
cd src && mypy --implicit-reexport --strict -p "$(PROJECT)"
|
cd src && mypy --implicit-reexport --strict -p "$(PROJECT)"
|
||||||
find "src/$(PROJECT)" tests -name "*.py" -execdir autopep8 --max-line-length 120 -aa -i {} +
|
find "src/$(PROJECT)" tests -name "*.py" -execdir autopep8 --exit-code --max-line-length 120 -aa -i {} +
|
||||||
cd src && pylint --rcfile=../.pylintrc "$(PROJECT)"
|
cd src && pylint --rcfile=../.pylintrc "$(PROJECT)"
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
|
@ -24,13 +24,19 @@ import ahriman.application.handlers as handlers
|
|||||||
import ahriman.version as version
|
import ahriman.version as version
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
# pylint: disable=too-many-statements
|
||||||
|
def _parser() -> argparse.ArgumentParser:
|
||||||
|
"""
|
||||||
|
command line parser generator
|
||||||
|
:return: command line parser for the application
|
||||||
|
"""
|
||||||
parser = argparse.ArgumentParser(prog="ahriman", description="ArcHlinux ReposItory MANager")
|
parser = argparse.ArgumentParser(prog="ahriman", description="ArcHlinux ReposItory MANager")
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"-a",
|
"-a",
|
||||||
"--architecture",
|
"--architecture",
|
||||||
help="target architectures (can be used multiple times)",
|
help="target architectures (can be used multiple times)",
|
||||||
action="append")
|
action="append",
|
||||||
|
required=True)
|
||||||
parser.add_argument("-c", "--config", help="configuration path", default="/etc/ahriman.ini")
|
parser.add_argument("-c", "--config", help="configuration path", default="/etc/ahriman.ini")
|
||||||
parser.add_argument("--force", help="force run, remove file lock", action="store_true")
|
parser.add_argument("--force", help="force run, remove file lock", action="store_true")
|
||||||
parser.add_argument("--lock", help="lock file", default="/tmp/ahriman.lock")
|
parser.add_argument("--lock", help="lock file", default="/tmp/ahriman.lock")
|
||||||
@ -38,7 +44,7 @@ if __name__ == "__main__":
|
|||||||
parser.add_argument("--no-report", help="force disable reporting to web service", action="store_true")
|
parser.add_argument("--no-report", help="force disable reporting to web service", action="store_true")
|
||||||
parser.add_argument("--unsafe", help="allow to run ahriman as non-ahriman user", action="store_true")
|
parser.add_argument("--unsafe", help="allow to run ahriman as non-ahriman user", action="store_true")
|
||||||
parser.add_argument("-v", "--version", action="version", version=version.__version__)
|
parser.add_argument("-v", "--version", action="version", version=version.__version__)
|
||||||
subparsers = parser.add_subparsers(title="command")
|
subparsers = parser.add_subparsers(title="command", help="command to run", dest="command", required=True)
|
||||||
|
|
||||||
add_parser = subparsers.add_parser("add", description="add package")
|
add_parser = subparsers.add_parser("add", description="add package")
|
||||||
add_parser.add_argument("package", help="package base/name or archive path", nargs="+")
|
add_parser.add_argument("package", help="package base/name or archive path", nargs="+")
|
||||||
@ -96,10 +102,12 @@ if __name__ == "__main__":
|
|||||||
web_parser = subparsers.add_parser("web", description="start web server")
|
web_parser = subparsers.add_parser("web", description="start web server")
|
||||||
web_parser.set_defaults(handler=handlers.Web, lock=None, no_report=True)
|
web_parser.set_defaults(handler=handlers.Web, lock=None, no_report=True)
|
||||||
|
|
||||||
args = parser.parse_args()
|
return parser
|
||||||
if "handler" not in args:
|
|
||||||
parser.print_help()
|
|
||||||
sys.exit(1)
|
if __name__ == "__main__":
|
||||||
|
arg_parser = _parser()
|
||||||
|
args = arg_parser.parse_args()
|
||||||
|
|
||||||
handler: handlers.Handler = args.handler
|
handler: handlers.Handler = args.handler
|
||||||
status = handler.execute(args)
|
status = handler.execute(args)
|
||||||
|
@ -38,7 +38,7 @@ class Client:
|
|||||||
:param status: current package build status
|
:param status: current package build status
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# pylint: disable=R0201
|
# pylint: disable=no-self-use
|
||||||
def get(self, base: Optional[str]) -> List[Tuple[Package, BuildStatus]]:
|
def get(self, base: Optional[str]) -> List[Tuple[Package, BuildStatus]]:
|
||||||
"""
|
"""
|
||||||
get package status
|
get package status
|
||||||
@ -48,7 +48,7 @@ class Client:
|
|||||||
del base
|
del base
|
||||||
return []
|
return []
|
||||||
|
|
||||||
# pylint: disable=R0201
|
# pylint: disable=no-self-use
|
||||||
def get_self(self) -> BuildStatus:
|
def get_self(self) -> BuildStatus:
|
||||||
"""
|
"""
|
||||||
get ahriman status itself
|
get ahriman status itself
|
||||||
|
@ -3,6 +3,7 @@ import pytest
|
|||||||
|
|
||||||
from pytest_mock import MockerFixture
|
from pytest_mock import MockerFixture
|
||||||
|
|
||||||
|
from ahriman.application.ahriman import _parser
|
||||||
from ahriman.application.application import Application
|
from ahriman.application.application import Application
|
||||||
from ahriman.application.lock import Lock
|
from ahriman.application.lock import Lock
|
||||||
from ahriman.core.configuration import Configuration
|
from ahriman.core.configuration import Configuration
|
||||||
@ -22,3 +23,8 @@ def args() -> argparse.Namespace:
|
|||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def lock(args: argparse.Namespace, configuration: Configuration) -> Lock:
|
def lock(args: argparse.Namespace, configuration: Configuration) -> Lock:
|
||||||
return Lock(args, "x86_64", configuration)
|
return Lock(args, "x86_64", configuration)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def parser() -> argparse.ArgumentParser:
|
||||||
|
return _parser()
|
||||||
|
@ -0,0 +1,55 @@
|
|||||||
|
import argparse
|
||||||
|
|
||||||
|
|
||||||
|
def test_parser(parser: argparse.ArgumentParser) -> None:
|
||||||
|
"""
|
||||||
|
must parse valid command line
|
||||||
|
"""
|
||||||
|
parser.parse_args(["-a", "x86_64", "config"])
|
||||||
|
|
||||||
|
|
||||||
|
def test_multiple_architectures(parser: argparse.ArgumentParser) -> None:
|
||||||
|
"""
|
||||||
|
must accept multiple architectures
|
||||||
|
"""
|
||||||
|
args = parser.parse_args(["-a", "x86_64", "-a", "i686", "config"])
|
||||||
|
assert len(args.architecture) == 2
|
||||||
|
|
||||||
|
|
||||||
|
def test_subparsers_check(parser: argparse.ArgumentParser) -> None:
|
||||||
|
"""
|
||||||
|
check command must imply no_aur, no_manual and dry_run
|
||||||
|
"""
|
||||||
|
args = parser.parse_args(["-a", "x86_64", "check"])
|
||||||
|
assert not args.no_aur
|
||||||
|
assert args.no_manual
|
||||||
|
assert args.dry_run
|
||||||
|
|
||||||
|
|
||||||
|
def test_subparsers_config(parser: argparse.ArgumentParser) -> None:
|
||||||
|
"""
|
||||||
|
config command must imply lock, no_report and unsafe
|
||||||
|
"""
|
||||||
|
args = parser.parse_args(["-a", "x86_64", "config"])
|
||||||
|
assert args.lock is None
|
||||||
|
assert args.no_report
|
||||||
|
assert args.unsafe
|
||||||
|
|
||||||
|
|
||||||
|
def test_subparsers_status(parser: argparse.ArgumentParser) -> None:
|
||||||
|
"""
|
||||||
|
status command must imply lock, no_report and unsafe
|
||||||
|
"""
|
||||||
|
args = parser.parse_args(["-a", "x86_64", "status"])
|
||||||
|
assert args.lock is None
|
||||||
|
assert args.no_report
|
||||||
|
assert args.unsafe
|
||||||
|
|
||||||
|
|
||||||
|
def test_subparsers_web(parser: argparse.ArgumentParser) -> None:
|
||||||
|
"""
|
||||||
|
web command must imply lock and no_report
|
||||||
|
"""
|
||||||
|
args = parser.parse_args(["-a", "x86_64", "web"])
|
||||||
|
assert args.lock is None
|
||||||
|
assert args.no_report
|
Loading…
Reference in New Issue
Block a user