Skip to content

Commit

Permalink
Fix tests on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
vstinner committed Jan 30, 2025
1 parent fdf2d50 commit 1cd6e1b
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions Lib/test/test_capi/test_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@
from test.support import import_helper, os_helper


FIRST_LINE = 'import io\n' # First line of this file
_testcapi = import_helper.import_module('_testcapi')
_testlimitedcapi = import_helper.import_module('_testlimitedcapi')
_io = import_helper.import_module('_io')
NULL = None

with open(__file__, 'rb') as fp:
FIRST_LINE = next(fp).decode()
FIRST_LINE_NORM = FIRST_LINE.rstrip() + '\n'


class CAPIFileTest(unittest.TestCase):
def test_pyfile_fromfd(self):
Expand Down Expand Up @@ -48,7 +51,7 @@ def test_pyfile_fromfd(self):
self.assertIsInstance(obj, _io.TextIOWrapper)
self.assertEqual(obj.encoding, "utf-8")
self.assertEqual(obj.errors, "replace")
self.assertEqual(obj.readline(), FIRST_LINE)
self.assertEqual(obj.readline(), FIRST_LINE_NORM)
finally:
obj.close()

Expand All @@ -60,17 +63,20 @@ def test_pyfile_getline(self):
# Test Unicode
with open(__file__, "r") as fp:
fp.seek(0)
self.assertEqual(pyfile_getline(fp, -1), FIRST_LINE.rstrip())
self.assertEqual(pyfile_getline(fp, -1),
FIRST_LINE_NORM.rstrip('\n'))
fp.seek(0)
self.assertEqual(pyfile_getline(fp, 0), FIRST_LINE)
self.assertEqual(pyfile_getline(fp, 0),
FIRST_LINE_NORM)
fp.seek(0)
self.assertEqual(pyfile_getline(fp, 6), FIRST_LINE[:6])
self.assertEqual(pyfile_getline(fp, 6),
FIRST_LINE_NORM[:6])

# Test bytes
with open(__file__, "rb") as fp:
fp.seek(0)
self.assertEqual(pyfile_getline(fp, -1),
FIRST_LINE.rstrip().encode())
FIRST_LINE.rstrip('\n').encode())
fp.seek(0)
self.assertEqual(pyfile_getline(fp, 0), FIRST_LINE.encode())
fp.seek(0)
Expand Down

0 comments on commit 1cd6e1b

Please sign in to comment.