mirror of
https://github.com/pre-commit/pre-commit-hooks.git
synced 2026-04-05 11:36:54 +00:00
tests for mismatched args
This commit is contained in:
parent
dbe3cd46d7
commit
238d3da42e
6 changed files with 28 additions and 0 deletions
|
|
@ -11,6 +11,7 @@ class BranchNameChecker(CheckerTemplateMethod):
|
|||
self.parser.add_argument('-r', '--regex', help='Regex that git current branch must match.')
|
||||
|
||||
def _perform_checks(self):
|
||||
super(BranchNameChecker, self)._add_arguments_to_parser()
|
||||
regular_expression = self.args.regex
|
||||
pattern = re.compile(regular_expression)
|
||||
current_branch_name = get_current_branch_name()
|
||||
|
|
|
|||
|
|
@ -39,3 +39,24 @@ def test_locations_error1():
|
|||
|
||||
def test_locations_error2():
|
||||
perform_test_on_file_expecting_result('check_location_samples/not_enabled_directory/incorrect_xml.xml', main, expected_result=2)
|
||||
|
||||
|
||||
def test_locations_arguments_size_mismatch_error():
|
||||
sys.argv = []
|
||||
|
||||
sys.argv.append('--directories')
|
||||
sys.argv.append(r'.*\/xml')
|
||||
# Lacking files for this directory
|
||||
sys.argv.append('--directories')
|
||||
sys.argv.append(r'.*\/javascript')
|
||||
|
||||
sys.argv.append('--files')
|
||||
sys.argv.append(r'correct_xml.xml')
|
||||
|
||||
perform_test_on_file_expecting_result('check_location_samples/xml/correct_xml.xml', main, expected_result=2)
|
||||
|
||||
|
||||
def test_locations_no_arguments_error():
|
||||
with pytest.raises(TypeError) as error:
|
||||
perform_test_on_file_expecting_result('check_location_samples/xml/correct_xml.xml', main)
|
||||
assert "'NoneType' object is not iterable" in str(error.value)
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ class BranchNameChecker(CheckerTemplateMethod):
|
|||
self.parser.add_argument('-r', '--regex', help='Regex that git current branch must match.')
|
||||
|
||||
def _perform_checks(self):
|
||||
super(BranchNameChecker, self)._perform_checks()
|
||||
regular_expression = self.args.regex
|
||||
pattern = re.compile(regular_expression)
|
||||
current_branch_name = get_current_branch_name()
|
||||
|
|
|
|||
|
|
@ -4,11 +4,13 @@ import re
|
|||
from pre_commit_hooks.loaderon_hooks.util.git_helpers import get_current_branch_name
|
||||
from pre_commit_hooks.loaderon_hooks.util.template_methods.checker_template_method import CheckerTemplateMethod
|
||||
|
||||
|
||||
class BranchNameChecker(CheckerTemplateMethod):
|
||||
def _add_arguments_to_parser(self):
|
||||
self.parser.add_argument('-r', '--regex', help='Regex that git current branch must match.')
|
||||
|
||||
def _perform_checks(self):
|
||||
super(BranchNameChecker, self)._perform_checks()
|
||||
regular_expression = self.args.regex
|
||||
pattern = re.compile(regular_expression)
|
||||
current_branch_name = get_current_branch_name()
|
||||
|
|
|
|||
|
|
@ -4,11 +4,13 @@ import re
|
|||
from pre_commit_hooks.loaderon_hooks.util.git_helpers import get_current_branch_name
|
||||
from pre_commit_hooks.loaderon_hooks.util.template_methods.checker_template_method import CheckerTemplateMethod
|
||||
|
||||
|
||||
class BranchNameChecker(CheckerTemplateMethod):
|
||||
def _add_arguments_to_parser(self):
|
||||
self.parser.add_argument('-r', '--regex', help='Regex that git current branch must match.')
|
||||
|
||||
def _perform_checks(self):
|
||||
super(BranchNameChecker, self)._perform_checks()
|
||||
regular_expression = self.args.regex
|
||||
pattern = re.compile(regular_expression)
|
||||
current_branch_name = get_current_branch_name()
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ class FileCheckerTemplateMethod(CheckerTemplateMethod):
|
|||
self.parser.add_argument('filenames', nargs='*')
|
||||
|
||||
def _perform_checks(self):
|
||||
super(FileCheckerTemplateMethod, self)._perform_checks()
|
||||
"""For each file, check it's location."""
|
||||
for self.filename in self.args.filenames:
|
||||
self._check_file()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue