66import sys
77import pickle
88from test import support
9+ from test .support import ALWAYS_EQ , NEVER_EQ
910
1011# Various iterables
1112# This is used for checking the constructor (here and in test_deque.py)
@@ -209,6 +210,7 @@ def test_getslice(self):
209210 a = self .type2test ([0 ,1 ,2 ,3 ,4 ])
210211 self .assertEqual (a [ - pow (2 ,128 ): 3 ], self .type2test ([0 ,1 ,2 ]))
211212 self .assertEqual (a [ 3 : pow (2 ,145 ) ], self .type2test ([3 ,4 ]))
213+ self .assertEqual (a [3 ::sys .maxsize ], self .type2test ([3 ]))
212214
213215 def test_contains (self ):
214216 u = self .type2test ([0 , 1 , 2 ])
@@ -220,15 +222,15 @@ def test_contains(self):
220222 self .assertRaises (TypeError , u .__contains__ )
221223
222224 def test_contains_fake (self ):
223- class AllEq :
224- # Sequences must use rich comparison against each item
225- # (unless "is" is true, or an earlier item answered)
226- # So instances of AllEq must be found in all non-empty sequences.
227- def __eq__ ( self , other ):
228- return True
229- __hash__ = None # Can't meet hash invariant requirements
230- self .assertNotIn (AllEq () , self .type2test ([]))
231- self .assertIn (AllEq () , self .type2test ([1 ]))
225+ # Sequences must use rich comparison against each item
226+ # (unless "is" is true, or an earlier item answered)
227+ # So ALWAYS_EQ must be found in all non-empty sequences.
228+ self . assertNotIn ( ALWAYS_EQ , self . type2test ([]))
229+ self . assertIn ( ALWAYS_EQ , self . type2test ([ 1 ]))
230+ self . assertIn ( 1 , self . type2test ([ ALWAYS_EQ ]))
231+ self . assertNotIn ( NEVER_EQ , self . type2test ([]))
232+ self .assertNotIn (ALWAYS_EQ , self .type2test ([NEVER_EQ ]))
233+ self .assertIn (NEVER_EQ , self .type2test ([ALWAYS_EQ ]))
232234
233235 def test_contains_order (self ):
234236 # Sequences must test in-order. If a rich comparison has side
@@ -349,6 +351,11 @@ def test_count(self):
349351 self .assertEqual (a .count (1 ), 3 )
350352 self .assertEqual (a .count (3 ), 0 )
351353
354+ self .assertEqual (a .count (ALWAYS_EQ ), 9 )
355+ self .assertEqual (self .type2test ([ALWAYS_EQ , ALWAYS_EQ ]).count (1 ), 2 )
356+ self .assertEqual (self .type2test ([ALWAYS_EQ , ALWAYS_EQ ]).count (NEVER_EQ ), 2 )
357+ self .assertEqual (self .type2test ([NEVER_EQ , NEVER_EQ ]).count (ALWAYS_EQ ), 0 )
358+
352359 self .assertRaises (TypeError , a .count )
353360
354361 class BadExc (Exception ):
@@ -377,6 +384,11 @@ def test_index(self):
377384 self .assertEqual (u .index (0 , 3 , 4 ), 3 )
378385 self .assertRaises (ValueError , u .index , 2 , 0 , - 10 )
379386
387+ self .assertEqual (u .index (ALWAYS_EQ ), 0 )
388+ self .assertEqual (self .type2test ([ALWAYS_EQ , ALWAYS_EQ ]).index (1 ), 0 )
389+ self .assertEqual (self .type2test ([ALWAYS_EQ , ALWAYS_EQ ]).index (NEVER_EQ ), 0 )
390+ self .assertRaises (ValueError , self .type2test ([NEVER_EQ , NEVER_EQ ]).index , ALWAYS_EQ )
391+
380392 self .assertRaises (TypeError , u .index )
381393
382394 class BadExc (Exception ):
0 commit comments