Skip to content

Commit

Permalink
Add test for validate_required method from GitCommand and update impl…
Browse files Browse the repository at this point in the history
…ementation
  • Loading branch information
dl1998 committed Dec 27, 2023
1 parent 009be44 commit b81ee63
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 1 deletion.
2 changes: 1 addition & 1 deletion sources/options/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ def validate_required(self, options: Union[GitOption, List[GitOption]]) -> Tuple
missing_definitions = []
for required_definition in required_definitions:
aliases = '|'.join(required_definition.get_names())
missing_definitions.append(f'({aliases})')
missing_definitions.append(f'{aliases}')
return len(required_definitions) == 0, missing_definitions

def validate_choices(self, option: GitOption, definition: Optional[GitOptionDefinition] = None) -> bool:
Expand Down
62 changes: 62 additions & 0 deletions tests/unit_tests/pygit/options/test_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,68 @@ def test_validate_positional_list_positive(self, positional_definitions: List[Tu
})
assert command.validate_positional_list() == expected

@pytest.mark.parametrize("option_definitions,expected", [
(['option', 'long-option', 's'], (True, [])),
(['o', 'long-option', 's'], (True, [])),
(['option', 's'], (False, ['long-option'])),
(['option', 'long-option'], (False, ['s'])),
(['long-option', 's'], (False, ['option|o'])),
(['option'], (False, ['long-option', 's'])),
], ids=("All required options are present (long alias for two aliases option)",
"All required options are present (short alias for two aliases option)",
"Long option is missing", "Short option is missing", "Required option with two aliases is missing",
"Long option and short option are missing"))
def test_validate_required_positive(self, option_definitions: List[str], expected: Tuple[bool, Optional[str]]):
"""
Method tests that 'validate_required' method from 'GitCommand' class returns Tuple[status, missing options],
where missing options is a list of options that are required, but missing.
:param option_definitions: List of options.
:type option_definitions: List[str]
:param expected: The expected value that shall be returned by method.
:type expected: Tuple[bool, Optional[str]]
"""
options = []
for option in option_definitions:
options.append(GitOption(name=option, value='value'))
command = GitCommandGenerator.from_dict({
'command': 'demo-command',
'definitions': [
{
'aliases': [
{
'name': 'option',
'short-option': False
},
{
'name': 'o',
'short-option': True
}
],
'required': True
},
{
'aliases': [
{
'name': 'long-option',
'short-option': False
}
],
'required': True
},
{
'aliases': [
{
'name': 's',
'short-option': True
}
],
'required': True
},
]
})
assert command.validate_required(options) == expected

def test_transform_to_command_positive(self):
"""
Method tests that 'transform_to_command' method from 'GitCommand' class is able to correctly transform
Expand Down

0 comments on commit b81ee63

Please sign in to comment.