summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorent Xicluna <florent.xicluna@gmail.com>2014-01-17 04:08:35 +0100
committerFlorent Xicluna <florent.xicluna@gmail.com>2014-01-17 04:08:35 +0100
commit8c10314eccd145063a8801bbb70f8f362e8c2dcd (patch)
treed1f59843fc35cb72af1af8645155d284ba840592
parent47c51212c57387aa494eb933b5d4a2726ec237c3 (diff)
parent2bb9beb7174a7cbe7a734a480b84519d1b51f1df (diff)
downloadpyflakes-8c10314eccd145063a8801bbb70f8f362e8c2dcd.tar.gz
Merge pull request #19 from laurentb/doctest-fix
-rw-r--r--pyflakes/checker.py2
-rw-r--r--pyflakes/test/test_doctests.py19
2 files changed, 20 insertions, 1 deletions
diff --git a/pyflakes/checker.py b/pyflakes/checker.py
index 56399c8..04491f9 100644
--- a/pyflakes/checker.py
+++ b/pyflakes/checker.py
@@ -580,7 +580,7 @@ class Checker(object):
except SyntaxError:
e = sys.exc_info()[1]
position = (node_lineno + example.lineno + e.lineno,
- example.indent + 4 + e.offset)
+ example.indent + 4 + (e.offset or 0))
self.report(messages.DoctestSyntaxError, node, position)
else:
self.offset = (node_offset[0] + node_lineno + example.lineno,
diff --git a/pyflakes/test/test_doctests.py b/pyflakes/test/test_doctests.py
index b466375..d7df779 100644
--- a/pyflakes/test/test_doctests.py
+++ b/pyflakes/test/test_doctests.py
@@ -207,3 +207,22 @@ class Test(TestOther, TestImports, TestUndefinedNames):
>>> Foo
'''
""")
+
+ def test_noOffsetSyntaxErrorInDoctest(self):
+ exceptions = super(Test, self).flakes(
+ '''
+ def buildurl(base, *args, **kwargs):
+ """
+ >>> buildurl('/blah.php', ('a', '&'), ('b', '=')
+ '/blah.php?a=%26&b=%3D'
+ >>> buildurl('/blah.php', a='&', 'b'='=')
+ '/blah.php?b=%3D&a=%26'
+ """
+ pass
+ ''',
+ m.DoctestSyntaxError,
+ m.DoctestSyntaxError).messages
+ exc = exceptions[0]
+ self.assertEqual(exc.lineno, 4)
+ exc = exceptions[1]
+ self.assertEqual(exc.lineno, 6)