home *** CD-ROM | disk | FTP | other *** search
/ PC World 2001 April / PCWorld_2001-04_cd.bin / Software / TemaCD / webclean / !!!python!!! / BeOpen-Python-2.0.exe / TEST_OPERATIONS.PY < prev    next >
Encoding:
Text File  |  2000-09-28  |  683 b   |  29 lines

  1. # Python test set -- part 3, built-in operations.
  2.  
  3.  
  4. print '3. Operations'
  5. print 'XXX Mostly not yet implemented'
  6.  
  7.  
  8. print '3.1 Dictionary lookups succeed even if __cmp__() raises an exception'
  9.  
  10. # SourceForge bug #112558:
  11. # http://sourceforge.net/bugs/?func=detailbug&bug_id=112558&group_id=5470
  12.  
  13. class BadDictKey: 
  14.     def __hash__(self): 
  15.         return hash(self.__class__) 
  16.  
  17.     def __cmp__(self, other): 
  18.         if isinstance(other, self.__class__): 
  19.             print "raising error" 
  20.             raise RuntimeError, "gotcha" 
  21.         return other 
  22.  
  23. d = {}
  24. x1 = BadDictKey()
  25. x2 = BadDictKey()
  26. d[x1] = 1
  27. d[x2] = 2
  28. print "No exception passed through."
  29.