def test_syntax_errorNoOffset():
    """syntax_error doesn't include a caret pointing to the error if offset is passed as None."""
    err = StringIO()
    reporter = Reporter(err, err)
    reporter.flake(PythonSyntaxError('foo.py', 'a problem', 3, None, 'bad line of source', verbose=True))
    assert ("foo.py:3:0:E402::a problem\n"
            "bad line of source\n") == err.getvalue()
Example #2
0
def test_syntax_errorNoOffset():
    """syntax_error doesn't include a caret pointing to the error if offset is passed as None."""
    err = StringIO()
    reporter = Reporter(None, err)
    reporter.syntax_error('foo.py', 'a problem', 3, None, 'bad line of source')
    assert ("foo.py:3: a problem\n"
            "bad line of source\n") == err.getvalue()
def test_unexpected_error():
    """
        unexpected_error reports an error processing a source file
    """
    err = StringIO()
    reporter = Reporter(None, err)
    reporter.unexpected_error('source.py', 'error message')
    assert 'source.py: error message\n' == err.getvalue()
def test_flake():
    """
        flake reports a code warning from Frosted.
        It is exactly the str() of a frosted.messages.Message
    """
    out = StringIO()
    reporter = Reporter(out, None)
    message = UnusedImport('foo.py', Node(42), 'bar')
    reporter.flake(message)
    assert out.getvalue() == "%s\n" % (message,)
def test_multiLineSyntaxError():
    """ If there's a multi-line syntax error, then we only report the last line.

    The offset is adjusted so that it is relative to the start of the last line

    """
    err = StringIO()
    lines = ['bad line of source', 'more bad lines of source']
    reporter = Reporter(err, err)
    reporter.flake(PythonSyntaxError('foo.py', 'a problem', 3, len(lines[0]) + 7, '\n'.join(lines), verbose=True))
    assert ("foo.py:3:6:E402::a problem\n" +
            lines[-1] + "\n" +
            "      ^\n") == err.getvalue()
def test_syntax_error():
    """syntax_error reports that there was a syntax error in the source file.

    It reports to the error stream and includes the filename, line number, error message, actual line of source and a
    caret pointing to where the error is

    """
    err = StringIO()
    reporter = Reporter(err, err)
    reporter.flake(PythonSyntaxError('foo.py', 'a problem', 3, 7, 'bad line of source', verbose=True))
    assert ("foo.py:3:7:E402::a problem\n"
            "bad line of source\n"
            "       ^\n") == err.getvalue()