def hacked_pep257(to_lint): """ Check for the presence of docstrings, but ignore some of the options """ def ignore(*args, **kwargs): pass pep257.check_blank_before_after_class = ignore pep257.check_blank_after_last_paragraph = ignore pep257.check_blank_after_summary = ignore pep257.check_ends_with_period = ignore pep257.check_one_liners = ignore pep257.check_imperative_mood = ignore original_check_return_type = pep257.check_return_type def better_check_return_type(def_docstring, context, is_script): """ Ignore private methods """ def_name = context.split()[1] if def_name.startswith("_") and not def_name.endswith("__"): original_check_return_type(def_docstring, context, is_script) pep257.check_return_type = better_check_return_type errors = [] for filename in to_lint: with open(filename) as f: source = f.read() if source: errors.extend(pep257.check_source(source, filename)) return "\n".join([str(error) for error in sorted(errors)])
def hacked_pep257(to_lint): """ Check for the presence of docstrings, but ignore some of the options """ def ignore(*args, **kwargs): pass pep257.check_blank_before_after_class = ignore pep257.check_blank_after_last_paragraph = ignore pep257.check_blank_after_summary = ignore pep257.check_ends_with_period = ignore pep257.check_one_liners = ignore pep257.check_imperative_mood = ignore original_check_return_type = pep257.check_return_type def better_check_return_type(def_docstring, context, is_script): """ Ignore private methods """ def_name = context.split()[1] if def_name.startswith('_') and not def_name.endswith('__'): original_check_return_type(def_docstring, context, is_script) pep257.check_return_type = better_check_return_type errors = [] for filename in to_lint: with open(filename) as f: source = f.read() if source: errors.extend(pep257.check_source(source, filename)) return '\n'.join([str(error) for error in sorted(errors)])
def test_ignore_scripts(): import mock def check_is_script(doc_string, context, is_script): assert is_script return None mock_check = mock.MagicMock(side_effect=check_is_script) with mock.patch('pep257.find_checks', return_value=[mock_check]): from pep257 import check_source # files that start with a shabang are ignored check_source('#! /usr/bin/env python\n\nprint "This is a script"', 'somefilename.py') # files that start with 'test_' are ignored check_source('"""Some docstring"""', 'test_filename.py') # files that start with 'test_' but inside some other directories are # ignored check_source('"""Some docstring"""', '/module/mod/mo/test_filename.py') assert len(mock_check.mock_calls) > 1