示例#1
0
def test_ignore_list():
    """Test that `ignore`d errors are not reported in the API."""
    function_to_check = textwrap.dedent('''
        def function_with_bad_docstring(foo):
            """ does spacinwithout a period in the end
            no blank line after one-liner is bad. Also this - """
            return foo
    ''')
    expected_error_codes = {'D100', 'D400', 'D401', 'D205', 'D209', 'D210',
                            'D403'}
    mock_open = mock.mock_open(read_data=function_to_check)
    from pydocstyle import checker
    with mock.patch.object(
            checker.tk, 'open', mock_open, create=True):
        errors = tuple(checker.check(['filepath']))
        error_codes = {error.code for error in errors}
        assert error_codes == expected_error_codes

    # We need to recreate the mock, otherwise the read file is empty
    mock_open = mock.mock_open(read_data=function_to_check)
    with mock.patch.object(
            checker.tk, 'open', mock_open, create=True):
        ignored = {'D100', 'D202', 'D213'}
        errors = tuple(checker.check(['filepath'], ignore=ignored))
        error_codes = {error.code for error in errors}
        assert error_codes == expected_error_codes - ignored
示例#2
0
def test_ignore_list():
    """Test that `ignore`d errors are not reported in the API."""
    function_to_check = textwrap.dedent('''
        def function_with_bad_docstring(foo):
            """ does spacinwithout a period in the end
            no blank line after one-liner is bad. Also this - """
            return foo
    ''')
    expected_error_codes = {
        'D100', 'D400', 'D401', 'D205', 'D209', 'D210', 'D403', 'D415', 'D213'
    }
    mock_open = mock.mock_open(read_data=function_to_check)
    from pydocstyle import checker
    with mock.patch.object(checker.tk, 'open', mock_open, create=True):
        # Passing a blank ignore here explicitly otherwise
        # checkers takes the pep257 ignores by default.
        errors = tuple(checker.check(['filepath'], ignore={}))
        error_codes = {error.code for error in errors}
        assert error_codes == expected_error_codes

    # We need to recreate the mock, otherwise the read file is empty
    mock_open = mock.mock_open(read_data=function_to_check)
    with mock.patch.object(checker.tk, 'open', mock_open, create=True):
        ignored = {'D100', 'D202', 'D213'}
        errors = tuple(checker.check(['filepath'], ignore=ignored))
        error_codes = {error.code for error in errors}
        assert error_codes == expected_error_codes - ignored
示例#3
0
    def setUpClass(cls):

        cls.violations = list()

        # TODO: fix all violations to make it empty
        _disabled_checks = [
            'D205',  # 1 blank line required between summary line and description
            'D102',  # Missing docstring in public method
            'D400',  # First line should end with a period
            'D100',  # Missing docstring in public module
            'D107',  # Missing docstring in __init__
            'D103',  # Missing docstring in public function
            'D401',  # First line should be in imperative mood
            'D101',  # Missing docstring in public class
            'D413',  # Missing blank line after last section
            'D105',  # Missing docstring in magic method
            'D104',  # Missing docstring in public package
            'D302',  # Use u"""for Unicode docstrings

            # Rules that has conflict with yapf
            'D202',  # No blank lines allowed after function docstring
        ]

        for filename in list_all_py_files():
            print(filename)
            for err in check([filename]):
                if not err.code in _disabled_checks:
                    cls.violations.append(err)
示例#4
0
    def setUpClass(cls):

        cls.violations = list()

        # TODO: fix all violations to make it empty
        _disabled_checks = [
            'D205',  # 1 blank line required between summary line and description
            'D102',  # Missing docstring in public method
            'D400',  # First line should end with a period
            'D100',  # Missing docstring in public module
            'D107',  # Missing docstring in __init__
            'D103',  # Missing docstring in public function
            'D401',  # First line should be in imperative mood
            'D101',  # Missing docstring in public class
            'D413',  # Missing blank line after last section
            'D105',  # Missing docstring in magic method
            'D104',  # Missing docstring in public package
            'D302',  # Use u"""for Unicode docstrings

            # Rules that has conflict with yapf
            'D202',  # No blank lines allowed after function docstring
        ]

        for filename in list_all_py_files():
            print(filename)
            for err in check([filename]):
                if not err.code in _disabled_checks:
                    cls.violations.append(err)
示例#5
0
def test_pep257_conformance():
    """Test that we conform to PEP 257."""
    base_dir = (pathlib.Path(__file__).parent / '..').resolve()
    excluded = base_dir / 'tests' / 'test_cases'
    src_files = (str(path) for path in base_dir.glob('**/*.py')
                 if excluded not in path.parents)

    ignored = {'D104', 'D105'}
    select = violations.conventions.pep257 - ignored
    errors = list(checker.check(src_files, select=select))
    assert errors == [], errors
