Tests for location checker

This commit is contained in:
Alvaro Andrés Rodríguez Scelza 2019-06-07 14:54:15 -03:00
parent 3232c22bdf
commit b50feb702a
6 changed files with 41 additions and 0 deletions

View file

@ -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)