Skip to content

Commit 4747fda

Browse files
Add more tests.
1 parent 9eda73e commit 4747fda

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

Lib/test/test_capi/test_getargs.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1352,6 +1352,55 @@ def test_nested_tuple(self):
13521352
"argument 1 must be sequence of length 1, not 0"):
13531353
parse(((),), {}, '(' + f + ')', ['a'])
13541354

1355+
def test_specific_type_errors(self):
1356+
parse = _testcapi.parse_tuple_and_keywords
1357+
1358+
def check(format, arg, expected, got='list'):
1359+
errmsg = f'must be {expected}, not {got}'
1360+
with self.assertRaisesRegex(TypeError, errmsg):
1361+
parse((arg,), {}, format, ['a'])
1362+
1363+
check('k', [], 'int')
1364+
check('?k', [], 'int or None')
1365+
check('K', [], 'int')
1366+
check('?K', [], 'int or None')
1367+
check('c', [], 'a byte string of length 1')
1368+
check('?c', [], 'a byte string of length 1 or None')
1369+
check('c', b'abc', 'a byte string of length 1',
1370+
'a bytes object of length 3')
1371+
check('?c', b'abc', 'a byte string of length 1 or None',
1372+
'a bytes object of length 3')
1373+
check('c', bytearray(b'abc'), 'a byte string of length 1',
1374+
'a bytearray object of length 3')
1375+
check('?c', bytearray(b'abc'), 'a byte string of length 1 or None',
1376+
'a bytearray object of length 3')
1377+
check('C', [], 'a unicode character')
1378+
check('?C', [], 'a unicode character or None')
1379+
check('C', 'abc', 'a unicode character',
1380+
'a string of length 3')
1381+
check('?C', 'abc', 'a unicode character or None',
1382+
'a string of length 3')
1383+
check('s', [], 'str')
1384+
check('?s', [], 'str or None')
1385+
check('z', [], 'str or None')
1386+
check('?z', [], 'str or None')
1387+
check('es', [], 'str')
1388+
check('?es', [], 'str or None')
1389+
check('es#', [], 'str')
1390+
check('?es#', [], 'str or None')
1391+
check('et', [], 'str, bytes or bytearray')
1392+
check('?et', [], 'str, bytes or bytearray or None')
1393+
check('et#', [], 'str, bytes or bytearray')
1394+
check('?et#', [], 'str, bytes or bytearray or None')
1395+
check('w*', [], 'read-write bytes-like object')
1396+
check('?w*', [], 'read-write bytes-like object or None')
1397+
check('S', [], 'bytes')
1398+
check('?S', [], 'bytes or None')
1399+
check('U', [], 'str')
1400+
check('?U', [], 'str or None')
1401+
check('Y', [], 'bytearray')
1402+
check('?Y', [], 'bytearray or None')
1403+
13551404
def test_nullable(self):
13561405
parse = _testcapi.parse_tuple_and_keywords
13571406

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy