diff --git a/pre_commit_hooks/loaderon_hooks/tests/automatic_testing/general_hooks/check_class_docstring_test.py b/pre_commit_hooks/loaderon_hooks/tests/automatic_testing/general_hooks/check_class_docstring_test.py index d05a282..7455a29 100644 --- a/pre_commit_hooks/loaderon_hooks/tests/automatic_testing/general_hooks/check_class_docstring_test.py +++ b/pre_commit_hooks/loaderon_hooks/tests/automatic_testing/general_hooks/check_class_docstring_test.py @@ -1,10 +1,9 @@ -import subprocess +import os import sys -import uuid import pytest -from pre_commit_hooks.loaderon_hooks.general_hooks.check_branch_name import main +from pre_commit_hooks.loaderon_hooks.general_hooks.check_class_docstring import main @pytest.fixture(autouse=True) @@ -13,27 +12,48 @@ def clean_sys_argv(): yield +def get_sample_file_path(file_name): + current_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + testing_files_folder_path = current_path + '/testing_files/class_docstring_samples/' + return testing_files_folder_path + file_name + + +def perform_test_on_file_expecting_result(file_name, expected_result=0): + sample_file_path = get_sample_file_path(file_name) + sys.argv.append(sample_file_path) + + result = main(sys.argv) + + assert result == expected_result + + def test_docstring_ok(): + perform_test_on_file_expecting_result('docstring_ok.py') - 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_docstring_error_1(): + perform_test_on_file_expecting_result('docstring_error_1.py', expected_result=2) -def test_branch_name_error(): - subprocess.check_output(['git', 'checkout', 'master']) - sys.argv.append('--regex') - sys.argv.append(r'\b(?!master)\b\S+') +def test_docstring_error_2(): + perform_test_on_file_expecting_result('docstring_error_2.py', expected_result=2) - result = main(sys.argv) - assert result == 2 +def test_docstring_error_3(): + perform_test_on_file_expecting_result('docstring_error_3.py', expected_result=2) + + +def test_docstring_error_4(): + perform_test_on_file_expecting_result('docstring_error_4.py', expected_result=2) + + +def test_docstring_error_5(): + perform_test_on_file_expecting_result('docstring_error_5.py', expected_result=2) + + +def test_docstring_error_6(): + perform_test_on_file_expecting_result('docstring_error_6.py', expected_result=2) + + +def test_docstring_error_7(): + perform_test_on_file_expecting_result('docstring_error_7.py', expected_result=2) diff --git a/pre_commit_hooks/loaderon_hooks/tests/automatic_testing/testing_files/class_docstring_samples/docstring_ok.py b/pre_commit_hooks/loaderon_hooks/tests/automatic_testing/testing_files/class_docstring_samples/docstring_ok.py new file mode 100644 index 0000000..e8be810 --- /dev/null +++ b/pre_commit_hooks/loaderon_hooks/tests/automatic_testing/testing_files/class_docstring_samples/docstring_ok.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- + + +class TestingClass(object): # SHOULD PASS + """""" + + +class TestingClass1(object): # SHOULD PASS + """ + Hola mundo + """ + + +class TestingClass2(object): # SHOULD PASS + """Hola mundo""" + + +class TestingClass3(object): # SHOULD PASS + """Hola mundo""" + class InternalTestingClass(object): + """Hola mundo""" diff --git a/pre_commit_hooks/loaderon_hooks/tests/automatic_testing/testing_files/class_docstring_samples/docstring_ok_1.py b/pre_commit_hooks/loaderon_hooks/tests/automatic_testing/testing_files/class_docstring_samples/docstring_ok_1.py deleted file mode 100644 index c66f26a..0000000 --- a/pre_commit_hooks/loaderon_hooks/tests/automatic_testing/testing_files/class_docstring_samples/docstring_ok_1.py +++ /dev/null @@ -1,5 +0,0 @@ -# -*- coding: utf-8 -*- - - -class TestingClass(object): # SHOULD PASS - """""" diff --git a/pre_commit_hooks/loaderon_hooks/tests/automatic_testing/testing_files/class_docstring_samples/docstring_ok_2.py b/pre_commit_hooks/loaderon_hooks/tests/automatic_testing/testing_files/class_docstring_samples/docstring_ok_2.py deleted file mode 100644 index 4edd464..0000000 --- a/pre_commit_hooks/loaderon_hooks/tests/automatic_testing/testing_files/class_docstring_samples/docstring_ok_2.py +++ /dev/null @@ -1,7 +0,0 @@ -# -*- coding: utf-8 -*- - - -class TestingClass(object): # SHOULD PASS - """ - Hola mundo - """ diff --git a/pre_commit_hooks/loaderon_hooks/tests/automatic_testing/testing_files/class_docstring_samples/docstring_ok_3.py b/pre_commit_hooks/loaderon_hooks/tests/automatic_testing/testing_files/class_docstring_samples/docstring_ok_3.py deleted file mode 100644 index c1470b9..0000000 --- a/pre_commit_hooks/loaderon_hooks/tests/automatic_testing/testing_files/class_docstring_samples/docstring_ok_3.py +++ /dev/null @@ -1,5 +0,0 @@ -# -*- coding: utf-8 -*- - - -class TestingClass(object): # SHOULD PASS - """Hola mundo""" diff --git a/pre_commit_hooks/loaderon_hooks/tests/automatic_testing/testing_files/class_docstring_samples/docstring_ok_4.py b/pre_commit_hooks/loaderon_hooks/tests/automatic_testing/testing_files/class_docstring_samples/docstring_ok_4.py deleted file mode 100644 index 25b1ef3..0000000 --- a/pre_commit_hooks/loaderon_hooks/tests/automatic_testing/testing_files/class_docstring_samples/docstring_ok_4.py +++ /dev/null @@ -1,7 +0,0 @@ -# -*- coding: utf-8 -*- - - -class TestingClass(object): # SHOULD PASS - """Hola mundo""" - class InternalTestingClass(object): - """Hola mundo"""