Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Standard Library #2

Draft
wants to merge 119 commits into
base: development
Choose a base branch
from
Draft
Changes from 1 commit
Commits
Show all changes
119 commits
Select commit Hold shift + click to select a range
763fe90
Add Python requirements file
dl1998 Sep 1, 2023
cbc1b9d
Add Sphinx configuration
dl1998 Sep 1, 2023
a5a408d
Add sources folder
dl1998 Sep 1, 2023
9c95e77
Add tests folder
dl1998 Sep 1, 2023
d414600
Update commit variable in Branch class
dl1998 Sep 1, 2023
eae6104
Add PyLinter
dl1998 Sep 1, 2023
e5643f5
Add setup.py
dl1998 Sep 1, 2023
fcd669d
Add changelog file
dl1998 Sep 1, 2023
51f58fc
Update README.md
dl1998 Sep 30, 2023
90f8b96
Update PyLinter configuration
dl1998 Sep 30, 2023
979e886
Update base class for GitCommand
dl1998 Sep 30, 2023
c20c703
Update PullCommandDefinitions class to be compliant with the base class
dl1998 Sep 30, 2023
4ceb98e
Add a new class with definition of the 'git add' command
dl1998 Sep 30, 2023
8dc2a58
Add a new class with definition of the 'git clone' command
dl1998 Sep 30, 2023
abf26f1
Add a new class with definition of the 'git for-each-ref' command
dl1998 Sep 30, 2023
f274075
Add a new class with definition of the 'git init' command
dl1998 Sep 30, 2023
f2d8ca7
Add a new class with definition of the 'git log' command
dl1998 Sep 30, 2023
8a15aa7
Add a new class with definition of the 'git mv' command
dl1998 Sep 30, 2023
c8494fe
Add a new class with definition of the 'git push' command
dl1998 Sep 30, 2023
cf11c51
Add a new class with definition of the 'git rm' command
dl1998 Sep 30, 2023
47a54e4
Add a new class with definition of the 'git show' command
dl1998 Sep 30, 2023
8c4bb52
Add .DS_Store file to the .gitignore
dl1998 Sep 30, 2023
e76275c
Add a new class for manipulations with the paths
dl1998 Sep 30, 2023
c43811e
Uncomment .idea exclude
dl1998 Sep 30, 2023
465a6af
Add submodule for git object models
dl1998 Sep 30, 2023
b177b3c
Add common model classes
dl1998 Sep 30, 2023
c3532e6
Add models for the git branches
dl1998 Sep 30, 2023
34726c6
Add models for the git commits
dl1998 Sep 30, 2023
a751e62
Add models for the git remotes
dl1998 Sep 30, 2023
4e8a93c
Add model for the git repository paths
dl1998 Sep 30, 2023
b91cf4f
Add models for the git tags
dl1998 Sep 30, 2023
78c439a
Add submodule for git objects parsers
dl1998 Sep 30, 2023
ceba40c
Add a new parser for the git branches
dl1998 Sep 30, 2023
5d554f3
Add a new parser for the git commits
dl1998 Sep 30, 2023
bd86163
Add a new parser for the git commits
dl1998 Sep 30, 2023
7d436ee
Extend git command runner functionality
dl1998 Sep 30, 2023
3c312ac
Update main classes to work with recent changes
dl1998 Sep 30, 2023
96dc1c6
Refactor documentation modules
dl1998 Sep 30, 2023
420ed63
Add docs/build to .gitignore list
dl1998 Sep 30, 2023
3675492
Change typing for commit parent on Optional[Commit]
dl1998 Sep 30, 2023
475675d
Update docstring for create_from_value method
dl1998 Sep 30, 2023
f9d9366
Update python requirements list
dl1998 Sep 30, 2023
7229237
Update setup.py configuration
dl1998 Sep 30, 2023
5e202f3
Add GitHub configuration files
dl1998 Sep 30, 2023
d9a0be6
Update repository name
dl1998 Sep 30, 2023
52a6849
Fix issues in add and rm commands
dl1998 Sep 30, 2023
5d8abe2
Minor code cleanup
dl1998 Sep 30, 2023
afb0009
Change LICENSE file extension
dl1998 Sep 30, 2023
c78bf1f
Add tests for git init, git clone, and git mv commands
dl1998 Oct 1, 2023
82805e6
Update PathsMapping to set default root path
dl1998 Oct 1, 2023
a90be71
Extend GitConfig functionality
dl1998 Oct 1, 2023
ebd84db
Add a new class with definition of the 'git config' command
dl1998 Oct 1, 2023
497e5d1
Update GitRepository class to use ConfigCommandDefinitions
dl1998 Oct 1, 2023
34002ef
Add method for saving changes in the GitIgnore
dl1998 Oct 1, 2023
da38dbc
Add docstrings to GitConfig class
dl1998 Oct 1, 2023
e488d16
Resolve minor pylint warnings
dl1998 Oct 1, 2023
e212c43
Add docstrings to GitIgnore class
dl1998 Oct 1, 2023
2f20618
Add classes to handle option name aliases
dl1998 Oct 1, 2023
1e46ffb
Extend git options definitions to use option name aliases
dl1998 Oct 1, 2023
3f5a95e
Add docstrings and typing to FilesChangesHandler
dl1998 Oct 1, 2023
d142a5d
Remove old redundant constants that has been moved to TagsParser
dl1998 Oct 1, 2023
266ff5b
Update typing for the raw_tags in the docstring
dl1998 Oct 1, 2023
0b612c0
Add exceptions for the git commands: show, config, and checkout
dl1998 Oct 1, 2023
02d6f7d
Fix docstrings
dl1998 Oct 1, 2023
3f60786
Add a new class with definition of the 'git checkout' command
dl1998 Oct 1, 2023
8a19a7f
Remove autogenerated .rst files
dl1998 Oct 1, 2023
20f8a0f
Add an exception class for 'git for-each-ref' command
dl1998 Oct 1, 2023
ecf76a5
Add an exception class for 'git log' command
dl1998 Oct 1, 2023
fd4f29a
Add command wrappers for basic operations
dl1998 Oct 1, 2023
c8f18af
Add command wrapper for 'git log'
dl1998 Oct 1, 2023
ffd898a
Refactor GitRepository standard methods to use new command wrappers
dl1998 Oct 1, 2023
3b4401b
Remove unused import
dl1998 Oct 1, 2023
ede17ba
Update commits parser to use log command wrapper
dl1998 Oct 1, 2023
6b8ac40
Update tags parser to use for-each-ref command wrapper
dl1998 Oct 1, 2023
2c88801
Extend checkout functionality to create a new branch
dl1998 Oct 1, 2023
3302965
Extend git command to support 'commit' command
dl1998 Oct 3, 2023
6ebc8ea
Improve module reference readability
dl1998 Oct 3, 2023
df7e2e5
Update commit method used in tests
dl1998 Oct 4, 2023
c892a45
Add docstrings and typing to CheckoutHandler
dl1998 Oct 4, 2023
90dc880
Move PathsMapping to path utils
dl1998 Oct 4, 2023
de35d09
Add docstrings and typing to PathsMapping
dl1998 Oct 4, 2023
fffd323
Add docstrings and typing to GitRepository
dl1998 Oct 4, 2023
542ecd2
Add method and class for commit handling
dl1998 Oct 7, 2023
e6a376c
Cleanup and simplify models
dl1998 Oct 7, 2023
d060873
Add pytest dependency
dl1998 Oct 7, 2023
ffb7db3
Add testing utilities for options
dl1998 Oct 28, 2023
767f02d
Add tests for options base clases
dl1998 Oct 28, 2023
4c4d767
Add tests for 'git add' options
dl1998 Oct 28, 2023
4eac11c
Add tests for 'git commit' options
dl1998 Oct 28, 2023
8e79903
Add tests for 'git clone' options
dl1998 Oct 28, 2023
35e92e1
Add tests for 'git commit' options
dl1998 Oct 28, 2023
ca7ec64
Add tests for 'git config' options
dl1998 Oct 28, 2023
2e53f3a
Add tests for 'git for-each-ref' options
dl1998 Oct 28, 2023
c4add5f
Add tests for 'git init' options
dl1998 Oct 28, 2023
6cdd458
Add tests for 'git log' options
dl1998 Oct 28, 2023
da3d588
Add tests for 'git mv' options
dl1998 Oct 28, 2023
a0932e9
Add tests for 'git pull' options
dl1998 Oct 28, 2023
f98454d
Add tests for 'git push' options
dl1998 Oct 28, 2023
09d7b88
Add tests for 'git rm' options
dl1998 Oct 28, 2023
7ff1193
Add tests for 'git show' options
dl1998 Oct 28, 2023
316b850
Add tests documentation for 'git add' options
dl1998 Oct 28, 2023
abad548
Add tests documentation for 'git checkout' options
dl1998 Oct 28, 2023
a85132e
Add tests documentation for 'git clone' options
dl1998 Oct 28, 2023
216870f
Add tests documentation for 'git commit' options
dl1998 Oct 28, 2023
b20bdb4
Add tests documentation for 'git config' options
dl1998 Oct 28, 2023
3e542de
Add tests documentation for 'git for-each-ref' options
dl1998 Oct 28, 2023
afb1220
Add tests documentation for 'git init' options
dl1998 Oct 28, 2023
7f8d14a
Add tests documentation for 'git mv' options
dl1998 Oct 28, 2023
75828fb
Add tests documentation for 'git pull' options
dl1998 Oct 28, 2023
1ab87ba
Add tests documentation for 'git push' options
dl1998 Oct 28, 2023
3db7aec
Add tests documentation for 'git rm' options
dl1998 Oct 28, 2023
00bf5d2
Add tests documentation for 'git show' options
dl1998 Oct 28, 2023
47316fe
Add tests documentation for options utils class
dl1998 Oct 28, 2023
cf40b52
Add tests documentation for the tests for options module
dl1998 Dec 26, 2023
49eb2f4
Update docstring commit for validate_positional_list
dl1998 Dec 26, 2023
009be44
Add GitCommand generator and tests for validate_positional_list method
dl1998 Dec 26, 2023
b81ee63
Add test for validate_required method from GitCommand and update impl…
dl1998 Dec 27, 2023
69c63c8
Add test for validate_choices method from GitCommand and update imple…
dl1998 Dec 27, 2023
932c2b6
Add tests for CommandOptions class
dl1998 Dec 28, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add tests for options base clases
dl1998 committed Oct 28, 2023
commit 767f02df98583815e8e8efa899e0edfa822e2f27
171 changes: 171 additions & 0 deletions tests/unit_tests/pygit/options/test_options.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
from typing import Any, Type

