66import pickle
77import random
88import re
9- import string
109import subprocess
1110import sys
1211import sysconfig
@@ -414,174 +413,6 @@ def test_subinterps(self):
414413 self .assertNotEqual (pickle .load (f ), id (builtins ))
415414
416415
417- # Bug #6012
418- class Test6012 (unittest .TestCase ):
419- def test (self ):
420- self .assertEqual (_testcapi .argparsing ("Hello" , "World" ), 1 )
421-
422-
423- class SkipitemTest (unittest .TestCase ):
424-
425- def test_skipitem (self ):
426- """
427- If this test failed, you probably added a new "format unit"
428- in Python/getargs.c, but neglected to update our poor friend
429- skipitem() in the same file. (If so, shame on you!)
430-
431- With a few exceptions**, this function brute-force tests all
432- printable ASCII*** characters (32 to 126 inclusive) as format units,
433- checking to see that PyArg_ParseTupleAndKeywords() return consistent
434- errors both when the unit is attempted to be used and when it is
435- skipped. If the format unit doesn't exist, we'll get one of two
436- specific error messages (one for used, one for skipped); if it does
437- exist we *won't* get that error--we'll get either no error or some
438- other error. If we get the specific "does not exist" error for one
439- test and not for the other, there's a mismatch, and the test fails.
440-
441- ** Some format units have special funny semantics and it would
442- be difficult to accommodate them here. Since these are all
443- well-established and properly skipped in skipitem() we can
444- get away with not testing them--this test is really intended
445- to catch *new* format units.
446-
447- *** Python C source files must be ASCII. Therefore it's impossible
448- to have non-ASCII format units.
449-
450- """
451- empty_tuple = ()
452- tuple_1 = (0 ,)
453- dict_b = {'b' :1 }
454- keywords = ["a" , "b" ]
455-
456- for i in range (32 , 127 ):
457- c = chr (i )
458-
459- # skip parentheses, the error reporting is inconsistent about them
460- # skip 'e', it's always a two-character code
461- # skip '|' and '$', they don't represent arguments anyway
462- if c in '()e|$' :
463- continue
464-
465- # test the format unit when not skipped
466- format = c + "i"
467- try :
468- _testcapi .parse_tuple_and_keywords (tuple_1 , dict_b ,
469- format , keywords )
470- when_not_skipped = False
471- except SystemError as e :
472- s = "argument 1 (impossible<bad format char>)"
473- when_not_skipped = (str (e ) == s )
474- except TypeError :
475- when_not_skipped = False
476-
477- # test the format unit when skipped
478- optional_format = "|" + format
479- try :
480- _testcapi .parse_tuple_and_keywords (empty_tuple , dict_b ,
481- optional_format , keywords )
482- when_skipped = False
483- except SystemError as e :
484- s = "impossible<bad format char>: '{}'" .format (format )
485- when_skipped = (str (e ) == s )
486-
487- message = ("test_skipitem_parity: "
488- "detected mismatch between convertsimple and skipitem "
489- "for format unit '{}' ({}), not skipped {}, skipped {}" .format (
490- c , i , when_skipped , when_not_skipped ))
491- self .assertIs (when_skipped , when_not_skipped , message )
492-
493- def test_skipitem_with_suffix (self ):
494- parse = _testcapi .parse_tuple_and_keywords
495- empty_tuple = ()
496- tuple_1 = (0 ,)
497- dict_b = {'b' :1 }
498- keywords = ["a" , "b" ]
499-
500- supported = ('s#' , 's*' , 'z#' , 'z*' , 'u#' , 'Z#' , 'y#' , 'y*' , 'w#' , 'w*' )
501- for c in string .ascii_letters :
502- for c2 in '#*' :
503- f = c + c2
504- with self .subTest (format = f ):
505- optional_format = "|" + f + "i"
506- if f in supported :
507- parse (empty_tuple , dict_b , optional_format , keywords )
508- else :
509- with self .assertRaisesRegex (SystemError ,
510- 'impossible<bad format char>' ):
511- parse (empty_tuple , dict_b , optional_format , keywords )
512-
513- for c in map (chr , range (32 , 128 )):
514- f = 'e' + c
515- optional_format = "|" + f + "i"
516- with self .subTest (format = f ):
517- if c in 'st' :
518- parse (empty_tuple , dict_b , optional_format , keywords )
519- else :
520- with self .assertRaisesRegex (SystemError ,
521- 'impossible<bad format char>' ):
522- parse (empty_tuple , dict_b , optional_format , keywords )
523-
524- def test_parse_tuple_and_keywords (self ):
525- # Test handling errors in the parse_tuple_and_keywords helper itself
526- self .assertRaises (TypeError , _testcapi .parse_tuple_and_keywords ,
527- (), {}, 42 , [])
528- self .assertRaises (ValueError , _testcapi .parse_tuple_and_keywords ,
529- (), {}, '' , 42 )
530- self .assertRaises (ValueError , _testcapi .parse_tuple_and_keywords ,
531- (), {}, '' , ['' ] * 42 )
532- self .assertRaises (ValueError , _testcapi .parse_tuple_and_keywords ,
533- (), {}, '' , [42 ])
534-
535- def test_bad_use (self ):
536- # Test handling invalid format and keywords in
537- # PyArg_ParseTupleAndKeywords()
538- self .assertRaises (SystemError , _testcapi .parse_tuple_and_keywords ,
539- (1 ,), {}, '||O' , ['a' ])
540- self .assertRaises (SystemError , _testcapi .parse_tuple_and_keywords ,
541- (1 , 2 ), {}, '|O|O' , ['a' , 'b' ])
542- self .assertRaises (SystemError , _testcapi .parse_tuple_and_keywords ,
543- (), {'a' : 1 }, '$$O' , ['a' ])
544- self .assertRaises (SystemError , _testcapi .parse_tuple_and_keywords ,
545- (), {'a' : 1 , 'b' : 2 }, '$O$O' , ['a' , 'b' ])
546- self .assertRaises (SystemError , _testcapi .parse_tuple_and_keywords ,
547- (), {'a' : 1 }, '$|O' , ['a' ])
548- self .assertRaises (SystemError , _testcapi .parse_tuple_and_keywords ,
549- (), {'a' : 1 , 'b' : 2 }, '$O|O' , ['a' , 'b' ])
550- self .assertRaises (SystemError , _testcapi .parse_tuple_and_keywords ,
551- (1 ,), {}, '|O' , ['a' , 'b' ])
552- self .assertRaises (SystemError , _testcapi .parse_tuple_and_keywords ,
553- (1 ,), {}, '|OO' , ['a' ])
554- self .assertRaises (SystemError , _testcapi .parse_tuple_and_keywords ,
555- (), {}, '|$O' , ['' ])
556- self .assertRaises (SystemError , _testcapi .parse_tuple_and_keywords ,
557- (), {}, '|OO' , ['a' , '' ])
558-
559- def test_positional_only (self ):
560- parse = _testcapi .parse_tuple_and_keywords
561-
562- parse ((1 , 2 , 3 ), {}, 'OOO' , ['' , '' , 'a' ])
563- parse ((1 , 2 ), {'a' : 3 }, 'OOO' , ['' , '' , 'a' ])
564- with self .assertRaisesRegex (TypeError ,
565- r'function takes at least 2 positional arguments \(1 given\)' ):
566- parse ((1 ,), {'a' : 3 }, 'OOO' , ['' , '' , 'a' ])
567- parse ((1 ,), {}, 'O|OO' , ['' , '' , 'a' ])
568- with self .assertRaisesRegex (TypeError ,
569- r'function takes at least 1 positional arguments \(0 given\)' ):
570- parse ((), {}, 'O|OO' , ['' , '' , 'a' ])
571- parse ((1 , 2 ), {'a' : 3 }, 'OO$O' , ['' , '' , 'a' ])
572- with self .assertRaisesRegex (TypeError ,
573- r'function takes exactly 2 positional arguments \(1 given\)' ):
574- parse ((1 ,), {'a' : 3 }, 'OO$O' , ['' , '' , 'a' ])
575- parse ((1 ,), {}, 'O|O$O' , ['' , '' , 'a' ])
576- with self .assertRaisesRegex (TypeError ,
577- r'function takes at least 1 positional arguments \(0 given\)' ):
578- parse ((), {}, 'O|O$O' , ['' , '' , 'a' ])
579- with self .assertRaisesRegex (SystemError , r'Empty parameter name after \$' ):
580- parse ((1 ,), {}, 'O|$OO' , ['' , '' , 'a' ])
581- with self .assertRaisesRegex (SystemError , 'Empty keyword' ):
582- parse ((1 ,), {}, 'O|OO' , ['' , 'a' , '' ])
583-
584-
585416class TestThreadState (unittest .TestCase ):
586417
587418 @support .reap_threads
@@ -607,17 +438,9 @@ def callback():
607438
608439
609440class Test_testcapi (unittest .TestCase ):
610- def test__testcapi (self ):
611- if support .verbose :
612- print ()
613- for name in dir (_testcapi ):
614- if not name .startswith ('test_' ):
615- continue
616- with self .subTest ("internal" , name = name ):
617- if support .verbose :
618- print (f" { name } " , flush = True )
619- test = getattr (_testcapi , name )
620- test ()
441+ locals ().update ((name , getattr (_testcapi , name ))
442+ for name in dir (_testcapi )
443+ if name .startswith ('test_' ) and not name .endswith ('_code' ))
621444
622445
623446class PyMemDebugTests (unittest .TestCase ):
0 commit comments