示例#6
0
def test_pep257_conformance():
    """Test that we conform to PEP 257."""
    base_dir = (pathlib.Path(__file__).parent / '..').resolve()
    src_dirs = (base_dir, base_dir / 'tests')
    src_files = []
    for src_dir in src_dirs:
        src_files.extend(str(path) for path in src_dir.glob('*.py'))

    ignored = {'D104', 'D105'}
    select = violations.conventions.pep257 - ignored
    errors = list(checker.check(src_files, select=select))
    assert errors == [], errors
示例#7
0
def test_pep257_conformance():
    """Test that we conform to PEP 257."""
    base_dir = (pathlib.Path(__file__).parent / '..').resolve()
    src_dirs = (base_dir, base_dir / 'tests')
    src_files = []
    for src_dir in src_dirs:
        src_files.extend(str(path) for path in src_dir.glob('*.py'))

    ignored = {'D104', 'D105'}
    select = violations.conventions.pep257 - ignored
    errors = list(checker.check(src_files, select=select))
    assert errors == [], errors
def test_ignore_list():
    function_to_check = textwrap.dedent('''
        def function_with_bad_docstring(foo):
            """ does spacinwithout a period in the end
            no blank line after one-liner is bad. Also this - """
            return foo
    ''')
    expected_error_codes = set(
        ('D100', 'D400', 'D401', 'D205', 'D209', 'D210', 'D403'))
    mock_open = mock.mock_open(read_data=function_to_check)
    from pydocstyle import checker
    with mock.patch.object(checker, 'tokenize_open', mock_open, create=True):
        errors = tuple(checker.check(['filepath']))
        error_codes = set(error.code for error in errors)
        assert error_codes == expected_error_codes

    # We need to recreate the mock, otherwise the read file is empty
    mock_open = mock.mock_open(read_data=function_to_check)
    with mock.patch.object(checker, 'tokenize_open', mock_open, create=True):
        ignored = set(('D100', 'D202', 'D213'))
        errors = tuple(checker.check(['filepath'], ignore=ignored))
        error_codes = set(error.code for error in errors)
        assert error_codes == expected_error_codes - ignored
示例#9
0
    def setUpClass(cls):

        cls.violations = list()

        _disabled_checks = [
            'D202',  # No blank lines allowed after function docstring
            'D205',  # 1 blank line required between summary line and description
        ]

        for filename in testing.list_all_py_files():

            print(filename)
            for err in check([filename]):

                if not err.code in _disabled_checks:
                    cls.violations.append(err)
示例#10
0
def test_pep257(test_case):
    """Run domain-specific tests from test.py file."""
    case_module = __import__('test_cases.{0}'.format(test_case),
                             globals=globals(),
                             locals=locals(),
                             fromlist=['expectation'],
                             level=1)
    results = list(
        check([
            os.path.join(os.path.dirname(__file__), 'test_cases',
                         test_case + '.py')
        ],
              select=set(ErrorRegistry.get_error_codes())))
    for error in results:
        assert isinstance(error, Error)
    results = set([(e.definition.name, e.message) for e in results])
    assert case_module.expectation.expected == results
示例#11
0
def test_pep257(test_case):
    """Run domain-specific tests from test.py file."""
    case_module = __import__('test_cases.{}'.format(test_case),
                             globals=globals(),
                             locals=locals(),
                             fromlist=['expectation'],
                             level=1)
    test_case_dir = os.path.normcase(os.path.dirname(__file__))
    test_case_file = os.path.join(test_case_dir,
                                  'test_cases',
                                  test_case + '.py')
    results = list(check([test_case_file],
                         select=set(ErrorRegistry.get_error_codes()),
                         ignore_decorators=re.compile('wraps')))
    for error in results:
        assert isinstance(error, Error)
    results = set([(e.definition.name, e.message) for e in results])
    assert case_module.expectation.expected == results
示例#12
0
def test_complex_file(test_case):
    """Run domain-specific tests from test.py file."""
    case_module = __import__('test_cases.{}'.format(test_case),
                             globals=globals(),
                             locals=locals(),
                             fromlist=['expectation'],
                             level=1)
    test_case_dir = os.path.normcase(os.path.dirname(__file__))
    test_case_file = os.path.join(test_case_dir, 'test_cases',
                                  test_case + '.py')
    results = list(
        check([test_case_file],
              select=set(ErrorRegistry.get_error_codes()),
              ignore_decorators=re.compile('wraps')))
    for error in results:
        assert isinstance(error, Error)
    results = {(e.definition.name, e.message) for e in results}
    assert case_module.expectation.expected == results
示例#13
0
def check_all_files():
    for filename in testing.list_all_py_files():
        for err in check([filename]):
            if not err.code in _disabled_checks:
                yield err