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_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(None, err) reporter.syntax_error('foo.py', 'a problem', 3, 7, 'bad line of source') assert ("foo.py:3:7: a problem\n" "bad line of source\n" " ^\n") == err.getvalue()
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(None, err) reporter.syntax_error('foo.py', 'a problem', 3, len(lines[0]) + 7, '\n'.join(lines)) assert ("foo.py:3:6: a problem\n" + lines[-1] + "\n" + " ^\n") == err.getvalue()