import pytest

from sources.exceptions import GitException, GitMissingDefinitionException, GitIncorrectOptionValueException, \
GitMissingRequiredOptionsException
from sources.options.options import GitOptionNameAliases, GitOptionNameAlias, GitOptionDefinition, GitOption, \
GitCommand, CommandOptions


class DemoCommand(GitCommand):
class Options(CommandOptions):
OPTION = GitOptionNameAliases(aliases=[
GitOptionNameAlias(name='option', short_option=False),
GitOptionNameAlias(name='o', short_option=True),
])
LONG_OPTION = GitOptionNameAliases(aliases=[
GitOptionNameAlias(name='long-option', short_option=False),
])
SHORT_OPTION = GitOptionNameAliases(aliases=[
GitOptionNameAlias(name='s', short_option=True)
])
POSITIONAL_OPTION = GitOptionNameAliases(aliases=[
GitOptionNameAlias(name='positional', short_option=True)
])

def __init__(self):
super().__init__('command')
self.definitions = [
GitOptionDefinition(name_aliases=self.Options.OPTION, type=(str, bool)),
GitOptionDefinition(name_aliases=self.Options.LONG_OPTION, type=str, choices=['first', 'second']),
GitOptionDefinition(name_aliases=self.Options.SHORT_OPTION, type=bool),
GitOptionDefinition(name_aliases=self.Options.POSITIONAL_OPTION, type=str, positional=True, position=0,
required=True),
]


