8000 gh-111495: Add PyFile tests by vstinner · Pull Request #129449 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-111495: Add PyFile tests #129449

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jan 30, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix tests on Windows
  • Loading branch information
vstinner committed Jan 30, 2025
commit 1cd6e1b998fb2d1e1e8193d0cc38a46b5c9fd5a9
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
Loading
0