11import unittest
22import sys
33from collections import OrderedDict
4- from test import support
54from test .support import import_helper
6- import _testcapi
75
6+ _testcapi = import_helper .import_module ('_testcapi' )
7+ from _testcapi import PY_SSIZE_T_MIN , PY_SSIZE_T_MAX
88
99NULL = None
1010
@@ -446,6 +446,8 @@ def test_sequence_getitem(self):
446446 self .assertEqual (getitem (lst , 1 ), 'b' )
447447 self .assertEqual (getitem (lst , - 1 ), 'c' )
448448 self .assertRaises (IndexError , getitem , lst , 3 )
449+ self .assertRaises (IndexError , getitem , lst , PY_SSIZE_T_MAX )
450+ self .assertRaises (IndexError , getitem , lst , PY_SSIZE_T_MIN )
449451
450452 self .assertRaises (TypeError , getitem , 42 , 1 )
451453 self .assertRaises (TypeError , getitem , {}, 1 )
@@ -470,6 +472,9 @@ def test_sequence_repeat(self):
470472 self .assertEqual (repeat (('a' , 'b' ), 2 ), ('a' , 'b' , 'a' , 'b' ))
471473 self .assertEqual (repeat (['a' , 'b' ], 0 ), [])
472474 self .assertEqual (repeat (['a' , 'b' ], - 1 ), [])
475+ self .assertEqual (repeat (['a' , 'b' ], PY_SSIZE_T_MIN ), [])
476+ self .assertEqual (repeat ([], PY_SSIZE_T_MAX ), [])
477+ self .assertRaises (MemoryError , repeat , ['a' , 'b' ], PY_SSIZE_T_MAX )
473478
474479 self .assertRaises (TypeError , repeat , set (), 2 )
475480 self .assertRaises (TypeError , repeat , 42 , 2 )
@@ -503,6 +508,9 @@ def test_sequence_inplacerepeat(self):
503508 self .assertEqual (inplacerepeat (('a' , 'b' ), 2 ), ('a' , 'b' , 'a' , 'b' ))
504509 self .assertEqual (inplacerepeat (['a' , 'b' ], 0 ), [])
505510 self .assertEqual (inplacerepeat (['a' , 'b' ], - 1 ), [])
511+ self .assertEqual (inplacerepeat (['a' , 'b' ], PY_SSIZE_T_MIN ), [])
512+ self .assertEqual (inplacerepeat ([], PY_SSIZE_T_MAX ), [])
513+ self .assertRaises (MemoryError , inplacerepeat , ['a' , 'b' ], PY_SSIZE_T_MAX )
506514
507515 self .assertRaises (TypeError , inplacerepeat , set (), 2 )
508516 self .assertRaises (TypeError , inplacerepeat , 42 , 2 )
@@ -519,6 +527,8 @@ def test_sequence_setitem(self):
519527 setitem (lst , 0 , NULL )
520528 self .assertEqual (lst , ['x' , 'y' ])
521529 self .assertRaises (IndexError , setitem , lst , 3 , 'x' )
530+ self .assertRaises (IndexError , setitem , lst , PY_SSIZE_T_MAX , 'x' )
531+ self .assertRaises (IndexError , setitem , lst , PY_SSIZE_T_MIN , 'x' )
522532
523533 self .assertRaises (TypeError , setitem , 42 , 1 , 'x' )
524534 self .assertRaises (TypeError , setitem , {}, 1 , 'x' )
@@ -532,6 +542,8 @@ def test_sequence_delitem(self):
532542 delitem (lst , - 1 )
533543 self .assertEqual (lst , ['a' ])
534544 self .assertRaises (IndexError , delitem , lst , 3 )
545+ self .assertRaises (IndexError , delitem , lst , PY_SSIZE_T_MAX )
546+ self .assertRaises (IndexError , delitem , lst , PY_SSIZE_T_MIN )
535547
536548 self .assertRaises (TypeError , delitem , 42 , 1 )
537549 self .assertRaises (TypeError , delitem , {}, 1 )
@@ -541,13 +553,19 @@ def test_sequence_setslice(self):
541553 setslice = _testcapi .sequence_setslice
542554
543555 # Correct case:
544- data = [1 , 2 , 3 , 4 , 5 ]
545- data_copy = data .copy ()
546-
547- setslice (data , 1 , 3 , [8 , 9 ])
548- data_copy [1 :3 ] = [8 , 9 ]
549- self .assertEqual (data , data_copy )
550- self .assertEqual (data , [1 , 8 , 9 , 4 , 5 ])
556+ for start in [* range (- 6 , 7 ), PY_SSIZE_T_MIN , PY_SSIZE_T_MAX ]:
557+ for stop in [* range (- 6 , 7 ), PY_SSIZE_T_MIN , PY_SSIZE_T_MAX ]:
558+ data = [1 , 2 , 3 , 4 , 5 ]
559+ data_copy = [1 , 2 , 3 , 4 , 5 ]
560+ setslice (data , start , stop , [8 , 9 ])
561+ data_copy [start :stop ] = [8 , 9 ]
562+ self .assertEqual (data , data_copy )
563+
564+ data = [1 , 2 , 3 , 4 , 5 ]
565+ data_copy = [1 , 2 , 3 , 4 , 5 ]
566+ setslice (data , start , stop , NULL )
567+ del data_copy [start :stop ]
568+ self .assertEqual (data , data_copy )
551569
552570 # Custom class:
553571 class Custom :
@@ -573,21 +591,17 @@ def __setitem__(self, index, value):
573591 self .assertRaises (TypeError , setslice , object (), 1 , 3 , 'xy' )
574592 self .assertRaises (SystemError , setslice , NULL , 1 , 3 , 'xy' )
575593
576- data_copy = data .copy ()
577- setslice (data_copy , 1 , 3 , NULL )
578- self .assertEqual (data_copy , [1 , 4 , 5 ])
579-
580594 def test_sequence_delslice (self ):
581595 delslice = _testcapi .sequence_delslice
582596
583597 # Correct case:
584- data = [ 1 , 2 , 3 , 4 , 5 ]
585- data_copy = data . copy ()
586-
587- delslice ( data , 1 , 3 )
588- del data_copy [ 1 : 3 ]
589- self . assertEqual ( data , data_copy )
590- self .assertEqual (data , [ 1 , 4 , 5 ] )
598+ for start in [ * range ( - 6 , 7 ), PY_SSIZE_T_MIN , PY_SSIZE_T_MAX ]:
599+ for stop in [ * range ( - 6 , 7 ), PY_SSIZE_T_MIN , PY_SSIZE_T_MAX ]:
600+ data = [ 1 , 2 , 3 , 4 , 5 ]
601+ data_copy = [ 1 , 2 , 3 , 4 , 5 ]
602+ delslice ( data , start , stop )
603+ del data_copy [ start : stop ]
604+ self .assertEqual (data , data_copy )
591605
592606 # Custom class:
593607 class Custom :
0 commit comments