class TestGitOptionNameAliases:
@pytest.mark.parametrize('name,short_option,length', [('option', False, 1), ('o', True, 1)],
ids=('Get long alias', 'Get short alias'))
def test_get_aliases_positive(self, name: str, short_option: bool, length: int):
alias = GitOptionNameAlias(name=name, short_option=short_option)
option_aliases = GitOptionNameAliases(aliases=[
alias,
])
aliases = option_aliases.get_aliases(short_option=short_option)
assert len(aliases) == length
assert aliases[0] == alias

# noinspection PyTypeChecker
def test_get_aliases_negative(self):
alias = 'option'
try:
option_aliases = GitOptionNameAliases(aliases=[
alias,
])
option_aliases.get_aliases(short_option=False)
test_result = False
except AttributeError:
test_result = True
assert test_result

@pytest.mark.parametrize('name,short_option', [('option', False), ('o', True)],
ids=("Without short options", 'With short options'))
def test_has_short_aliases_positive(self, name: str, short_option: bool):
alias = GitOptionNameAlias(name=name, short_option=short_option)
option_aliases = GitOptionNameAliases(aliases=[
alias,
])
has_short_aliases = option_aliases.has_short_aliases()
assert has_short_aliases == short_option

@pytest.mark.parametrize('name,short_option', [('option', False), ('o', True)],
ids=("Without short options", 'With short options'))
def test_has_long_aliases_positive(self, name: str, short_option: bool):
alias = GitOptionNameAlias(name=name, short_option=short_option)
option_aliases = GitOptionNameAliases(aliases=[
alias,
])
has_long_aliases = option_aliases.has_long_aliases()
assert has_long_aliases != short_option

