Ejemplo n.º 1
0
def test_check_blank_after_summary():
    from pep257 import check_blank_after_summary as check
    s1 = '''"""Blank line missing after one-line summary.
    ....................
    """'''
    s2 = '''"""Blank line missing after one-line summary.

    """'''
    assert check(s1, None, None)
    assert not check(s2, None, None)
Ejemplo n.º 2
0
def test_check_blank_after_last_paragraph():
    from pep257 import check_blank_after_last_paragraph as check
    s1 = '''"""Multiline docstring should end with 1 blank line.

    Blank here:

    """'''
    s2 = '''"""Multiline docstring should end with 1 blank line.

    No blank here.
    """'''
    assert not check(s1, None, None)
    assert check(s2, None, None)
Ejemplo n.º 3
0
    def runtest(self):
        """Run the pep257 checker on collected file."""
        # Get a list of all pep257.Errors
        temp = list(pep257.check([str(self.fspath)], ignore=self.ignorelist))

        if temp:
            raise PEP257Error(temp)
Ejemplo n.º 4
0
def test_ignore_list():
    function_to_check = """def function_with_bad_docstring(foo):
    \"\"\" does spacing without 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'))
    mock_open = mock.mock_open(read_data=function_to_check)
    with mock.patch('pep257.open', mock_open, create=True):
        errors = tuple(pep257.check(['filepath']))
        error_codes = set(error.code for error in errors)
        assert error_codes == expected_error_codes

        errors = tuple(pep257.check(['filepath'], ignore=['D100', 'D202']))
        error_codes = set(error.code for error in errors)
        assert error_codes == expected_error_codes - set(('D100', 'D202'))
Ejemplo n.º 5
0
 def test_pep257(self):
     """Test pep257 conformance."""
     # need to coerce into list to get the length.
     # Other option would be to write a generator has next function or
     # something
     result = list(pep257.check(self.files))
     self.assertEqual(len(result), 0,
                      "Found pep257 errors (and warnings).\n{}".format('\n'.join([str(err) for err in result])))
Ejemplo n.º 6
0
def test_pep257():
    """Run domain-specific tests from test.py file."""
    import test
    results = list(check(['test.py']))
    assert set(map(type, results)) == set([Error]), results
    results = set([(e.definition.name, e.message) for e in results])
    print('\nextra: %r' % (results - test.expected))
    print('\nmissing: %r' % (test.expected - results))
    assert test.expected == results
Ejemplo n.º 7
0
def run():
    """Run the functions above and check errors agains expected errors."""
    import pep257
    results = list(pep257.check([__file__]))
    assert set(map(type, results)) == set([pep257.Error]), results
    results = set([(e.definition.name, e.message) for e in results])
    print('\n  extra: %r' % (results - expected))
    print('\nmissing: %r' % (expected - results))
    assert expected == results
Ejemplo n.º 8
0
def test_pep257():
    """Run domain-specific tests from test.py file."""
    import test
    results = list(check(['test.py']))
    assert set(map(type, results)) == set([Error]), results
    results = set([(e.definition.name, e.message) for e in results])
    print('\nextra: %r' % (results - test.expected))
    print('\nmissing: %r' % (test.expected - results))
    assert test.expected == results
Ejemplo n.º 9
0
 def test_pep257(self):
     """Test pep257 conformance."""
     # need to coerce into list to get the length.
     # Other option would be to write a generator has next function or
     # something
     result = list(pep257.check(self.files))
     self.assertEqual(
         len(result), 0, "Found pep257 errors (and warnings).\n{}".format(
             '\n'.join([str(err) for err in result])))
Ejemplo n.º 10
0
def run():
    """Run the functions above and check errors agains expected errors."""
    import pep257
    results = list(pep257.check([__file__]))
    assert set(map(type, results)) == set([pep257.Error]), results
    results = set([(e.definition.name, e.message) for e in results])
    print('\n  extra: %r' % (results - expected))
    print('\nmissing: %r' % (expected - results))
    assert expected == results
Ejemplo n.º 11
0
def test_check_indent():
    from pep257 import check_indent as check
    context = '''def foo():
    """Docstring.

    Properly indented.

    """
    pass'''
    assert not check('"""%s"""' % context.split('"""')[1], context, None)
    context = '''def foo():
    """Docstring.

Not Properly indented.

    """
    pass'''
    assert check('"""%s"""' % context.split('"""')[1], context, None)
