コード例 #1
0
def is_inline_ignored(style_guide, checker, result):
    code, lineno, colno, text, line = result
    error = Violation(code, checker.display_name,
                      lineno, (colno or 0) + 1, text, line)

    if hasattr(error, 'is_inline_ignored'):
        return error.is_inline_ignored(style_guide.options.disable_noqa)

    # flake8 <3.4.0
    return style_guide.is_inline_ignored(error)
コード例 #2
0
def test_parse_file_one_error():
    target_path = os.path.join(tempfile.gettempdir(), str(uuid4()))
    os.makedirs(target_path)

    cwd = os.getcwd()
    os.chdir(target_path)
    try:
        rp = ReportSVGBadge(Values({'output_file': None, 'image': '123.svg'}))

        with open('lala.py', 'w') as f:
            f.write('print(123)\n')
            f.write('print(123)\n')

        with open('lulu.py', 'w') as f:
            f.write('print(123)\n')
            f.write('print(123)\n')
            f.write('print(123)\n')
            f.write('print(123)\n')

        rp.beginning('lala.py')
        rp.finished('lala.py')

        rp.beginning('lulu.py')
        rp.handle(Violation('F101', 'lulu.py', 123, 123, 123, 123))
        rp.finished('lulu.py')

        rp.stop()

        with open("123.svg") as f:
            el = xmltodict.parse(f.read())

        assert el['svg']['g'][1]['text'][3]['#text'] == '67%'
    finally:
        os.chdir(cwd)
        rmtree(target_path)
コード例 #3
0
    def setUp(self):
        self.options = unittest.mock.Mock(["output_file", "tee"])
        self.options.output_file = tempfile.mktemp(suffix=".json", dir=".")
        self.options.tee = False

        self.formatter = GitlabCodeClimateFormatter(self.options)
        self.error1 = Violation(
            code="E302",
            filename="examples/hello-world.py",
            line_number=23,
            column_number=None,
            text="expected 2 blank lines, found 1",
            physical_line=None,
        )

        self.error2 = Violation(
            code="X111",  # unknown
            filename="examples/unknown.py",
            line_number=99,
            column_number=None,
            text="Some extension produced this.",
            physical_line=None,
        )

        self.logging_error = Violation(
            code="G001",  # This is coming from flake8-logging-format
            filename="examples/logging-format.py",
            line_number=4,
            column_number=None,
            text="Logging statement uses string.format()",
            physical_line=None,
        )

        self.complexity_error = Violation(
            code="C901",  # This is coming from flake8-logging-format
            filename="examples/complex-code.py",
            line_number=42,
            column_number=None,
            text="Something is too complex",
            physical_line=None,
        )
コード例 #4
0
def violation_from_flake8_line(l):
    """
    Given a line in "default format, parse out a Violation.

        examples/unused-module.py:5:1: F401 'sys' imported but unused

    """
    match = flake8_fmt_re.match(l.strip())
    if match is None:
        return None

    filename, line_number, column_number, code, text = match.groups()
    return Violation(
        code=code,
        filename=filename,
        line_number=int(line_number),
        column_number=int(column_number),
        text=text,
        physical_line=None
    )
コード例 #5
0
def test_handle():
    """Verify that a formatter will call format from handle."""
    formatter = CheckstylePlugin(options(show_source=False))
    error = Violation(
        code='A001',
        filename='example.py',
        line_number=1,
        column_number=1,
        text='Fake error',
        physical_line='a = 1',
    )

    formatter.handle(error)
    formatter.finished('example.py')
    io = StringIO()
    sys.stdout = io
    formatter.stop()
    sys.stdout = sys.__stdout__
    assert io.getvalue(
    ) == '<?xml version=\'1.0\' encoding=\'utf-8\'?>\n<checkstyle><file name="example.py"><error column="1" line="1" message="A001 Fake error" severity="info" source="undefined code" /></file></checkstyle>\n'
コード例 #6
0
def violation_from_pylint_line(l):
    """
    Given a line in "pylint" format, parse out a Violation.

    >>> l = 'tourmap/json.py:23: [E302] expected 2 blank lines, found 1'
    >>> v = violation_from_pylint_line(l)
    >>> v.code, v.filename, v.line_number, v.text
    ('E302', 'tourmap/json.py', 23, 'expected 2 blank lines, found 1')
    """
    match = pylint_fmt_re.match(l.strip())
    if match is None:
        return None

    filename, line_number, code, text = match.groups()
    return Violation(
        code=code,
        filename=filename,
        line_number=int(line_number),
        column_number=None,
        text=text,
        physical_line=None
    )
コード例 #7
0
 def is_in(self, diff):
     return Violation.is_in(self, diff)
コード例 #8
0
 def is_inline_ignored(self, disable_noqa):
     return Violation.is_inline_ignored(self, disable_noqa)
コード例 #9
0
ファイル: _violation.py プロジェクト: ffix/flakehell-py27
 def is_in(self, diff):
     values = self._asdict()
     del (values['plugin'])
     return Violation(**values).is_in(diff)
コード例 #10
0
ファイル: _violation.py プロジェクト: ffix/flakehell-py27
 def is_inline_ignored(self, disable_noqa):
     values = self._asdict()
     del (values['plugin'])
     return Violation(**values).is_inline_ignored(disable_noqa)