8000 gh-134706: Return bytes written from codecs.Stream(Reader)Writer.write() by srittau · Pull Request #134708 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-134706: Return bytes written from codecs.Stream(Reader)Writer.write() #134708

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

Closed
wants to merge 5 commits into from
Closed
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
8000
Diff view
Diff view
Prev Previous commit
Next Next commit
Add tests
  • Loading branch information
srittau committed May 27, 2025
commit 1e620c97e5ab96def5511c187315b15d1eea5d52
11 changes: 11 additions & 0 deletions Lib/test/test_codecs.py
Original file line number Diff line number Diff line change
Expand Up @@ -1985,6 +1985,11 @@ class StreamWriterTest(unittest.TestCase):
def setUp(self):
self.writer = codecs.getwriter('utf-8')

def test_write(self):
bio = io.BytesIO()
assert self.writer(bio).write("Hällo") == 6
self.assertEqual(bio.getvalue(), b'H\xc3\xa4llo')

def test_copy(self):
f = self.writer(Queue(b''))
with self.assertRaisesRegex(TypeError, 'StreamWriter'):
Expand All @@ -2006,6 +2011,12 @@ def setUp(self):
self.reader = codecs.getreader('latin1')
self.writer = codecs.getwriter('utf-8')

def test_write(self):
bio = io.BytesIO()
f = codecs.StreamReaderWriter(bio, self.reader, self.writer)
assert f.write("Hällo") == 6
self.assertEqual(bio.getvalue(), b'H\xc3\xa4llo')

def test_copy(self):
f = codecs.StreamReaderWriter(Queue(b''), self.reader, self.writer)
with self.assertRaisesRegex(TypeError, 'StreamReaderWriter'):
Expand Down
Loading
0