blob: c1929637ac093a6578af0b6a281697dffec33efe [file] [log] [blame]
Guido van Rossum3bead091992-01-27 17:00:37 +00001# Python test set -- part 2, opcodes
2
Barry Warsaw408b6d32002-07-30 23:27:12 +00003from test.test_support import TestFailed
Guido van Rossum3bead091992-01-27 17:00:37 +00004
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):
Fred Drake004d5e62000-10-23 17:22:08 +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
Fred Drake132dce22000-12-12 23:11:42 +000022if n != 90:
Fred Drake004d5e62000-10-23 17:22:08 +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:
Moshe Zadka497671e2001-01-29 06:21:17 +000053 if v != b: raise TestFailed, "v!=b"
54else: raise TestFailed, "no exception"
Guido van Rossum6de668f1995-02-09 10:28:43 +000055
56try: raise b
57except AClass, v:
Moshe Zadka497671e2001-01-29 06:21:17 +000058 if v != b: raise TestFailed, "v!=b AClass"
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):
Moshe Zadka497671e2001-01-29 06:21:17 +000067 raise TestFailed, "v not DClass"
Guido van Rossum570278b1997-08-05 16:52:50 +000068
69print '2.3 comparing function objects'
70
71f = eval('lambda: None')
72g = eval('lambda: None')
Moshe Zadka497671e2001-01-29 06:21:17 +000073if f == g: raise TestFailed, "functions should not be same"
Guido van Rossum570278b1997-08-05 16:52:50 +000074
75f = eval('lambda a: a')
76g = eval('lambda a: a')
Moshe Zadka497671e2001-01-29 06:21:17 +000077if f == g: raise TestFailed, "functions should not be same"
Guido van Rossum570278b1997-08-05 16:52:50 +000078
79f = eval('lambda a=1: a')
80g = eval('lambda a=1: a')
Moshe Zadka497671e2001-01-29 06:21:17 +000081if f == g: raise TestFailed, "functions should not be same"
Guido van Rossum570278b1997-08-05 16:52:50 +000082
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