9
9
import subprocess
10
10
import tempfile
11
11
12
- from pyflakes .checker import PY2
13
12
from pyflakes .messages import UnusedImport
14
13
from pyflakes .reporter import Reporter
15
14
from pyflakes .api import (
@@ -449,7 +448,7 @@ def evaluate(source):
449
448
450
449
with self .makeTempFile (source ) as sourcePath :
451
450
if PYPY :
452
- message = 'EOF while scanning triple-quoted string literal'
451
+ message = 'end of file ( EOF) while scanning triple-quoted string literal'
453
452
else :
454
453
message = 'invalid syntax'
455
454
@@ -491,8 +490,8 @@ def test_eofSyntaxErrorWithTab(self):
491
490
syntax error reflects the cause for the syntax error.
492
491
"""
493
492
with self .makeTempFile ("if True:\n \t foo =" ) as sourcePath :
494
- column = 5 if PYPY else 7
495
- last_line = '\t ^' if PYPY else '\t ^'
493
+ column = 6 if PYPY else 7
494
+ last_line = '\t ^' if PYPY else '\t ^'
496
495
497
496
self .assertHasErrors (
498
497
sourcePath ,
@@ -514,7 +513,12 @@ def foo(bar=baz, bax):
514
513
"""
515
514
with self .makeTempFile (source ) as sourcePath :
516
515
if ERROR_HAS_LAST_LINE :
517
- column = 9 if sys .version_info >= (3 , 8 ) else 8
516
+ if PYPY and sys .version_info >= (3 ,):
517
+ column = 7
518
+ elif sys .version_info >= (3 , 8 ):
519
+ column = 9
520
+ else :
521
+ column = 8
518
522
last_line = ' ' * (column - 1 ) + '^\n '
519
523
columnstr = '%d:' % column
520
524
else :
@@ -537,7 +541,12 @@ def test_nonKeywordAfterKeywordSyntaxError(self):
537
541
"""
538
542
with self .makeTempFile (source ) as sourcePath :
539
543
if ERROR_HAS_LAST_LINE :
540
- column = 14 if sys .version_info >= (3 , 8 ) else 13
544
+ if PYPY and sys .version_info >= (3 ,):
545
+ column = 12
546
+ elif sys .version_info >= (3 , 8 ):
547
+ column = 14
548
+ else :
549
+ column = 13
541
550
last_line = ' ' * (column - 1 ) + '^\n '
542
551
columnstr = '%d:' % column
543
552
else :
@@ -707,6 +716,12 @@ class IntegrationTests(TestCase):
707
716
Tests of the pyflakes script that actually spawn the script.
708
717
"""
709
718
719
+ # https://bitbucket.org/pypy/pypy/issues/3069/pypy36-on-windows-incorrect-line-separator
720
+ if PYPY and sys .version_info >= (3 ,) and WIN :
721
+ LINESEP = '\n '
722
+ else :
723
+ LINESEP = os .linesep
724
+
710
725
def setUp (self ):
711
726
self .tempdir = tempfile .mkdtemp ()
712
727
self .tempfilepath = os .path .join (self .tempdir , 'temp' )
@@ -747,9 +762,6 @@ def runPyflakes(self, paths, stdin=None):
747
762
if sys .version_info >= (3 ,):
748
763
stdout = stdout .decode ('utf-8' )
749
764
stderr = stderr .decode ('utf-8' )
750
- # Workaround https://bitbucket.org/pypy/pypy/issues/2350
751
- if PYPY and PY2 and WIN :
752
- stderr = stderr .replace ('\r \r \n ' , '\r \n ' )
753
765
return (stdout , stderr , rv )
754
766
755
767
def test_goodFile (self ):
@@ -770,7 +782,7 @@ def test_fileWithFlakes(self):
770
782
fd .write ("import contraband\n " .encode ('ascii' ))
771
783
d = self .runPyflakes ([self .tempfilepath ])
772
784
expected = UnusedImport (self .tempfilepath , Node (1 ), 'contraband' )
773
- self .assertEqual (d , ("%s%s" % (expected , os . linesep ), '' , 1 ))
785
+ self .assertEqual (d , ("%s%s" % (expected , self . LINESEP ), '' , 1 ))
774
786
775
787
def test_errors_io (self ):
776
788
"""
@@ -780,7 +792,7 @@ def test_errors_io(self):
780
792
"""
781
793
d = self .runPyflakes ([self .tempfilepath ])
782
794
error_msg = '%s: No such file or directory%s' % (self .tempfilepath ,
783
- os . linesep )
795
+ self . LINESEP )
784
796
self .assertEqual (d , ('' , error_msg , 1 ))
785
797
786
798
def test_errors_syntax (self ):
@@ -792,8 +804,8 @@ def test_errors_syntax(self):
792
804
with open (self .tempfilepath , 'wb' ) as fd :
793
805
fd .write ("import" .encode ('ascii' ))
794
806
d = self .runPyflakes ([self .tempfilepath ])
795
- error_msg = '{0}:1:{2}: invalid syntax{1}import{1} {3}^{1}' .format (
796
- self .tempfilepath , os . linesep , 5 if PYPY else 7 , '' if PYPY else ' ' )
807
+ error_msg = '{0}:1:{2}: invalid syntax{1}import{1} {3}^{1}' .format (
808
+ self .tempfilepath , self . LINESEP , 6 if PYPY else 7 , '' if PYPY else ' ' )
797
809
self .assertEqual (d , ('' , error_msg , 1 ))
798
810
799
811
def test_readFromStdin (self ):
@@ -802,13 +814,14 @@ def test_readFromStdin(self):
802
814
"""
803
815
d = self .runPyflakes ([], stdin = 'import contraband' )
804
816
expected = UnusedImport ('<stdin>' , Node (1 ), 'contraband' )
805
- self .assertEqual (d , ("%s%s" % (expected , os . linesep ), '' , 1 ))
817
+ self .assertEqual (d , ("%s%s" % (expected , self . LINESEP ), '' , 1 ))
806
818
807
819
808
820
class TestMain (IntegrationTests ):
809
821
"""
810
822
Tests of the pyflakes main function.
811
823
"""
824
+ LINESEP = os .linesep
812
825
813
826
def runPyflakes (self , paths , stdin = None ):
814
827
try :
0 commit comments