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 7455a29..956fc28 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,59 +1,45 @@ -import os import sys import pytest +from pre_commit_hooks.loaderon_hooks.tests.automatic_testing.util.test_helpers import \ + perform_test_on_file_expecting_result from pre_commit_hooks.loaderon_hooks.general_hooks.check_class_docstring import main @pytest.fixture(autouse=True) -def clean_sys_argv(): +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') + perform_test_on_file_expecting_result('check_class_docstring_samples/docstring_ok.py', main) def test_docstring_error_1(): - perform_test_on_file_expecting_result('docstring_error_1.py', expected_result=2) + perform_test_on_file_expecting_result('check_class_docstring_samples/docstring_error_1.py', main, expected_result=2) def test_docstring_error_2(): - perform_test_on_file_expecting_result('docstring_error_2.py', expected_result=2) + perform_test_on_file_expecting_result('check_class_docstring_samples/docstring_error_2.py', main, expected_result=2) def test_docstring_error_3(): - perform_test_on_file_expecting_result('docstring_error_3.py', expected_result=2) + perform_test_on_file_expecting_result('check_class_docstring_samples/docstring_error_3.py', main, expected_result=2) def test_docstring_error_4(): - perform_test_on_file_expecting_result('docstring_error_4.py', expected_result=2) + perform_test_on_file_expecting_result('check_class_docstring_samples/docstring_error_4.py', main, expected_result=2) def test_docstring_error_5(): - perform_test_on_file_expecting_result('docstring_error_5.py', expected_result=2) + perform_test_on_file_expecting_result('check_class_docstring_samples/docstring_error_5.py', main, expected_result=2) def test_docstring_error_6(): - perform_test_on_file_expecting_result('docstring_error_6.py', expected_result=2) + perform_test_on_file_expecting_result('check_class_docstring_samples/docstring_error_6.py', main, expected_result=2) def test_docstring_error_7(): - perform_test_on_file_expecting_result('docstring_error_7.py', expected_result=2) + perform_test_on_file_expecting_result('check_class_docstring_samples/docstring_error_7.py', main, expected_result=2) diff --git a/pre_commit_hooks/loaderon_hooks/tests/automatic_testing/general_hooks/check_line_test.py b/pre_commit_hooks/loaderon_hooks/tests/automatic_testing/general_hooks/check_line_test.py new file mode 100644 index 0000000..07ab4b6 --- /dev/null +++ b/pre_commit_hooks/loaderon_hooks/tests/automatic_testing/general_hooks/check_line_test.py @@ -0,0 +1,45 @@ +import sys + +import pytest + +from pre_commit_hooks.loaderon_hooks.tests.automatic_testing.util.test_helpers import \ + perform_test_on_file_expecting_result +from pre_commit_hooks.loaderon_hooks.general_hooks.check_line import main + + +@pytest.fixture(autouse=True) +def clean_sys_argv(): + sys.argv = [] + + # Multiple checks, one regexp per type of line to check. + sys.argv.append('--line-to-check') + sys.argv.append(r'^(\t| )* + + + + some.model.form.inherit + some.model + + + diff --git a/pre_commit_hooks/loaderon_hooks/tests/automatic_testing/util/__init__.py b/pre_commit_hooks/loaderon_hooks/tests/automatic_testing/util/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/pre_commit_hooks/loaderon_hooks/tests/automatic_testing/util/test_helpers.py b/pre_commit_hooks/loaderon_hooks/tests/automatic_testing/util/test_helpers.py new file mode 100644 index 0000000..9ed9466 --- /dev/null +++ b/pre_commit_hooks/loaderon_hooks/tests/automatic_testing/util/test_helpers.py @@ -0,0 +1,17 @@ +import os +import sys + + +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/' + return testing_files_folder_path + file_name + + +def perform_test_on_file_expecting_result(file_name, main_function, expected_result=0): + sample_file_path = get_sample_file_path(file_name) + sys.argv.append(sample_file_path) + + result = main_function(sys.argv) + + assert result == expected_result