mirror of
https://github.com/pre-commit/pre-commit-hooks.git
synced 2026-04-05 11:36:54 +00:00
new tests for check line.
refactoring common code: sent to new tests util file
This commit is contained in:
parent
ae4b423b45
commit
d327922f34
6 changed files with 82 additions and 25 deletions
|
|
@ -1,59 +1,45 @@
|
|||
import os
|
||||
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_class_docstring import main
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def clean_sys_argv():
|
||||
def clean_():
|
||||
sys.argv = []
|
||||
yield
|
||||
|
||||
|
||||
def get_sample_file_path(file_name):
|
||||
current_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
testing_files_folder_path = current_path + '/testing_files/class_docstring_samples/'
|
||||
return testing_files_folder_path + file_name
|
||||
|
||||
|
||||
def perform_test_on_file_expecting_result(file_name, expected_result=0):
|
||||
sample_file_path = get_sample_file_path(file_name)
|
||||
sys.argv.append(sample_file_path)
|
||||
|
||||
result = main(sys.argv)
|
||||
|
||||
assert result == expected_result
|
||||
|
||||
|
||||
def test_docstring_ok():
|
||||
perform_test_on_file_expecting_result('docstring_ok.py')
|
||||
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('docstring_error_1.py', expected_result=2)
|
||||
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('docstring_error_2.py', expected_result=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('docstring_error_3.py', expected_result=2)
|
||||
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('docstring_error_4.py', expected_result=2)
|
||||
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('docstring_error_5.py', expected_result=2)
|
||||
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('docstring_error_6.py', expected_result=2)
|
||||
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('docstring_error_7.py', expected_result=2)
|
||||
perform_test_on_file_expecting_result('check_class_docstring_samples/docstring_error_7.py', main, expected_result=2)
|
||||
|
|
|
|||
|
|
@ -0,0 +1,45 @@
|
|||
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_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)
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo>
|
||||
<data>
|
||||
<record id="id" model="ir.ui.view">
|
||||
<field name="name">some.model.form.inherit</field>
|
||||
<field name="model">some.model</field>
|
||||
</record>
|
||||
</data>
|
||||
</odoo>
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
import os
|
||||
import sys
|
||||
|
||||
|
||||
def get_sample_file_path(file_name):
|
||||
current_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
testing_files_folder_path = current_path + '/testing_files/'
|
||||
return testing_files_folder_path + file_name
|
||||
|
||||
|
||||
def perform_test_on_file_expecting_result(file_name, main_function, expected_result=0):
|
||||
sample_file_path = get_sample_file_path(file_name)
|
||||
sys.argv.append(sample_file_path)
|
||||
|
||||
result = main_function(sys.argv)
|
||||
|
||||
assert result == expected_result
|
||||
Loading…
Add table
Add a link
Reference in a new issue