66from test .support import import_helper , os_helper
77
88
9- FIRST_LINE = 'import io\n ' # First line of this file
109_testcapi = import_helper .import_module ('_testcapi' )
1110_testlimitedcapi = import_helper .import_module ('_testlimitedcapi' )
1211_io = import_helper .import_module ('_io' )
1312NULL = None
1413
14+ with open (__file__ , 'rb' ) as fp :
15+ FIRST_LINE = next (fp ).decode ()
16+ FIRST_LINE_NORM = FIRST_LINE .rstrip () + '\n '
17+
1518
1619class CAPIFileTest (unittest .TestCase ):
1720 def test_pyfile_fromfd (self ):
@@ -48,7 +51,7 @@ def test_pyfile_fromfd(self):
4851 self .assertIsInstance (obj , _io .TextIOWrapper )
4952 self .assertEqual (obj .encoding , "utf-8" )
5053 self .assertEqual (obj .errors , "replace" )
51- self .assertEqual (obj .readline (), FIRST_LINE )
54+ self .assertEqual (obj .readline (), FIRST_LINE_NORM )
5255 finally :
5356 obj .close ()
5457
@@ -60,17 +63,20 @@ def test_pyfile_getline(self):
6063 # Test Unicode
6164 with open (__file__ , "r" ) as fp :
6265 fp .seek (0 )
63- self .assertEqual (pyfile_getline (fp , - 1 ), FIRST_LINE .rstrip ())
66+ self .assertEqual (pyfile_getline (fp , - 1 ),
67+ FIRST_LINE_NORM .rstrip ('\n ' ))
6468 fp .seek (0 )
65- self .assertEqual (pyfile_getline (fp , 0 ), FIRST_LINE )
69+ self .assertEqual (pyfile_getline (fp , 0 ),
70+ FIRST_LINE_NORM )
6671 fp .seek (0 )
67- self .assertEqual (pyfile_getline (fp , 6 ), FIRST_LINE [:6 ])
72+ self .assertEqual (pyfile_getline (fp , 6 ),
73+ FIRST_LINE_NORM [:6 ])
6874
6975 # Test bytes
7076 with open (__file__ , "rb" ) as fp :
7177 fp .seek (0 )
7278 self .assertEqual (pyfile_getline (fp , - 1 ),
73- FIRST_LINE .rstrip ().encode ())
79+ FIRST_LINE .rstrip (' \n ' ).encode ())
7480 fp .seek (0 )
7581 self .assertEqual (pyfile_getline (fp , 0 ), FIRST_LINE .encode ())
7682 fp .seek (0 )
0 commit comments