Guido van Rossum | 3bead09 | 1992-01-27 17:00:37 +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): |
Guido van Rossum | 41360a4 | 1998-03-26 19:42:58 +0000 | [diff] [blame] | 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 |
Guido van Rossum | 3bead09 | 1992-01-27 17:00:37 +0000 | [diff] [blame] | 22 | if n <> 90: |
Guido van Rossum | 41360a4 | 1998-03-26 19:42:58 +0000 | [diff] [blame] | 23 | raise TestFailed, 'try inside for' |
Guido van Rossum | 6de668f | 1995-02-09 10:28:43 +0000 | [diff] [blame] | 24 | |
| 25 | |
| 26 | print '2.2 raise class exceptions' |
| 27 | |
| 28 | class AClass: pass |
| 29 | class BClass(AClass): pass |
| 30 | class CClass: pass |
Barry Warsaw | 558f66f | 1997-08-22 21:28:05 +0000 | [diff] [blame] | 31 | class DClass(AClass): |
| 32 | def __init__(self, ignore): |
Guido van Rossum | 41360a4 | 1998-03-26 19:42:58 +0000 | [diff] [blame] | 33 | pass |
Guido van Rossum | 6de668f | 1995-02-09 10:28:43 +0000 | [diff] [blame] | 34 | |
| 35 | try: raise AClass() |
| 36 | except: pass |
| 37 | |
| 38 | try: raise AClass() |
| 39 | except AClass: pass |
| 40 | |
| 41 | try: raise BClass() |
| 42 | except AClass: pass |
| 43 | |
| 44 | try: raise BClass() |
| 45 | except CClass: raise TestFailed |
| 46 | except: pass |
| 47 | |
| 48 | a = AClass() |
| 49 | b = BClass() |
| 50 | |
| 51 | try: raise AClass, b |
Guido van Rossum | ae631f7 | 1997-10-01 04:41:05 +0000 | [diff] [blame] | 52 | except BClass, v: |
Guido van Rossum | 41360a4 | 1998-03-26 19:42:58 +0000 | [diff] [blame] | 53 | if v != b: raise TestFailed |
Guido van Rossum | ae631f7 | 1997-10-01 04:41:05 +0000 | [diff] [blame] | 54 | else: raise TestFailed |
Guido van Rossum | 6de668f | 1995-02-09 10:28:43 +0000 | [diff] [blame] | 55 | |
| 56 | try: raise b |
| 57 | except AClass, v: |
Guido van Rossum | 41360a4 | 1998-03-26 19:42:58 +0000 | [diff] [blame] | 58 | if v != b: raise TestFailed |
Guido van Rossum | 6de668f | 1995-02-09 10:28:43 +0000 | [diff] [blame] | 59 | |
Barry Warsaw | 558f66f | 1997-08-22 21:28:05 +0000 | [diff] [blame] | 60 | # not enough arguments |
Guido van Rossum | 6de668f | 1995-02-09 10:28:43 +0000 | [diff] [blame] | 61 | try: raise BClass, a |
| 62 | except TypeError: pass |
Guido van Rossum | 570278b | 1997-08-05 16:52:50 +0000 | [diff] [blame] | 63 | |
Barry Warsaw | 558f66f | 1997-08-22 21:28:05 +0000 | [diff] [blame] | 64 | try: raise DClass, a |
| 65 | except DClass, v: |
| 66 | if not isinstance(v, DClass): |
Guido van Rossum | 41360a4 | 1998-03-26 19:42:58 +0000 | [diff] [blame] | 67 | raise TestFailed |
Guido van Rossum | 570278b | 1997-08-05 16:52:50 +0000 | [diff] [blame] | 68 | |
| 69 | print '2.3 comparing function objects' |
| 70 | |
| 71 | f = eval('lambda: None') |
| 72 | g = eval('lambda: None') |
| 73 | if f != g: raise TestFailed |
| 74 | |
| 75 | f = eval('lambda a: a') |
| 76 | g = eval('lambda a: a') |
| 77 | if f != g: raise TestFailed |
| 78 | |
| 79 | f = eval('lambda a=1: a') |
| 80 | g = eval('lambda a=1: a') |
| 81 | if f != g: raise TestFailed |
| 82 | |
| 83 | f = eval('lambda: 0') |
| 84 | g = eval('lambda: 1') |
| 85 | if f == g: raise TestFailed |
| 86 | |
| 87 | f = eval('lambda: None') |
| 88 | g = eval('lambda a: None') |
| 89 | if f == g: raise TestFailed |
| 90 | |
| 91 | f = eval('lambda a: None') |
| 92 | g = eval('lambda b: None') |
| 93 | if f == g: raise TestFailed |
| 94 | |
| 95 | f = eval('lambda a: None') |
| 96 | g = eval('lambda a=None: None') |
| 97 | if f == g: raise TestFailed |
| 98 | |
| 99 | f = eval('lambda a=0: None') |
| 100 | g = eval('lambda a=1: None') |
| 101 | if f == g: raise TestFailed |