0001 # Python test set -- part 2, opcodes 0002 0003 from test.test_support import TestFailed 0004 0005 0006 print '2. Opcodes' 0007 print 'XXX Not yet fully implemented' 0008 0009 print '2.1 try inside for loop' 0010 n = 0 0011 for i in range(10): 0012 n = n+i 0013 try: 1/0 0014 except NameError: pass 0015 except ZeroDivisionError: pass 0016 except TypeError: pass 0017 try: pass 0018 except: pass 0019 try: pass 0020 finally: pass 0021 n = n+i 0022 if n != 90: 0023 raise TestFailed, 'try inside for' 0024 0025 0026 print '2.2 raise class exceptions' 0027 0028 class AClass: pass 0029 class BClass(AClass): pass 0030 class CClass: pass 0031 class DClass(AClass): 0032 def __init__(self, ignore): 0033 pass 0034 0035 try: raise AClass() 0036 except: pass 0037 0038 try: raise AClass() 0039 except AClass: pass 0040 0041 try: raise BClass() 0042 except AClass: pass 0043 0044 try: raise BClass() 0045 except CClass: raise TestFailed 0046 except: pass 0047 0048 a = AClass() 0049 b = BClass() 0050 0051 try: raise AClass, b 0052 except BClass, v: 0053 if v != b: raise TestFailed, "v!=b" 0054 else: raise TestFailed, "no exception" 0055 0056 try: raise b 0057 except AClass, v: 0058 if v != b: raise TestFailed, "v!=b AClass" 0059 0060 # not enough arguments 0061 try: raise BClass, a 0062 except TypeError: pass 0063 0064 try: raise DClass, a 0065 except DClass, v: 0066 if not isinstance(v, DClass): 0067 raise TestFailed, "v not DClass" 0068 0069 print '2.3 comparing function objects' 0070 0071 f = eval('lambda: None') 0072 g = eval('lambda: None') 0073 if f == g: raise TestFailed, "functions should not be same" 0074 0075 f = eval('lambda a: a') 0076 g = eval('lambda a: a') 0077 if f == g: raise TestFailed, "functions should not be same" 0078 0079 f = eval('lambda a=1: a') 0080 g = eval('lambda a=1: a') 0081 if f == g: raise TestFailed, "functions should not be same" 0082 0083 f = eval('lambda: 0') 0084 g = eval('lambda: 1') 0085 if f == g: raise TestFailed 0086 0087 f = eval('lambda: None') 0088 g = eval('lambda a: None') 0089 if f == g: raise TestFailed 0090 0091 f = eval('lambda a: None') 0092 g = eval('lambda b: None') 0093 if f == g: raise TestFailed 0094 0095 f = eval('lambda a: None') 0096 g = eval('lambda a=None: None') 0097 if f == g: raise TestFailed 0098 0099 f = eval('lambda a=0: None') 0100 g = eval('lambda a=1: None') 0101 if f == g: raise TestFailed 0102
Generated by PyXR 0.9.4