Exemplo n.º 1
0
def main():
    # import re
    # lineno = re.compile(r'^(\d+)\:')
    results = {'E': 0, 'W': 0}
    output, warnings = [], []

    filepath = os.environ['TM_FILEPATH']

    warnings += check(sys.stdin.read(), filepath)
    
    for warning in warnings:
        # line = lineno.sub('' % dict(
        #     filepath=warning.filename,
        #     lineno=warning.lineno,
        #     col=warning.col,
        # ), str(warning))
        output.append('<li><a href="txmt://open?url=file://%(filepath)s&line=%(lineno)s&column=%(col)s">%(filename)s:%(lineno)s</a><pre><code>%(message)s</code></pre></li>' % dict(
            col=warning.col,
            lineno=warning.lineno,
            filepath=warning.filename,
            filename=os.path.basename(warning.filename),
            message=warning.message % warning.message_args,
        ))
        results[warning.level] += 1
  
    output = "\n\n".join(output)
    
    print HTML % dict(
        output=output,
        results='%d error(s), %d warning(s)' % (results['E'], results['W']),
    )
Exemplo n.º 2
0
def main():
    # import re
    # lineno = re.compile(r'^(\d+)\:')
    results = {'E': 0, 'W': 0}
    output, warnings = [], []

    filepath = os.environ['TM_FILEPATH']

    warnings += check(sys.stdin.read(), filepath)

    for warning in warnings:
        # line = lineno.sub('' % dict(
        #     filepath=warning.filename,
        #     lineno=warning.lineno,
        #     col=warning.col,
        # ), str(warning))
        output.append(
            '<li><a href="txmt://open?url=file://%(filepath)s&line=%(lineno)s&column=%(col)s">%(filename)s:%(lineno)s</a><pre><code>%(message)s</code></pre></li>'
            % dict(
                col=warning.col,
                lineno=warning.lineno,
                filepath=warning.filename,
                filename=os.path.basename(warning.filename),
                message=warning.message % warning.message_args,
            ))
        results[warning.level] += 1

    output = "\n\n".join(output)

    print HTML % dict(
        output=output,
        results='%d error(s), %d warning(s)' % (results['E'], results['W']),
    )
 def test_missingTrailingNewline(self):
     """
     Source which doesn't end with a newline shouldn't cause any
     exception to be raised nor an error indicator to be returned by
     L{check}.
     """
     if sys.version < "2.7":
         return  # XXX syntax error on older python
     content = "def foo():\n\tpass\n\t"
     self.assertFalse(check(content, "dummy.py"))
    def test_misencodedFile(self):
        """
        If a source file contains bytes which cannot be decoded, this is
        reported on stderr.
        """
        source = u"""\
# coding: ascii
x = "\N{SNOWMAN}"
""".encode(
            "utf-8"
        )
        err = StringIO()
        count = check(source, "dummy.py", stderr=err)
        self.assertEquals(count, 1)
        self.assertEquals(err.getvalue(), "dummy.py: problem decoding source\n")
    def test_eofSyntaxError(self):
        """
        The error reported for source files which end prematurely causing a
        syntax error reflects the cause for the syntax error.
        """
        source = "def foo("
        err = StringIO()
        count = check(source, "dummy.py", stderr=err)
        self.assertEqual(count, 1)
        self.assertEqual(
            err.getvalue(),
            """\
dummy.py:1: unexpected EOF while parsing
def foo(
         ^
""",
        )
    def test_nonKeywordAfterKeywordSyntaxError(self):
        """
        Source which has a non-keyword argument after a keyword argument should
        include the line number of the syntax error.  However these exceptions
        do not include an offset.
        """
        source = """\
foo(bar=baz, bax)
"""
        err = StringIO()
        count = check(source, "dummy.py", stderr=err)
        self.assertEqual(count, 1)
        self.assertEqual(
            err.getvalue(),
            """\
dummy.py:1: non-keyword arg after keyword arg
foo(bar=baz, bax)
""",
        )
    def test_nonDefaultFollowsDefaultSyntaxError(self):
        """
        Source which has a non-default argument following a default argument
        should include the line number of the syntax error.  However these
        exceptions do not include an offset.
        """
        source = """\
def foo(bar=baz, bax):
    pass
"""
        err = StringIO()
        count = check(source, "dummy.py", stderr=err)
        self.assertEqual(count, 1)
        self.assertEqual(
            err.getvalue(),
            """\
dummy.py:1: non-default argument follows default argument
def foo(bar=baz, bax):
""",
        )
Exemplo n.º 8
0
def main():
    content = open(sys.argv[-1], 'r').read()

    warnings = check(content, '')
    for warning in warnings:
        print warning
Exemplo n.º 9
0
def main():
    content = open(sys.argv[-1], 'r').read()
    check(content, '')
Exemplo n.º 10
0
def main():
    content = open(sys.argv[-1], 'r').read()

    warnings = check(content, '')
    for warning in warnings:
        print warning
def baz():
    '''quux'''
"""

        # Sanity check - SyntaxError.text should be multiple lines, if it
        # isn't, something this test was unprepared for has happened.
        try:
            compile(source, "dummy.py", "exec")
        except SyntaxError, exc:
            self.assertTrue(exc.text.count("\n") > 1)
        else:
            self.fail("uhm where is our syntax error")

        err = StringIO()
        count = check(source, "dummy.py", stderr=err)
        self.assertEqual(count, 1)

        self.assertEqual(
            err.getvalue(),
            """\
dummy.py:8: invalid syntax
    '''quux'''
           ^
""",
        )

    def test_eofSyntaxError(self):
        """
        The error reported for source files which end prematurely causing a
        syntax error reflects the cause for the syntax error.
Exemplo n.º 12
0
 def check(self):
     bounds = self.doc.get_bounds()
     text = self.doc.get_text(*bounds)
     with redirect_out() as out:
         pyflakes.check(text, 'line')
     return out.getvalue()