From 238d3da42e0661db26c320ec9e00dab002945e8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alvaro=20Andr=C3=A9s=20Rodr=C3=ADguez=20Scelza?= Date: Thu, 13 Jun 2019 15:04:38 -0300 Subject: [PATCH] tests for mismatched args --- .../general_hooks/check_branch_name.py | 1 + .../general_hooks/check_location_test.py | 21 +++++++++++++++++++ .../check_using_pylint_samples/correct.py | 1 + .../check_using_pylint_samples/incorrect.py | 2 ++ .../incorrect_but_ignored.py | 2 ++ .../file_checker_template_method.py | 1 + 6 files changed, 28 insertions(+) diff --git a/pre_commit_hooks/loaderon_hooks/general_hooks/check_branch_name.py b/pre_commit_hooks/loaderon_hooks/general_hooks/check_branch_name.py index 8227ff7..9f25297 100644 --- a/pre_commit_hooks/loaderon_hooks/general_hooks/check_branch_name.py +++ b/pre_commit_hooks/loaderon_hooks/general_hooks/check_branch_name.py @@ -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() diff --git a/pre_commit_hooks/loaderon_hooks/tests/automatic_testing/general_hooks/check_location_test.py b/pre_commit_hooks/loaderon_hooks/tests/automatic_testing/general_hooks/check_location_test.py index 595e81f..7d0c0fb 100644 --- a/pre_commit_hooks/loaderon_hooks/tests/automatic_testing/general_hooks/check_location_test.py +++ b/pre_commit_hooks/loaderon_hooks/tests/automatic_testing/general_hooks/check_location_test.py @@ -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) diff --git a/pre_commit_hooks/loaderon_hooks/tests/automatic_testing/testing_samples/check_using_pylint_samples/correct.py b/pre_commit_hooks/loaderon_hooks/tests/automatic_testing/testing_samples/check_using_pylint_samples/correct.py index 91eda6e..da95a2f 100644 --- a/pre_commit_hooks/loaderon_hooks/tests/automatic_testing/testing_samples/check_using_pylint_samples/correct.py +++ b/pre_commit_hooks/loaderon_hooks/tests/automatic_testing/testing_samples/check_using_pylint_samples/correct.py @@ -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() diff --git a/pre_commit_hooks/loaderon_hooks/tests/automatic_testing/testing_samples/check_using_pylint_samples/incorrect.py b/pre_commit_hooks/loaderon_hooks/tests/automatic_testing/testing_samples/check_using_pylint_samples/incorrect.py index 7cd0492..7d9d5ea 100644 --- a/pre_commit_hooks/loaderon_hooks/tests/automatic_testing/testing_samples/check_using_pylint_samples/incorrect.py +++ b/pre_commit_hooks/loaderon_hooks/tests/automatic_testing/testing_samples/check_using_pylint_samples/incorrect.py @@ -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() diff --git a/pre_commit_hooks/loaderon_hooks/tests/automatic_testing/testing_samples/check_using_pylint_samples/incorrect_but_ignored.py b/pre_commit_hooks/loaderon_hooks/tests/automatic_testing/testing_samples/check_using_pylint_samples/incorrect_but_ignored.py index 7cd0492..7d9d5ea 100644 --- a/pre_commit_hooks/loaderon_hooks/tests/automatic_testing/testing_samples/check_using_pylint_samples/incorrect_but_ignored.py +++ b/pre_commit_hooks/loaderon_hooks/tests/automatic_testing/testing_samples/check_using_pylint_samples/incorrect_but_ignored.py @@ -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() diff --git a/pre_commit_hooks/loaderon_hooks/util/template_methods/file_checker_template_method.py b/pre_commit_hooks/loaderon_hooks/util/template_methods/file_checker_template_method.py index ba8364f..d2c3b95 100644 --- a/pre_commit_hooks/loaderon_hooks/util/template_methods/file_checker_template_method.py +++ b/pre_commit_hooks/loaderon_hooks/util/template_methods/file_checker_template_method.py @@ -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()