From b50feb702ae3a48c00faa7236191b6d5d9d43e50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alvaro=20Andr=C3=A9s=20Rodr=C3=ADguez=20Scelza?= Date: Fri, 7 Jun 2019 14:54:15 -0300 Subject: [PATCH] Tests for location checker --- .../general_hooks/check_location_test.py | 41 +++++++++++++++++++ .../check_location_samples/__init__.py | 0 .../javascript/correct_js.js | 0 .../not_enabled_directory/incorrect_xml.xml | 0 .../xml/correct_xml.xml | 0 .../xml/incorrect_js.js | 0 6 files changed, 41 insertions(+) create mode 100644 pre_commit_hooks/loaderon_hooks/tests/automatic_testing/general_hooks/check_location_test.py create mode 100644 pre_commit_hooks/loaderon_hooks/tests/automatic_testing/testing_files/check_location_samples/__init__.py create mode 100644 pre_commit_hooks/loaderon_hooks/tests/automatic_testing/testing_files/check_location_samples/javascript/correct_js.js create mode 100644 pre_commit_hooks/loaderon_hooks/tests/automatic_testing/testing_files/check_location_samples/not_enabled_directory/incorrect_xml.xml create mode 100644 pre_commit_hooks/loaderon_hooks/tests/automatic_testing/testing_files/check_location_samples/xml/correct_xml.xml create mode 100644 pre_commit_hooks/loaderon_hooks/tests/automatic_testing/testing_files/check_location_samples/xml/incorrect_js.js 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 new file mode 100644 index 0000000..595e81f --- /dev/null +++ b/pre_commit_hooks/loaderon_hooks/tests/automatic_testing/general_hooks/check_location_test.py @@ -0,0 +1,41 @@ +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_location import main + + +@pytest.fixture(autouse=True) +def clean_sys_argv(): + sys.argv = [] + + # Each line is a directory that allows certain types of files. + sys.argv.append('--directories') + sys.argv.append(r'.*\/xml') + sys.argv.append('--directories') + sys.argv.append(r'.*\/javascript') + + # Each line specifies what types of files can be located inside the directory. + sys.argv.append('--files') + sys.argv.append(r'correct_xml.xml') + sys.argv.append('--files') + sys.argv.append(r'correct_js.js') + yield + + +def test_locations_ok_1(): + perform_test_on_file_expecting_result('check_location_samples/xml/correct_xml.xml', main) + + +def test_locations_ok_2(): + perform_test_on_file_expecting_result('check_location_samples/javascript/correct_js.js', main) + + +def test_locations_error1(): + perform_test_on_file_expecting_result('check_location_samples/xml/incorrect_js.js', main, expected_result=2) + + +def test_locations_error2(): + perform_test_on_file_expecting_result('check_location_samples/not_enabled_directory/incorrect_xml.xml', main, expected_result=2) diff --git a/pre_commit_hooks/loaderon_hooks/tests/automatic_testing/testing_files/check_location_samples/__init__.py b/pre_commit_hooks/loaderon_hooks/tests/automatic_testing/testing_files/check_location_samples/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/pre_commit_hooks/loaderon_hooks/tests/automatic_testing/testing_files/check_location_samples/javascript/correct_js.js b/pre_commit_hooks/loaderon_hooks/tests/automatic_testing/testing_files/check_location_samples/javascript/correct_js.js new file mode 100644 index 0000000..e69de29 diff --git a/pre_commit_hooks/loaderon_hooks/tests/automatic_testing/testing_files/check_location_samples/not_enabled_directory/incorrect_xml.xml b/pre_commit_hooks/loaderon_hooks/tests/automatic_testing/testing_files/check_location_samples/not_enabled_directory/incorrect_xml.xml new file mode 100644 index 0000000..e69de29 diff --git a/pre_commit_hooks/loaderon_hooks/tests/automatic_testing/testing_files/check_location_samples/xml/correct_xml.xml b/pre_commit_hooks/loaderon_hooks/tests/automatic_testing/testing_files/check_location_samples/xml/correct_xml.xml new file mode 100644 index 0000000..e69de29 diff --git a/pre_commit_hooks/loaderon_hooks/tests/automatic_testing/testing_files/check_location_samples/xml/incorrect_js.js b/pre_commit_hooks/loaderon_hooks/tests/automatic_testing/testing_files/check_location_samples/xml/incorrect_js.js new file mode 100644 index 0000000..e69de29