8
8
import subprocess
9
9
import tempfile
10
10
11
+ from pyflakes .checker import PY2
11
12
from pyflakes .messages import UnusedImport
12
13
from pyflakes .reporter import Reporter
13
14
from pyflakes .api import (
30
31
except AttributeError :
31
32
PYPY = False
32
33
34
+ try :
35
+ WindowsError
36
+ WIN = True
37
+ except NameError :
38
+ WIN = False
39
+
33
40
ERROR_HAS_COL_NUM = ERROR_HAS_LAST_LINE = sys .version_info >= (3 , 2 ) or PYPY
34
41
35
42
@@ -661,6 +668,9 @@ def runPyflakes(self, paths, stdin=None):
661
668
if sys .version_info >= (3 ,):
662
669
stdout = stdout .decode ('utf-8' )
663
670
stderr = stderr .decode ('utf-8' )
671
+ # Workaround https://bitbucket.org/pypy/pypy/issues/2350
672
+ if PYPY and PY2 and WIN :
673
+ stderr = stderr .replace ('\r \r \n ' , '\r \n ' )
664
674
return (stdout , stderr , rv )
665
675
666
676
def test_goodFile (self ):
@@ -685,7 +695,7 @@ def test_fileWithFlakes(self):
685
695
expected = UnusedImport (self .tempfilepath , Node (1 ), 'contraband' )
686
696
self .assertEqual (d , ("%s%s" % (expected , os .linesep ), '' , 1 ))
687
697
688
- def test_errors (self ):
698
+ def test_errors_io (self ):
689
699
"""
690
700
When pyflakes finds errors with the files it's given, (if they don't
691
701
exist, say), then the return code is non-zero and the errors are
@@ -696,6 +706,20 @@ def test_errors(self):
696
706
os .linesep )
697
707
self .assertEqual (d , ('' , error_msg , 1 ))
698
708
709
+ def test_errors_syntax (self ):
710
+ """
711
+ When pyflakes finds errors with the files it's given, (if they don't
712
+ exist, say), then the return code is non-zero and the errors are
713
+ printed to stderr.
714
+ """
715
+ fd = open (self .tempfilepath , 'wb' )
716
+ fd .write ("import" .encode ('ascii' ))
717
+ fd .close ()
718
+ d = self .runPyflakes ([self .tempfilepath ])
719
+ error_msg = '{0}:1:{2}: invalid syntax{1}import{1} {3}^{1}' .format (
720
+ self .tempfilepath , os .linesep , 5 if PYPY else 7 , '' if PYPY else ' ' )
721
+ self .assertEqual (d , ('' , error_msg , True ))
722
+
699
723
def test_readFromStdin (self ):
700
724
"""
701
725
If no arguments are passed to C{pyflakes} then it reads from stdin.
0 commit comments