mirror of
https://github.com/python/cpython.git
synced 2025-10-10 00:43:41 +00:00
Issue #22982: Improve BOM handling when seeking to multiple positions of a writable text file.
This commit is contained in:
parent
20d31b5182
commit
85e3ee749c
4 changed files with 52 additions and 15 deletions
|
@ -2669,6 +2669,19 @@ class TextIOWrapperTest(unittest.TestCase):
|
|||
with self.open(filename, 'rb') as f:
|
||||
self.assertEqual(f.read(), 'bbbzzz'.encode(charset))
|
||||
|
||||
def test_seek_append_bom(self):
|
||||
# Same test, but first seek to the start and then to the end
|
||||
filename = support.TESTFN
|
||||
for charset in ('utf-8-sig', 'utf-16', 'utf-32'):
|
||||
with self.open(filename, 'w', encoding=charset) as f:
|
||||
f.write('aaa')
|
||||
with self.open(filename, 'a', encoding=charset) as f:
|
||||
f.seek(0)
|
||||
f.seek(0, self.SEEK_END)
|
||||
f.write('xxx')
|
||||
with self.open(filename, 'rb') as f:
|
||||
self.assertEqual(f.read(), 'aaaxxx'.encode(charset))
|
||||
|
||||
def test_errors_property(self):
|
||||
with self.open(support.TESTFN, "w") as f:
|
||||
self.assertEqual(f.errors, "strict")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue