mirror of
https://github.com/pre-commit/pre-commit-hooks.git
synced 2026-04-06 03:56:54 +00:00
added unversioned files
This commit is contained in:
parent
bc7315b861
commit
71ee80081d
53 changed files with 1178 additions and 0 deletions
|
|
@ -0,0 +1,37 @@
|
|||
import subprocess
|
||||
import sys
|
||||
import uuid
|
||||
|
||||
import pytest
|
||||
|
||||
from pre_commit_hooks.loaderon_hooks.general_hooks.check_branch_name import main
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def clean_sys_argv():
|
||||
sys.argv = []
|
||||
yield
|
||||
|
||||
|
||||
def test_branch_name_ok():
|
||||
new_branch_name = str(uuid.uuid4())
|
||||
subprocess.check_output(['git', 'checkout', '-b', new_branch_name])
|
||||
sys.argv.append('--regex')
|
||||
sys.argv.append(r'\b(?!master)\b\S+')
|
||||
|
||||
result = main(sys.argv)
|
||||
|
||||
subprocess.check_output(['git', 'checkout', 'master'])
|
||||
subprocess.check_output(['git', 'branch', '-d', new_branch_name])
|
||||
|
||||
assert result == 0
|
||||
|
||||
|
||||
def test_branch_name_error():
|
||||
subprocess.check_output(['git', 'checkout', 'master'])
|
||||
sys.argv.append('--regex')
|
||||
sys.argv.append(r'\b(?!master)\b\S+')
|
||||
|
||||
result = main(sys.argv)
|
||||
|
||||
assert result == 2
|
||||
|
|
@ -0,0 +1,44 @@
|
|||
import sys
|
||||
|
||||
import pytest
|
||||
|
||||
from pre_commit_hooks.loaderon_hooks.tests.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 = []
|
||||
yield
|
||||
|
||||
|
||||
def test_docstring_ok():
|
||||
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('check_class_docstring_samples/docstring_error_1.py', main, expected_result=2)
|
||||
|
||||
|
||||
def test_docstring_error_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('check_class_docstring_samples/docstring_error_3.py', main, expected_result=2)
|
||||
|
||||
|
||||
def test_docstring_error_4():
|
||||
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('check_class_docstring_samples/docstring_error_5.py', main, expected_result=2)
|
||||
|
||||
|
||||
def test_docstring_error_6():
|
||||
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('check_class_docstring_samples/docstring_error_7.py', main, expected_result=2)
|
||||
|
|
@ -0,0 +1,48 @@
|
|||
import sys
|
||||
|
||||
import pytest
|
||||
|
||||
from pre_commit_hooks.loaderon_hooks.tests.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| )*<field.+')
|
||||
sys.argv.append('--line-to-check')
|
||||
sys.argv.append(r'^(\t| )*<record.+')
|
||||
sys.argv.append('--line-to-check')
|
||||
sys.argv.append(r'.+fields.Many2one.+')
|
||||
sys.argv.append('--line-to-check')
|
||||
sys.argv.append(r'.+fields.One2many.+')
|
||||
sys.argv.append('--line-to-check')
|
||||
sys.argv.append(r'.+fields.Many2many.+')
|
||||
sys.argv.append('--line-to-check')
|
||||
sys.argv.append(r'class.+')
|
||||
|
||||
# Regexp for knowing how the line must be in order to be correct.
|
||||
sys.argv.append('--regexp-to-match')
|
||||
sys.argv.append(r'^(\t| )*<field name=".+"')
|
||||
sys.argv.append('--regexp-to-match')
|
||||
sys.argv.append(r'^(\t| )*<record id=".+"')
|
||||
sys.argv.append('--regexp-to-match')
|
||||
sys.argv.append(r'^(\t| )*.+_id = fields.Many2one\(')
|
||||
sys.argv.append('--regexp-to-match')
|
||||
sys.argv.append(r'^(\t| )*.+_ids = fields.One2many\(')
|
||||
sys.argv.append('--regexp-to-match')
|
||||
sys.argv.append(r'^(\t| )*.+_ids = fields.Many2many\(')
|
||||
sys.argv.append('--regexp-to-match')
|
||||
sys.argv.append(r'class ([A-Z]+[a-z0-9]+)+\(models.Model\):')
|
||||
yield
|
||||
|
||||
|
||||
def test_odoo_xml_field_and_record_declaration_ok():
|
||||
perform_test_on_file_expecting_result('check_line_samples/xml_lines_ok.xml', main)
|
||||
|
||||
|
||||
def test_odoo_xml_record_declaration_error():
|
||||
perform_test_on_file_expecting_result('check_line_samples/xml_lines_error_1.xml', main, expected_result=2)
|
||||
|
|
@ -0,0 +1,62 @@
|
|||
import sys
|
||||
|
||||
import pytest
|
||||
|
||||
from pre_commit_hooks.loaderon_hooks.tests.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)
|
||||
|
||||
|
||||
def test_locations_arguments_size_mismatch_error():
|
||||
sys.argv = []
|
||||
|
||||
sys.argv.append('--directories')
|
||||
sys.argv.append(r'.*\/xml')
|
||||
# Lacking files for this directory
|
||||
sys.argv.append('--directories')
|
||||
sys.argv.append(r'.*\/javascript')
|
||||
|
||||
sys.argv.append('--files')
|
||||
sys.argv.append(r'correct_xml.xml')
|
||||
|
||||
perform_test_on_file_expecting_result('check_location_samples/xml/correct_xml.xml', main, expected_result=2)
|
||||
|
||||
|
||||
def test_locations_no_arguments_error():
|
||||
sys.argv = []
|
||||
with pytest.raises(TypeError) as error:
|
||||
perform_test_on_file_expecting_result('check_location_samples/xml/correct_xml.xml', main)
|
||||
assert "'NoneType' object is not iterable" in str(error.value)
|
||||
|
|
@ -0,0 +1,46 @@
|
|||
import os
|
||||
import sys
|
||||
import sys
|
||||
import unittest
|
||||
|
||||
import mock
|
||||
import pytest
|
||||
|
||||
from pre_commit_hooks.loaderon_hooks.general_hooks.check_using_pylint import main
|
||||
from pre_commit_hooks.loaderon_hooks.tests.util.test_helpers import perform_test_on_file_expecting_result
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def clean_sys_argv():
|
||||
sys.argv = []
|
||||
|
||||
# What files should we exclude from pylint checker
|
||||
sys.argv.append('--exclude')
|
||||
sys.argv.append(r'.*(\/)*incorrect_but_ignored.py')
|
||||
yield
|
||||
|
||||
|
||||
def test_with_pylint_ok():
|
||||
perform_test_on_file_expecting_result('check_using_pylint_samples/correct.py', main)
|
||||
|
||||
|
||||
def test_with_pylint_ignored():
|
||||
perform_test_on_file_expecting_result('check_using_pylint_samples/incorrect_but_ignored.py', main)
|
||||
|
||||
|
||||
def test_with_pylint_error():
|
||||
perform_test_on_file_expecting_result('check_using_pylint_samples/incorrect.py', main, expected_result=2)
|
||||
|
||||
|
||||
def walk_return(folder_path):
|
||||
loaderon_hooks_folder = os.path.dirname(folder_path)
|
||||
root = loaderon_hooks_folder + '/tests/testing_samples/check_using_pylint_samples'
|
||||
unused_dirs = []
|
||||
files = ['.pylintrc']
|
||||
return [(root, unused_dirs, files)]
|
||||
|
||||
|
||||
class TestWithPylintConf(unittest.TestCase):
|
||||
@mock.patch('os.walk', side_effect=walk_return)
|
||||
def test_with_pylint_conf_ok(self, walk_function):
|
||||
perform_test_on_file_expecting_result('check_using_pylint_samples/correct.py', main)
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
import sys
|
||||
|
||||
import pytest
|
||||
|
||||
from pre_commit_hooks.loaderon_hooks.general_hooks.check_xml_encoding import main
|
||||
from pre_commit_hooks.loaderon_hooks.tests.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'<?xml version="1.0" encoding="utf-8"?>')
|
||||
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)
|
||||
Loading…
Add table
Add a link
Reference in a new issue