summaryrefslogtreecommitdiff
path: root/pyflakes/test/test_script.py
diff options
context:
space:
mode:
authorJonathan Lange <jml@canonical.com>2012-07-06 18:42:25 +0100
committerJonathan Lange <jml@canonical.com>2012-07-06 18:42:25 +0100
commit52ef0bf4dec38ddbd04a13422eaa6b71cc25857c (patch)
tree0ee40e1cbe680033821233b7ffaa5a310556d2c4 /pyflakes/test/test_script.py
parent3877dd22c923d65beb1057f398dbb68d5666da71 (diff)
downloadpyflakes-52ef0bf4dec38ddbd04a13422eaa6b71cc25857c.tar.gz
Handle multiple lines in the reporter.
Restore the multi-line test to chheck output, just in case.
Diffstat (limited to 'pyflakes/test/test_script.py')
-rw-r--r--pyflakes/test/test_script.py38
1 files changed, 30 insertions, 8 deletions
diff --git a/pyflakes/test/test_script.py b/pyflakes/test/test_script.py
index 7f8041c..d646f22 100644
--- a/pyflakes/test/test_script.py
+++ b/pyflakes/test/test_script.py
@@ -90,6 +90,27 @@ class TestReporter(TestCase):
err.getvalue())
+ def test_multiLineSyntaxError(self):
+ """
+ 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)
+ reporter.syntaxError('foo.py', 'a problem', 3, len(lines[0]) + 5,
+ '\n'.join(lines))
+ self.assertEquals(
+ ("foo.py:3: a problem\n" +
+ lines[-1] + "\n" +
+ " ^\n"),
+ err.getvalue())
+
+
def test_ioError(self):
"""
C{ioError} reports an error reading a source file. It only includes
@@ -130,8 +151,8 @@ class CheckTests(TestCase):
"""
err = StringIO()
count = withStderrTo(err, checkPath, path)
- self.assertEquals(count, len(errorList))
- self.assertEquals(err.getvalue(), ''.join(errorList))
+ self.assertEquals(
+ (count, err.getvalue()), (len(errorList), ''.join(errorList)))
def getErrors(self, path):
@@ -186,12 +207,13 @@ def baz():
self.assertTrue(exc.text.count('\n') > 1)
sourcePath = self.makeTempFile(source)
- count, errors = self.getErrors(sourcePath)
- self.assertEquals(count, 1)
- self.assertEquals(
- errors,
- [('syntaxError', sourcePath, 'invalid syntax', 8, 10,
- " '''quux'''")])
+ self.assertHasErrors(
+ sourcePath, ["""\
+%s:8: invalid syntax
+ '''quux'''
+ ^
+"""
+ % (sourcePath,)])
def test_eofSyntaxError(self):