python类Checker()的实例源码

test_coding_standards.py 文件源码 项目:dati-ckan-docker 作者: italia 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def find_pep8_errors(cls, filename=None, lines=None):
        try:
            sys.stdout = cStringIO.StringIO()
            config = {}

            # Ignore long lines on test files, as the test names can get long
            # when following our test naming standards.
            if cls._is_test(filename):
                config['ignore'] = ['E501']

            checker = pep8.Checker(filename=filename, lines=lines,
                                   **config)
            checker.check_all()
            output = sys.stdout.getvalue()
        finally:
            sys.stdout = sys.__stdout__

        errors = []
        for line in output.split('\n'):
            parts = line.split(' ', 2)
            if len(parts) == 3:
                location, error, desc = parts
                line_no = location.split(':')[1]
                errors.append('%s ln:%s %s' % (error, line_no, desc))
        return errors
w9_wordplayer_tester.py 文件源码 项目:EC602 作者: gottben 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def test_style(self):
        if testing=='py':
            a = pep8.Checker(sourcecode)
            a.check_all()
            self.assertEqual(a.report.total_errors,0)
        else:
            T = subprocess.run(['cpplint',sourcecode],stdout=subprocess.PIPE, stderr=subprocess.PIPE)
            if T.returncode:
                print()
                print(T.stderr.decode())
            self.assertEqual(T.returncode,0)

        if grading:
            grade = 1.0
            print('your score', grade,end=" ")
            Grades.append(grade)
test_hacking.py 文件源码 项目:mos-horizon 作者: Mirantis 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def _run_check(self, code, checker, filename=None):
        pep8.register_check(checker)

        lines = textwrap.dedent(code).strip().splitlines(True)

        checker = pep8.Checker(filename=filename, lines=lines)
        checker.check_all()
        checker.report._deferred_print.sort()
        return checker.report._deferred_print
test_hacking.py 文件源码 项目:zun 作者: openstack 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def _run_check(self, code, checker, filename=None):
        pep8.register_check(checker)

        lines = textwrap.dedent(code).strip().splitlines(True)

        checker = pep8.Checker(filename=filename, lines=lines)
        checker.check_all()
        checker.report._deferred_print.sort()
        return checker.report._deferred_print
autopep8.py 文件源码 项目:specto 作者: mrknow 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def _execute_pep8(pep8_options, source):
    """Execute pep8 via python method calls."""
    class QuietReport(pep8.BaseReport):

        """Version of checker that does not print."""

        def __init__(self, options):
            super(QuietReport, self).__init__(options)
            self.__full_error_results = []

        def error(self, line_number, offset, text, _):
            """Collect errors."""
            code = super(QuietReport, self).error(line_number, offset, text, _)
            if code:
                self.__full_error_results.append(
                    {'id': code,
                     'line': line_number,
                     'column': offset + 1,
                     'info': text})

        def full_error_results(self):
            """Return error results in detail.

            Results are in the form of a list of dictionaries. Each
            dictionary contains 'id', 'line', 'column', and 'info'.

            """
            return self.__full_error_results

    checker = pep8.Checker('', lines=source,
                           reporter=QuietReport, **pep8_options)
    checker.check_all()
    return checker.report.full_error_results()
check.py 文件源码 项目:mWorkerService 作者: smices 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def check_pep8(srcdir):
    print(">>> Running pep8...")
    clean = True
    pep8.process_options([''])
    for pyfile in findpy(srcdir):
        if pep8.Checker(pyfile).check_all() != 0:
            clean = False
    return clean
analyze.py 文件源码 项目:blackmamba 作者: zrzka 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def _pep8_annotations(text, ignore=None, max_line_length=None):
    import pep8

    class _Pep8AnnotationReport(pep8.BaseReport):
        def __init__(self, options):
            super().__init__(options)
            self.annotations = []

        def error(self, line_number, offset, text, check):
            # If super doesn't return code, this one is ignored
            if not super().error(line_number, offset, text, check):
                return

            annotation = _AnalyzerAnnotation(self.line_offset + line_number, text, _Source.pep8, Style.warning)
            self.annotations.append(annotation)

    # pep8 requires you to include \n at the end of lines
    lines = text.splitlines(True)

    style_guide = pep8.StyleGuide(reporter=_Pep8AnnotationReport, )
    options = style_guide.options

    if ignore:
        options.ignore = tuple(ignore)
    else:
        options.ignore = tuple()

    if max_line_length:
        options.max_line_length = max_line_length

    checker = pep8.Checker(None, lines, options, None)
    checker.check_all()

    return checker.report.annotations


#
# pyflakes
#
test_hacking.py 文件源码 项目:masakari 作者: openstack 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def _run_check(self, code, checker, filename=None):
        pep8.register_check(checker)

        lines = textwrap.dedent(code).strip().splitlines(True)

        checker = pep8.Checker(filename=filename, lines=lines)
        checker.check_all()
        checker.report._deferred_print.sort()
        return checker.report._deferred_print
autopep8.py 文件源码 项目:wuye.vim 作者: zhaoyingnan911 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def _execute_pep8(pep8_options, source):
    """Execute pep8 via python method calls."""
    class QuietReport(pep8.BaseReport):

        """Version of checker that does not print."""

        def __init__(self, options):
            super(QuietReport, self).__init__(options)
            self.__full_error_results = []

        def error(self, line_number, offset, text, check):
            """Collect errors."""
            code = super(QuietReport, self).error(line_number,
                                                  offset,
                                                  text,
                                                  check)
            if code:
                self.__full_error_results.append(
                    {'id': code,
                     'line': line_number,
                     'column': offset + 1,
                     'info': text})

        def full_error_results(self):
            """Return error results in detail.

            Results are in the form of a list of dictionaries. Each
            dictionary contains 'id', 'line', 'column', and 'info'.

            """
            return self.__full_error_results

    checker = pep8.Checker('', lines=source,
                           reporter=QuietReport, **pep8_options)
    checker.check_all()
    return checker.report.full_error_results()
test_hacking.py 文件源码 项目:Trusted-Platform-Module-nova 作者: BU-NU-CLOUD-SP16 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def _run_check(self, code, checker, filename=None):
        pep8.register_check(checker)

        lines = textwrap.dedent(code).strip().splitlines(True)

        checker = pep8.Checker(filename=filename, lines=lines)
        checker.check_all()
        checker.report._deferred_print.sort()
        return checker.report._deferred_print


问题


面经


文章

微信
公众号

扫码关注公众号