1 # Python test set -- part 2, opcodes
3 from test
.test_support
import run_unittest
6 class OpcodeTest(unittest
.TestCase
):
8 def test_try_inside_for_loop(self
):
13 except NameError: pass
14 except ZeroDivisionError: pass
15 except TypeError: pass
22 self
.fail('try inside for')
24 def test_raise_class_exceptions(self
):
27 class BClass(AClass
): pass
30 def __init__(self
, ignore
):
43 except CClass
: self
.fail()
51 self
.assertEqual(v
, b
)
52 else: self
.fail("no exception")
56 self
.assertEqual(v
, b
)
58 self
.fail("no exception")
60 # not enough arguments
62 except TypeError: pass
63 else: self
.fail("no exception")
67 self
.assertTrue(isinstance(v
, DClass
))
69 self
.fail("no exception")
71 def test_compare_function_objects(self
):
73 f
= eval('lambda: None')
74 g
= eval('lambda: None')
75 self
.assertNotEquals(f
, g
)
77 f
= eval('lambda a: a')
78 g
= eval('lambda a: a')
79 self
.assertNotEquals(f
, g
)
81 f
= eval('lambda a=1: a')
82 g
= eval('lambda a=1: a')
83 self
.assertNotEquals(f
, g
)
87 self
.assertNotEquals(f
, g
)
89 f
= eval('lambda: None')
90 g
= eval('lambda a: None')
91 self
.assertNotEquals(f
, g
)
93 f
= eval('lambda a: None')
94 g
= eval('lambda b: None')
95 self
.assertNotEquals(f
, g
)
97 f
= eval('lambda a: None')
98 g
= eval('lambda a=None: None')
99 self
.assertNotEquals(f
, g
)
101 f
= eval('lambda a=0: None')
102 g
= eval('lambda a=1: None')
103 self
.assertNotEquals(f
, g
)
105 def test_modulo_of_string_subclasses(self
):
107 def __mod__(self
, value
):
109 self
.assertEqual(MyString() % 3, 42)
113 run_unittest(OpcodeTest
)
115 if __name__
== '__main__':