diff --git a/pre_commit_hooks/loaderon_hooks/tests/automatic_testing/general_hooks/check_xml_encoding_test.py b/pre_commit_hooks/loaderon_hooks/tests/automatic_testing/general_hooks/check_xml_encoding_test.py new file mode 100644 index 0000000..4f785d7 --- /dev/null +++ b/pre_commit_hooks/loaderon_hooks/tests/automatic_testing/general_hooks/check_xml_encoding_test.py @@ -0,0 +1,31 @@ +import sys + +import pytest + +from pre_commit_hooks.loaderon_hooks.general_hooks.check_xml_encoding import main +from pre_commit_hooks.loaderon_hooks.tests.automatic_testing.util.test_helpers import \ + perform_test_on_file_expecting_result + + +@pytest.fixture(autouse=True) +def clean_sys_argv(): + sys.argv = [] + + # Encoding to be checked + sys.argv.append('--encoding') + sys.argv.append(r'') + yield + + +def test_check_xml_encoding_ok(): + perform_test_on_file_expecting_result('check_xml_encoding_samples/ok.xml', main) + + +def test_check_xml_encoding_error_1(): + perform_test_on_file_expecting_result('check_xml_encoding_samples/no_encoding.xml', main, expected_result=2) + + +def test_check_xml_encoding_error_2(): + perform_test_on_file_expecting_result('check_xml_encoding_samples/first_line_is_empty_space.xml', + main, + expected_result=2) diff --git a/pre_commit_hooks/loaderon_hooks/tests/automatic_testing/testing_files/check_xml_encoding_samples/__init__.py b/pre_commit_hooks/loaderon_hooks/tests/automatic_testing/testing_files/check_xml_encoding_samples/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/pre_commit_hooks/loaderon_hooks/tests/automatic_testing/testing_files/check_xml_encoding_samples/first_line_is_empty_space.xml b/pre_commit_hooks/loaderon_hooks/tests/automatic_testing/testing_files/check_xml_encoding_samples/first_line_is_empty_space.xml new file mode 100644 index 0000000..3dfebd8 --- /dev/null +++ b/pre_commit_hooks/loaderon_hooks/tests/automatic_testing/testing_files/check_xml_encoding_samples/first_line_is_empty_space.xml @@ -0,0 +1,10 @@ + + + + + + some.model.form.inherit + some.model + + + diff --git a/pre_commit_hooks/loaderon_hooks/tests/automatic_testing/testing_files/check_xml_encoding_samples/no_encoding.xml b/pre_commit_hooks/loaderon_hooks/tests/automatic_testing/testing_files/check_xml_encoding_samples/no_encoding.xml new file mode 100644 index 0000000..c0b4a2f --- /dev/null +++ b/pre_commit_hooks/loaderon_hooks/tests/automatic_testing/testing_files/check_xml_encoding_samples/no_encoding.xml @@ -0,0 +1,8 @@ + + + + some.model.form.inherit + some.model + + + diff --git a/pre_commit_hooks/loaderon_hooks/tests/automatic_testing/testing_files/check_xml_encoding_samples/ok.xml b/pre_commit_hooks/loaderon_hooks/tests/automatic_testing/testing_files/check_xml_encoding_samples/ok.xml new file mode 100644 index 0000000..3b054a5 --- /dev/null +++ b/pre_commit_hooks/loaderon_hooks/tests/automatic_testing/testing_files/check_xml_encoding_samples/ok.xml @@ -0,0 +1,9 @@ + + + + + some.model.form.inherit + some.model + + +