@pytest.mark.parametrize('name,exists', [('option', True), ('o', True), ('another_option', False)],
ids=("Long option exists", 'Short option exists', 'Missing option'))
def test_exists_positive(self, name: str, exists: bool):
option_aliases = GitOptionNameAliases(aliases=[
GitOptionNameAlias(name='option', short_option=False),
GitOptionNameAlias(name='o', short_option=True),
])
option_exists = option_aliases.exists(name)
assert option_exists == exists

def test_get_names_positive(self):
option_aliases = GitOptionNameAliases(aliases=[
GitOptionNameAlias(name='option', short_option=False),
GitOptionNameAlias(name='o', short_option=True),
])
names = option_aliases.get_names()
assert names == ['option', 'o']

class TestGitOptionDefinition:
@pytest.mark.parametrize('name,value,expected', [
('option', True, True), ('option', 'value', True), ('o', True, True), ('o', 123, False),
('another_option', 'value', False)
], ids=('Correct long boolean option', 'Correct long string option', 'Correct short boolean option',
'Incorrect short integer option', 'Incorrect another string option'))
def test_compare_with_option_positive(self, name: str, value: Any, expected: bool):
name_aliases = GitOptionNameAliases(aliases=[
GitOptionNameAlias(name='option', short_option=False),
GitOptionNameAlias(name='o', short_option=True),
])
definition = GitOptionDefinition(name_aliases=name_aliases, type=(str, bool))
option = GitOption(name=name, value=value)
comparison_result = definition.compare_with_option(option)
assert comparison_result == expected

class TestGitCommand:
@pytest.mark.parametrize('name,value,expected', [
('option', True, True), ('option', 'value', True), ('o', True, True), ('o', 123, False),
('another_option', 'value', False)
], ids=("Definition exists for long boolean option", "Definition exists for long string option",
"Definition exists for short boolean option", "Definition doesn't exist for short integer option",
"Definition doesn't exist for another string option"))
def test_get_definition_positive(self, name: str, value: Any, expected: bool):
option = GitOption(name=name, value=value)
command = DemoCommand()
definition = command.get_definition(option)
if expected:
assert definition is not None
else:
assert definition is None

def test_validate_positive(self):
options = [
DemoCommand.Options.SHORT_OPTION.create_option(True),
DemoCommand.Options.LONG_OPTION.create_option('first'),
DemoCommand.Options.POSITIONAL_OPTION.create_option('value'),
]
command = DemoCommand()
fired = False
try:
command.validate(options)
except GitException:
fired = True
assert not fired

@pytest.mark.parametrize('name,value,expected_exception', [
('missing_option', True, GitMissingDefinitionException),
('long-option', 'third', GitIncorrectOptionValueException),
('option', True, GitMissingRequiredOptionsException),
], ids=("Missing option exception", "Incorrect option value exception", "Missing required option exception"))
def test_validate_negative(self, name: str, value: Any, expected_exception: Type[GitException]):
option = GitOption(name=name, value=value)
command = DemoCommand()
fired = False
try:
command.validate(option)
except expected_exception:
fired = True
assert fired

def test_transform_to_command_positive(self):
options = [
DemoCommand.Options.SHORT_OPTION.create_option(True),
DemoCommand.Options.LONG_OPTION.create_option('first'),
DemoCommand.Options.POSITIONAL_OPTION.create_option('value'),
]
command = DemoCommand()
expected_output = ['command', '-s', '--long-option', 'first', 'value']
transformed_command = command.transform_to_command(options)
assert transformed_command == expected_output