mirror of
https://github.com/pre-commit/pre-commit-hooks.git
synced 2026-04-06 03:56:54 +00:00
Tests for location checker
This commit is contained in:
parent
3232c22bdf
commit
b50feb702a
6 changed files with 41 additions and 0 deletions
|
|
@ -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)
|
||||||
Loading…
Add table
Add a link
Reference in a new issue