diff --git a/pre_commit_hooks/loaderon_hooks/Documentation/automatic_testing.txt b/pre_commit_hooks/loaderon_hooks/Documentation/automatic_testing.txt index 5933dfe..990c754 100644 --- a/pre_commit_hooks/loaderon_hooks/Documentation/automatic_testing.txt +++ b/pre_commit_hooks/loaderon_hooks/Documentation/automatic_testing.txt @@ -3,7 +3,7 @@ ALL pre_commit_hooks tests, not only Loaderon's): coverage erase coverage run --source pre_commit_hooks -m pytest -coverage report --fail-under 100 +coverage report ####################################################################################################################### diff --git a/pre_commit_hooks/loaderon_hooks/tests/automatic_testing/check_branch_name_test.py b/pre_commit_hooks/loaderon_hooks/tests/automatic_testing/check_branch_name_test.py new file mode 100644 index 0000000..1fb89db --- /dev/null +++ b/pre_commit_hooks/loaderon_hooks/tests/automatic_testing/check_branch_name_test.py @@ -0,0 +1,37 @@ +import subprocess +import sys +import uuid + +import pytest + +from pre_commit_hooks.loaderon_hooks.general_hooks.check_branch_name import main + + +@pytest.fixture(autouse=True) +def clean_sys_argv(): + sys.argv = [] + yield + + +def test_branch_name_ok(): + new_branch_name = str(uuid.uuid4()) + subprocess.check_output(['git', 'checkout', '-b', new_branch_name]) + sys.argv.append('--regex') + sys.argv.append(r'\b(?!master)\b\S+') + + result = main(sys.argv) + + subprocess.check_output(['git', 'checkout', 'master']) + subprocess.check_output(['git', 'branch', '-d', new_branch_name]) + + assert result == 0 + + +def test_branch_name_error(): + subprocess.check_output(['git', 'checkout', 'master']) + sys.argv.append('--regex') + sys.argv.append(r'\b(?!master)\b\S+') + + result = main(sys.argv) + + assert result == 2