Ejemplo n.º 12
0
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'))
    mock_open = mock.mock_open(read_data=function_to_check)
    with mock.patch('pep257.tokenize_open', mock_open, create=True):
        errors = tuple(pep257.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('pep257.tokenize_open', mock_open, create=True):
        errors = tuple(pep257.check(['filepath'], ignore=['D100', 'D202']))
        error_codes = set(error.code for error in errors)
        assert error_codes == expected_error_codes - set(('D100', 'D202'))
Ejemplo n.º 13
0
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"))
    mock_open = mock.mock_open(read_data=function_to_check)
    with mock.patch("pep257.tokenize_open", mock_open, create=True):
        errors = tuple(pep257.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("pep257.tokenize_open", mock_open, create=True):
        errors = tuple(pep257.check(["filepath"], ignore=["D100", "D202"]))
        error_codes = set(error.code for error in errors)
        assert error_codes == expected_error_codes - set(("D100", "D202"))
Ejemplo n.º 14
0
def test_check_backslashes():
    from pep257 import check_backslashes as check
    assert check('"""backslash\\here""""', None, None)
    assert not check('r"""backslash\\here""""', None, None)
Ejemplo n.º 15
0
 def run(self):
     """Use directly check() api from pep257."""
     for error in pep257.check([self.filename]):
         # Ignore AllError, Environment error.
         if isinstance(error, pep257.Error):
             yield (error.line, 0, error.message, type(self))
Ejemplo n.º 16
0
 def test_pep257(self):
     python_filepaths = self._get_python_filepaths(PEP257_ROOTS)
     result = list(pep257.check(python_filepaths))
     self.assertEqual(len(result), 0, "There are issues!\n" + '\n'.join(map(str, result)))
Ejemplo n.º 17
0
 def test_pep257(self):
     python_filepaths = self._get_python_filepaths(PEP257_ROOTS)
     result = list(pep257.check(python_filepaths))
     self.assertEqual(len(result), 0,
                      "There are issues!\n" + '\n'.join(map(str, result)))
Ejemplo n.º 18
0
def test_pep257_conformance():
    errors = list(pep257.check(['pep257.py', 'test_pep257.py']))
    print(errors)
    assert errors == []
Ejemplo n.º 19
0
def test_check_triple_double_quotes():
    from pep257 import check_triple_double_quotes as check
    assert check("'''Not using triple douple quotes'''", None, None)
    assert not check('"""Using triple double quotes"""', None, None)
    assert not check('r"""Using raw triple double quotes"""', None, None)
    assert not check('u"""Using unicode triple double quotes"""', None, None)
Ejemplo n.º 20
0
def check_pep257(files=None):
    import pep257
    for error in pep257.check(files or [__file__]):
        print error
Ejemplo n.º 21
0
 def runtest(self):
     errors = [str(error) for error in pep257.check([str(self.fspath)])]
     if errors:
         raise PEP257Error("\n".join(errors))
Ejemplo n.º 22
0
def test_check_unicode_docstring():
    from pep257 import check_unicode_docstring as check
    assert not check('"""No Unicode here."""', None, None)
    assert not check('u"""Здесь Юникод: øπΩ≈ç√∫˜µ≤"""', None, None)
    assert check('"""Здесь Юникод: øπΩ≈ç√∫˜µ≤"""', None, None)
Ejemplo n.º 23
0
def test_pep257():
    filenames = glob.glob('./economicpy/*.py')
    result = pep257.check(filenames, ['D100'])
    for r in result:
        print(r)
Ejemplo n.º 24
0
def test_check_ends_with_period():
    from pep257 import check_ends_with_period as check
    assert check('"""Should end with a period"""', None, None)
    assert not check('"""Should end with a period."""', None, None)
Ejemplo n.º 25
0
    def check_docstr_wrap(self, ignore=()):
        """Return pep257 instance of report of module."""
        report = pep257.check([self.current_file, ], ignore)

        return report
Ejemplo n.º 26
0
 def run(self):
     """Use directly check() api from pep257."""
     for error in pep257.check([self.filename]):
         # Ignore AllError, Environment error.
         if isinstance(error, pep257.Error):
             yield (error.line, 0, error.message, type(self))
Ejemplo n.º 27
0
def test_pep257_conformance():
    errors = list(pep257.check(['pep257.py', 'test_pep257.py']))
    print(errors)
    assert errors == []
Ejemplo n.º 28
0
 def run_pep257(self):
     """Run and return output from pep257 tool."""
     return pep257.check([self['filename']])
Ejemplo n.º 29
0
def test_pep257_pytest():
    python_filepaths = get_python_filepaths(PEP257_ROOTS)
    result = list(pep257.check(python_filepaths))
    assert len(result) == 0, "There are issues!\n" + '\n'.join(map(
        str, result))
Ejemplo n.º 30
0
def test_pep257_conformance():
    errors = list(pep257.check(["pep257.py", "test_pep257.py"]))
    print(errors)
    assert errors == []