Issue #12380: PyArg_ParseTuple now accepts a bytearray for the 'c' format.

As a side effect, this now allows the rjust, ljust and center methods of
bytes and bytearray to accept a bytearray argument.

Patch by Petri Lehtinen
This commit is contained in:
Eli Bendersky 2011-07-29 07:05:08 +03:00
parent 66d2be8986
commit 906b88fb2a
6 changed files with 53 additions and 4 deletions

View file

@ -294,6 +294,15 @@ class Keywords_TestCase(unittest.TestCase):
self.fail('TypeError should have been raised')
class Bytes_TestCase(unittest.TestCase):
def test_c(self):
from _testcapi import getargs_c
self.assertRaises(TypeError, getargs_c, b'abc') # len > 1
self.assertEqual(getargs_c(b'a'), b'a')
self.assertEqual(getargs_c(bytearray(b'a')), b'a')
self.assertRaises(TypeError, getargs_c, memoryview(b'a'))
self.assertRaises(TypeError, getargs_c, 's')
self.assertRaises(TypeError, getargs_c, None)
def test_s(self):
from _testcapi import getargs_s
self.assertEqual(getargs_s('abc\xe9'), b'abc\xc3\xa9')