99import subprocess
1010import tempfile
1111
12- from pyflakes .checker import PY2
1312from pyflakes .messages import UnusedImport
1413from pyflakes .reporter import Reporter
1514from pyflakes .api import (
@@ -449,7 +448,7 @@ def evaluate(source):
449448
450449 with self .makeTempFile (source ) as sourcePath :
451450 if PYPY :
452- message = 'EOF while scanning triple-quoted string literal'
451+ message = 'end of file ( EOF) while scanning triple-quoted string literal'
453452 else :
454453 message = 'invalid syntax'
455454
@@ -491,8 +490,8 @@ def test_eofSyntaxErrorWithTab(self):
491490 syntax error reflects the cause for the syntax error.
492491 """
493492 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 ^'
496495
497496 self .assertHasErrors (
498497 sourcePath ,
@@ -514,7 +513,12 @@ def foo(bar=baz, bax):
514513"""
515514 with self .makeTempFile (source ) as sourcePath :
516515 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
518522 last_line = ' ' * (column - 1 ) + '^\n '
519523 columnstr = '%d:' % column
520524 else :
@@ -537,7 +541,12 @@ def test_nonKeywordAfterKeywordSyntaxError(self):
537541"""
538542 with self .makeTempFile (source ) as sourcePath :
539543 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
541550 last_line = ' ' * (column - 1 ) + '^\n '
542551 columnstr = '%d:' % column
543552 else :
@@ -707,6 +716,12 @@ class IntegrationTests(TestCase):
707716 Tests of the pyflakes script that actually spawn the script.
708717 """
709718
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+
710725 def setUp (self ):
711726 self .tempdir = tempfile .mkdtemp ()
712727 self .tempfilepath = os .path .join (self .tempdir , 'temp' )
@@ -747,9 +762,6 @@ def runPyflakes(self, paths, stdin=None):
747762 if sys .version_info >= (3 ,):
748763 stdout = stdout .decode ('utf-8' )
749764 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 ' )
753765 return (stdout , stderr , rv )
754766
755767 def test_goodFile (self ):
@@ -770,7 +782,7 @@ def test_fileWithFlakes(self):
770782 fd .write ("import contraband\n " .encode ('ascii' ))
771783 d = self .runPyflakes ([self .tempfilepath ])
772784 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 ))
774786
775787 def test_errors_io (self ):
776788 """
@@ -780,7 +792,7 @@ def test_errors_io(self):
780792 """
781793 d = self .runPyflakes ([self .tempfilepath ])
782794 error_msg = '%s: No such file or directory%s' % (self .tempfilepath ,
783- os . linesep )
795+ self . LINESEP )
784796 self .assertEqual (d , ('' , error_msg , 1 ))
785797
786798 def test_errors_syntax (self ):
@@ -792,8 +804,8 @@ def test_errors_syntax(self):
792804 with open (self .tempfilepath , 'wb' ) as fd :
793805 fd .write ("import" .encode ('ascii' ))
794806 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 ' ' )
797809 self .assertEqual (d , ('' , error_msg , 1 ))
798810
799811 def test_readFromStdin (self ):
@@ -802,13 +814,14 @@ def test_readFromStdin(self):
802814 """
803815 d = self .runPyflakes ([], stdin = 'import contraband' )
804816 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 ))
806818
807819
808820class TestMain (IntegrationTests ):
809821 """
810822 Tests of the pyflakes main function.
811823 """
824+ LINESEP = os .linesep
812825
813826 def runPyflakes (self , paths , stdin = None ):
814827 try :
0 commit comments