mirror of
https://github.com/python/cpython.git
synced 2025-12-08 06:10:17 +00:00
gh-129813, PEP 782: Add PyBytesWriter_Format() (#138824)
Modify PyBytes_FromFormatV() to use the public PyBytesWriter API rather than the _PyBytesWriter private API.
This commit is contained in:
parent
419441a6e1
commit
c3fca5d478
7 changed files with 130 additions and 30 deletions
|
|
@ -361,12 +361,26 @@ def test_resize(self):
|
|||
writer.resize(len(b'number=123456'), b'456')
|
||||
self.assertEqual(writer.finish(), self.result_type(b'number=123456'))
|
||||
|
||||
def test_format_i(self):
|
||||
# Test PyBytesWriter_Format()
|
||||
writer = self.create_writer()
|
||||
writer.format_i(b'x=%i', 123456)
|
||||
self.assertEqual(writer.finish(), self.result_type(b'x=123456'))
|
||||
|
||||
writer = self.create_writer()
|
||||
writer.format_i(b'x=%i, ', 123)
|
||||
writer.format_i(b'y=%i', 456)
|
||||
self.assertEqual(writer.finish(), self.result_type(b'x=123, y=456'))
|
||||
|
||||
def test_example_abc(self):
|
||||
self.assertEqual(_testcapi.byteswriter_abc(), b'abc')
|
||||
|
||||
def test_example_resize(self):
|
||||
self.assertEqual(_testcapi.byteswriter_resize(), b'Hello World')
|
||||
|
||||
def test_example_highlevel(self):
|
||||
self.assertEqual(_testcapi.byteswriter_highlevel(), b'Hello World!')
|
||||
|
||||
|
||||
class ByteArrayWriterTest(BytesWriterTest):
|
||||
result_type = bytearray
|
||||
|
|
@ -374,5 +388,6 @@ class ByteArrayWriterTest(BytesWriterTest):
|
|||
def create_writer(self, alloc=0, string=b''):
|
||||
return _testcapi.PyBytesWriter(alloc, string, 1)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue