blob: bdace26a472b4d64901d3c8fdbb28527f4b011b4 [file] [log] [blame]
Guido van Rossum3bead091992-01-27 17:00:37 +00001# Python test set -- part 2, opcodes
2
3from test_support import *
4
5
6print '2. Opcodes'
7print 'XXX Not yet fully implemented'
8
9print '2.1 try inside for loop'
10n = 0
11for i in range(10):
Guido van Rossum41360a41998-03-26 19:42:58 +000012 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 Rossum3bead091992-01-27 17:00:37 +000022if n <> 90:
Guido van Rossum41360a41998-03-26 19:42:58 +000023 raise TestFailed, 'try inside for'
Guido van Rossum6de668f1995-02-09 10:28:43 +000024
25
26print '2.2 raise class exceptions'
27
28class AClass: pass
29class BClass(AClass): pass
30class CClass: pass
Barry Warsaw558f66f1997-08-22 21:28:05 +000031class DClass(AClass):
32 def __init__(self, ignore):
Guido van Rossum41360a41998-03-26 19:42:58 +000033 pass
Guido van Rossum6de668f1995-02-09 10:28:43 +000034
35try: raise AClass()
36except: pass
37
38try: raise AClass()
39except AClass: pass
40
41try: raise BClass()
42except AClass: pass
43
44try: raise BClass()
45except CClass: raise TestFailed
46except: pass
47
48a = AClass()
49b = BClass()
50
51try: raise AClass, b
Guido van Rossumae631f71997-10-01 04:41:05 +000052except BClass, v:
Guido van Rossum41360a41998-03-26 19:42:58 +000053 if v != b: raise TestFailed
Guido van Rossumae631f71997-10-01 04:41:05 +000054else: raise TestFailed
Guido van Rossum6de668f1995-02-09 10:28:43 +000055
56try: raise b
57except AClass, v:
Guido van Rossum41360a41998-03-26 19:42:58 +000058 if v != b: raise TestFailed
Guido van Rossum6de668f1995-02-09 10:28:43 +000059
Barry Warsaw558f66f1997-08-22 21:28:05 +000060# not enough arguments
Guido van Rossum6de668f1995-02-09 10:28:43 +000061try: raise BClass, a
62except TypeError: pass
Guido van Rossum570278b1997-08-05 16:52:50 +000063
Barry Warsaw558f66f1997-08-22 21:28:05 +000064try: raise DClass, a
65except DClass, v:
66 if not isinstance(v, DClass):
Guido van Rossum41360a41998-03-26 19:42:58 +000067 raise TestFailed
Guido van Rossum570278b1997-08-05 16:52:50 +000068
69print '2.3 comparing function objects'
70
71f = eval('lambda: None')
72g = eval('lambda: None')
73if f != g: raise TestFailed
74
75f = eval('lambda a: a')
76g = eval('lambda a: a')
77if f != g: raise TestFailed
78
79f = eval('lambda a=1: a')
80g = eval('lambda a=1: a')
81if f != g: raise TestFailed
82
83f = eval('lambda: 0')
84g = eval('lambda: 1')
85if f == g: raise TestFailed
86
87f = eval('lambda: None')
88g = eval('lambda a: None')
89if f == g: raise TestFailed
90
91f = eval('lambda a: None')
92g = eval('lambda b: None')
93if f == g: raise TestFailed
94
95f = eval('lambda a: None')
96g = eval('lambda a=None: None')
97if f == g: raise TestFailed
98
99f = eval('lambda a=0: None')
100g = eval('lambda a=1: None')
101if f == g: raise TestFailed