Verified Commit 403d18ee authored by David Runge's avatar David Runge
Browse files

argparse: Add parser for arch-release-sync

arch_release_promotion/argparse.py:
Add `ArgParseFactory.synchronize()` classmethod to add a simple
entrypoint for `arch-release-sync`, that supports the `-p`/`--project`
optional parameters and display of version information.

tests/test_argparse.py:
Add tests for `ArgParseFactory.synchronize()`.
parent fb651a75
......@@ -67,6 +67,37 @@ class ArgParseFactory:
return instance.parser
@classmethod
def synchronize(self) -> argparse.ArgumentParser:
"""A class method to create an ArgumentParser for synchronization
Returns
-------
argparse.ArgumentParser
An ArgumentParser instance specific for synchronization
"""
instance = self(
prog="arch-release-sync",
description="Synchronize promoted releases of a project with a local directory",
)
instance.parser.add_argument(
"-p",
"--project",
type=self.non_zero_string,
help=(
"the project to synchronize from a remote (e.g. 'group/project'). "
f"By default {instance.parser.prog} attempts to synchronize releases for "
"all projects specified in its config"
),
)
if instance.parser.parse_args().version:
print(f"{instance.parser.prog} {metadata.version('arch_release_promotion')}")
exit(0)
return instance.parser
@classmethod
def non_zero_string(self, input_: str) -> str:
"""Validate a string to be of non_zero length
......
......@@ -24,6 +24,18 @@ def test_argparse_promote(metadata_mock: Mock, exit_mock: Mock, parse_args_mock:
assert isinstance(argparse.ArgParseFactory.promote(), ArgumentParser)
@patch("argparse.ArgumentParser.parse_args")
@patch("arch_release_promotion.argparse.exit")
@patch("arch_release_promotion.argparse.metadata")
def test_argparse_synchronize(metadata_mock: Mock, exit_mock: Mock, parse_args_mock: Mock) -> None:
assert isinstance(argparse.ArgParseFactory.synchronize(), ArgumentParser)
assert call.version("arch_release_promotion") in metadata_mock.mock_calls
exit_mock.assert_called_once()
parse_args_mock.return_value = Mock(version=False)
assert isinstance(argparse.ArgParseFactory.synchronize(), ArgumentParser)
@mark.parametrize(
"input_string, expectation",
[
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment