~divmod-dev/divmod.org/compare-simpleordering-2839-2

« back to all changes in this revision

Viewing changes to Pyflakes/pyflakes/test/test_script.py

  • Committer: glyph
  • Date: 2009-03-27 21:38:31 UTC
  • Revision ID: svn-v4:866e43f7-fbfc-0310-8f2a-ec88d1da2979:trunk:17231
Provide line numbers via compilation when pyflakes gets `SyntaxError`s from parsing which do not include line numbers.

Author: dreid

Reviewer: glyph

Fixes #2832

More specifically, this fixes the bug where pyflakes/flymake integration would crash when the user typed a keyword argument before the argument list.

Show diffs side-by-side

added added

removed removed

Lines of Context:
106
106
         ^
107
107
""" % (sourcePath.path,))
108
108
 
 
109
 
 
110
    def test_nonDefaultFollowsDefaultSyntaxError(self):
 
111
        """
 
112
        Source which has a non-default argument following a default argument
 
113
        should include the line number of the syntax error.  However these
 
114
        exceptions do not include an offset.
 
115
        """
 
116
 
 
117
        source = """\
 
118
def foo(bar=baz, bax):
 
119
    pass
 
120
"""
 
121
        sourcePath = FilePath(self.mktemp())
 
122
        sourcePath.setContent(source)
 
123
        err = StringIO()
 
124
        count = withStderrTo(err, lambda: checkPath(sourcePath.path))
 
125
        self.assertEqual(count, 1)
 
126
        self.assertEqual(
 
127
            err.getvalue(),
 
128
            """\
 
129
%s:1: non-default argument follows default argument
 
130
def foo(bar=baz, bax):
 
131
""" % (sourcePath.path,))
 
132
 
 
133
 
 
134
    def test_nonKeywordAfterKeywordSyntaxError(self):
 
135
        """
 
136
        Source which has a non-keyword argument after a keyword argument should
 
137
        include the line number of the syntax error.  However these exceptions
 
138
        do not include an offset.
 
139
        """
 
140
 
 
141
        source = """\
 
142
foo(bar=baz, bax)
 
143
"""
 
144
        sourcePath = FilePath(self.mktemp())
 
145
        sourcePath.setContent(source)
 
146
        err = StringIO()
 
147
        count = withStderrTo(err, lambda: checkPath(sourcePath.path))
 
148
        self.assertEqual(count, 1)
 
149
        self.assertEqual(
 
150
            err.getvalue(),
 
151
            """\
 
152
%s:1: non-keyword arg after keyword arg
 
153
foo(bar=baz, bax)
 
154
""" % (sourcePath.path,))