Guido van Rossum | 5c97167 | 1996-07-22 15:23:25 +0000 | [diff] [blame] | 1 | # Python test set -- part 2, opcodes |
| 2 | |
| 3 | from test_support import * |
| 4 | |
| 5 | |
| 6 | print '2. Opcodes' |
| 7 | print 'XXX Not yet fully implemented' |
| 8 | |
| 9 | print '2.1 try inside for loop' |
| 10 | n = 0 |
| 11 | for i in range(10): |
| 12 | n = n+i |
| 13 | try: 1/0 |
| 14 | except NameError: pass |
| 15 | except ZeroDivisionError: pass |
| 16 | except TypeError: pass |
| 17 | try: pass |
| 18 | except: pass |
| 19 | try: pass |
| 20 | finally: pass |
| 21 | n = n+i |
| 22 | if n <> 90: |
| 23 | raise TestFailed, 'try inside for' |
| 24 | |
| 25 | |
| 26 | print '2.2 raise class exceptions' |
| 27 | |
| 28 | class AClass: pass |
| 29 | class BClass(AClass): pass |
| 30 | class CClass: pass |
| 31 | |
| 32 | try: raise AClass() |
| 33 | except: pass |
| 34 | |
| 35 | try: raise AClass() |
| 36 | except AClass: pass |
| 37 | |
| 38 | try: raise BClass() |
| 39 | except AClass: pass |
| 40 | |
| 41 | try: raise BClass() |
| 42 | except CClass: raise TestFailed |
| 43 | except: pass |
| 44 | |
| 45 | a = AClass() |
| 46 | b = BClass() |
| 47 | |
| 48 | try: raise AClass, b |
| 49 | except BClass, v: raise TestFailed |
| 50 | except AClass, v: |
| 51 | if v != b: raise TestFailed |
| 52 | |
| 53 | |
| 54 | try: raise b |
| 55 | except AClass, v: |
| 56 | if v != b: raise TestFailed |
| 57 | |
| 58 | try: raise BClass, a |
| 59 | except TypeError: pass |