mirror of
https://github.com/pre-commit/pre-commit-hooks.git
synced 2026-04-05 11:36:54 +00:00
organizing docsttring tests
This commit is contained in:
parent
fab7447c37
commit
8b6d2a5539
6 changed files with 61 additions and 44 deletions
|
|
@ -1,10 +1,9 @@
|
|||
import subprocess
|
||||
import os
|
||||
import sys
|
||||
import uuid
|
||||
|
||||
import pytest
|
||||
|
||||
from pre_commit_hooks.loaderon_hooks.general_hooks.check_branch_name import main
|
||||
from pre_commit_hooks.loaderon_hooks.general_hooks.check_class_docstring import main
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
|
|
@ -13,27 +12,48 @@ 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')
|
||||
|
||||
|
||||
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_docstring_error_1():
|
||||
perform_test_on_file_expecting_result('docstring_error_1.py', expected_result=2)
|
||||
|
||||
|
||||
def test_branch_name_error():
|
||||
subprocess.check_output(['git', 'checkout', 'master'])
|
||||
sys.argv.append('--regex')
|
||||
sys.argv.append(r'\b(?!master)\b\S+')
|
||||
def test_docstring_error_2():
|
||||
perform_test_on_file_expecting_result('docstring_error_2.py', expected_result=2)
|
||||
|
||||
result = main(sys.argv)
|
||||
|
||||
assert result == 2
|
||||
def test_docstring_error_3():
|
||||
perform_test_on_file_expecting_result('docstring_error_3.py', expected_result=2)
|
||||
|
||||
|
||||
def test_docstring_error_4():
|
||||
perform_test_on_file_expecting_result('docstring_error_4.py', expected_result=2)
|
||||
|
||||
|
||||
def test_docstring_error_5():
|
||||
perform_test_on_file_expecting_result('docstring_error_5.py', expected_result=2)
|
||||
|
||||
|
||||
def test_docstring_error_6():
|
||||
perform_test_on_file_expecting_result('docstring_error_6.py', expected_result=2)
|
||||
|
||||
|
||||
def test_docstring_error_7():
|
||||
perform_test_on_file_expecting_result('docstring_error_7.py', expected_result=2)
|
||||
|
|
|
|||
|
|
@ -0,0 +1,21 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
|
||||
class TestingClass(object): # SHOULD PASS
|
||||
""""""
|
||||
|
||||
|
||||
class TestingClass1(object): # SHOULD PASS
|
||||
"""
|
||||
Hola mundo
|
||||
"""
|
||||
|
||||
|
||||
class TestingClass2(object): # SHOULD PASS
|
||||
"""Hola mundo"""
|
||||
|
||||
|
||||
class TestingClass3(object): # SHOULD PASS
|
||||
"""Hola mundo"""
|
||||
class InternalTestingClass(object):
|
||||
"""Hola mundo"""
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
|
||||
class TestingClass(object): # SHOULD PASS
|
||||
""""""
|
||||
|
|
@ -1,7 +0,0 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
|
||||
class TestingClass(object): # SHOULD PASS
|
||||
"""
|
||||
Hola mundo
|
||||
"""
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
|
||||
class TestingClass(object): # SHOULD PASS
|
||||
"""Hola mundo"""
|
||||
|
|
@ -1,7 +0,0 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
|
||||
class TestingClass(object): # SHOULD PASS
|
||||
"""Hola mundo"""
|
||||
class InternalTestingClass(object):
|
||||
"""Hola mundo"""
|
||||
Loading…
Add table
Add a link
Reference in a new issue