Guido van Rossum | 3bead09 | 1992-01-27 17:00:37 +0000 | [diff] [blame] | 1 | # Python test set -- part 2, opcodes |
| 2 | |
Barry Warsaw | 408b6d3 | 2002-07-30 23:27:12 +0000 | [diff] [blame] | 3 | from test.test_support import TestFailed |
Guido van Rossum | 3bead09 | 1992-01-27 17:00:37 +0000 | [diff] [blame] | 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): |
Fred Drake | 004d5e6 | 2000-10-23 17:22:08 +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 |
Fred Drake | 132dce2 | 2000-12-12 23:11:42 +0000 | [diff] [blame] | 22 | if n != 90: |
Fred Drake | 004d5e6 | 2000-10-23 17:22:08 +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: |
Moshe Zadka | 497671e | 2001-01-29 06:21:17 +0000 | [diff] [blame] | 53 | if v != b: raise TestFailed, "v!=b" |
| 54 | else: raise TestFailed, "no exception" |
Guido van Rossum | 6de668f | 1995-02-09 10:28:43 +0000 | [diff] [blame] | 55 | |
| 56 | try: raise b |
| 57 | except AClass, v: |
Moshe Zadka | 497671e | 2001-01-29 06:21:17 +0000 | [diff] [blame] | 58 | if v != b: raise TestFailed, "v!=b AClass" |
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): |
Moshe Zadka | 497671e | 2001-01-29 06:21:17 +0000 | [diff] [blame] | 67 | raise TestFailed, "v not DClass" |
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') |
Moshe Zadka | 497671e | 2001-01-29 06:21:17 +0000 | [diff] [blame] | 73 | if f == g: raise TestFailed, "functions should not be same" |
Guido van Rossum | 570278b | 1997-08-05 16:52:50 +0000 | [diff] [blame] | 74 | |
| 75 | f = eval('lambda a: a') |
| 76 | g = eval('lambda a: a') |
Moshe Zadka | 497671e | 2001-01-29 06:21:17 +0000 | [diff] [blame] | 77 | if f == g: raise TestFailed, "functions should not be same" |
Guido van Rossum | 570278b | 1997-08-05 16:52:50 +0000 | [diff] [blame] | 78 | |
| 79 | f = eval('lambda a=1: a') |
| 80 | g = eval('lambda a=1: a') |
Moshe Zadka | 497671e | 2001-01-29 06:21:17 +0000 | [diff] [blame] | 81 | if f == g: raise TestFailed, "functions should not be same" |
Guido van Rossum | 570278b | 1997-08-05 16:52:50 +0000 | [diff] [blame] | 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 |