tests for mismatched args

This commit is contained in:
Alvaro Andrés Rodríguez Scelza 2019-06-13 15:04:38 -03:00
parent dbe3cd46d7
commit 238d3da42e
6 changed files with 28 additions and 0 deletions

View file

@ -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()

View file

@ -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)

View file

@ -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()

View file

@ -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()

View file

@ -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()

View file

@ -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()