Mercurial > cpython-lru_cache-weakref
annotate Lib/test/test_opcodes.py @ 58925:eecf1bef052d 2.6
Merged revisions 78207 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r78207 | ezio.melotti | 2010-02-17 01:26:09 +0200 (Wed, 17 Feb 2010) | 1 line
#7930: fix stripid
........
| author | Ezio Melotti <ezio.melotti@gmail.com> |
|---|---|
| date | Tue, 16 Feb 2010 23:29:44 +0000 |
| parents | 2c34f19e3922 |
| children | dba99828d91c 0848ebb8f9c8 |
| rev | line source |
|---|---|
| 653 | 1 # Python test set -- part 2, opcodes |
| 2 | |
|
40220
7d0bdd6e1c46
Convert test_opcodes to unittest.
Georg Brandl <georg@python.org>
parents:
24442
diff
changeset
|
3 from test.test_support import run_unittest |
|
7d0bdd6e1c46
Convert test_opcodes to unittest.
Georg Brandl <georg@python.org>
parents:
24442
diff
changeset
|
4 import unittest |
|
7d0bdd6e1c46
Convert test_opcodes to unittest.
Georg Brandl <georg@python.org>
parents:
24442
diff
changeset
|
5 |
|
7d0bdd6e1c46
Convert test_opcodes to unittest.
Georg Brandl <georg@python.org>
parents:
24442
diff
changeset
|
6 class OpcodeTest(unittest.TestCase): |
| 653 | 7 |
|
40220
7d0bdd6e1c46
Convert test_opcodes to unittest.
Georg Brandl <georg@python.org>
parents:
24442
diff
changeset
|
8 def test_try_inside_for_loop(self): |
|
7d0bdd6e1c46
Convert test_opcodes to unittest.
Georg Brandl <georg@python.org>
parents:
24442
diff
changeset
|
9 n = 0 |
|
7d0bdd6e1c46
Convert test_opcodes to unittest.
Georg Brandl <georg@python.org>
parents:
24442
diff
changeset
|
10 for i in range(10): |
|
7d0bdd6e1c46
Convert test_opcodes to unittest.
Georg Brandl <georg@python.org>
parents:
24442
diff
changeset
|
11 n = n+i |
|
7d0bdd6e1c46
Convert test_opcodes to unittest.
Georg Brandl <georg@python.org>
parents:
24442
diff
changeset
|
12 try: 1/0 |
|
7d0bdd6e1c46
Convert test_opcodes to unittest.
Georg Brandl <georg@python.org>
parents:
24442
diff
changeset
|
13 except NameError: pass |
|
7d0bdd6e1c46
Convert test_opcodes to unittest.
Georg Brandl <georg@python.org>
parents:
24442
diff
changeset
|
14 except ZeroDivisionError: pass |
|
7d0bdd6e1c46
Convert test_opcodes to unittest.
Georg Brandl <georg@python.org>
parents:
24442
diff
changeset
|
15 except TypeError: pass |
|
7d0bdd6e1c46
Convert test_opcodes to unittest.
Georg Brandl <georg@python.org>
parents:
24442
diff
changeset
|
16 try: pass |
|
7d0bdd6e1c46
Convert test_opcodes to unittest.
Georg Brandl <georg@python.org>
parents:
24442
diff
changeset
|
17 except: pass |
|
7d0bdd6e1c46
Convert test_opcodes to unittest.
Georg Brandl <georg@python.org>
parents:
24442
diff
changeset
|
18 try: pass |
|
7d0bdd6e1c46
Convert test_opcodes to unittest.
Georg Brandl <georg@python.org>
parents:
24442
diff
changeset
|
19 finally: pass |
|
7d0bdd6e1c46
Convert test_opcodes to unittest.
Georg Brandl <georg@python.org>
parents:
24442
diff
changeset
|
20 n = n+i |
|
7d0bdd6e1c46
Convert test_opcodes to unittest.
Georg Brandl <georg@python.org>
parents:
24442
diff
changeset
|
21 if n != 90: |
|
7d0bdd6e1c46
Convert test_opcodes to unittest.
Georg Brandl <georg@python.org>
parents:
24442
diff
changeset
|
22 self.fail('try inside for') |
|
7d0bdd6e1c46
Convert test_opcodes to unittest.
Georg Brandl <georg@python.org>
parents:
24442
diff
changeset
|
23 |
|
7d0bdd6e1c46
Convert test_opcodes to unittest.
Georg Brandl <georg@python.org>
parents:
24442
diff
changeset
|
24 def test_raise_class_exceptions(self): |
| 653 | 25 |
|
40220
7d0bdd6e1c46
Convert test_opcodes to unittest.
Georg Brandl <georg@python.org>
parents:
24442
diff
changeset
|
26 class AClass: pass |
|
7d0bdd6e1c46
Convert test_opcodes to unittest.
Georg Brandl <georg@python.org>
parents:
24442
diff
changeset
|
27 class BClass(AClass): pass |
|
7d0bdd6e1c46
Convert test_opcodes to unittest.
Georg Brandl <georg@python.org>
parents:
24442
diff
changeset
|
28 class CClass: pass |
|
7d0bdd6e1c46
Convert test_opcodes to unittest.
Georg Brandl <georg@python.org>
parents:
24442
diff
changeset
|
29 class DClass(AClass): |
|
7d0bdd6e1c46
Convert test_opcodes to unittest.
Georg Brandl <georg@python.org>
parents:
24442
diff
changeset
|
30 def __init__(self, ignore): |
|
7d0bdd6e1c46
Convert test_opcodes to unittest.
Georg Brandl <georg@python.org>
parents:
24442
diff
changeset
|
31 pass |
|
7d0bdd6e1c46
Convert test_opcodes to unittest.
Georg Brandl <georg@python.org>
parents:
24442
diff
changeset
|
32 |
|
7d0bdd6e1c46
Convert test_opcodes to unittest.
Georg Brandl <georg@python.org>
parents:
24442
diff
changeset
|
33 try: raise AClass() |
|
7d0bdd6e1c46
Convert test_opcodes to unittest.
Georg Brandl <georg@python.org>
parents:
24442
diff
changeset
|
34 except: pass |
|
7d0bdd6e1c46
Convert test_opcodes to unittest.
Georg Brandl <georg@python.org>
parents:
24442
diff
changeset
|
35 |
|
7d0bdd6e1c46
Convert test_opcodes to unittest.
Georg Brandl <georg@python.org>
parents:
24442
diff
changeset
|
36 try: raise AClass() |
|
7d0bdd6e1c46
Convert test_opcodes to unittest.
Georg Brandl <georg@python.org>
parents:
24442
diff
changeset
|
37 except AClass: pass |
|
7d0bdd6e1c46
Convert test_opcodes to unittest.
Georg Brandl <georg@python.org>
parents:
24442
diff
changeset
|
38 |
|
7d0bdd6e1c46
Convert test_opcodes to unittest.
Georg Brandl <georg@python.org>
parents:
24442
diff
changeset
|
39 try: raise BClass() |
|
7d0bdd6e1c46
Convert test_opcodes to unittest.
Georg Brandl <georg@python.org>
parents:
24442
diff
changeset
|
40 except AClass: pass |
|
7d0bdd6e1c46
Convert test_opcodes to unittest.
Georg Brandl <georg@python.org>
parents:
24442
diff
changeset
|
41 |
|
7d0bdd6e1c46
Convert test_opcodes to unittest.
Georg Brandl <georg@python.org>
parents:
24442
diff
changeset
|
42 try: raise BClass() |
|
7d0bdd6e1c46
Convert test_opcodes to unittest.
Georg Brandl <georg@python.org>
parents:
24442
diff
changeset
|
43 except CClass: self.fail() |
|
7d0bdd6e1c46
Convert test_opcodes to unittest.
Georg Brandl <georg@python.org>
parents:
24442
diff
changeset
|
44 except: pass |
|
7d0bdd6e1c46
Convert test_opcodes to unittest.
Georg Brandl <georg@python.org>
parents:
24442
diff
changeset
|
45 |
|
7d0bdd6e1c46
Convert test_opcodes to unittest.
Georg Brandl <georg@python.org>
parents:
24442
diff
changeset
|
46 a = AClass() |
|
7d0bdd6e1c46
Convert test_opcodes to unittest.
Georg Brandl <georg@python.org>
parents:
24442
diff
changeset
|
47 b = BClass() |
|
7d0bdd6e1c46
Convert test_opcodes to unittest.
Georg Brandl <georg@python.org>
parents:
24442
diff
changeset
|
48 |
|
7d0bdd6e1c46
Convert test_opcodes to unittest.
Georg Brandl <georg@python.org>
parents:
24442
diff
changeset
|
49 try: raise AClass, b |
|
7d0bdd6e1c46
Convert test_opcodes to unittest.
Georg Brandl <georg@python.org>
parents:
24442
diff
changeset
|
50 except BClass, v: |
|
47210
2c34f19e3922
use more specific asserts in test_opcode
Benjamin Peterson <benjamin@python.org>
parents:
40220
diff
changeset
|
51 self.assertEqual(v, b) |
|
40220
7d0bdd6e1c46
Convert test_opcodes to unittest.
Georg Brandl <georg@python.org>
parents:
24442
diff
changeset
|
52 else: self.fail("no exception") |
| 653 | 53 |
|
40220
7d0bdd6e1c46
Convert test_opcodes to unittest.
Georg Brandl <georg@python.org>
parents:
24442
diff
changeset
|
54 try: raise b |
|
7d0bdd6e1c46
Convert test_opcodes to unittest.
Georg Brandl <georg@python.org>
parents:
24442
diff
changeset
|
55 except AClass, v: |
|
47210
2c34f19e3922
use more specific asserts in test_opcode
Benjamin Peterson <benjamin@python.org>
parents:
40220
diff
changeset
|
56 self.assertEqual(v, b) |
|
40220
7d0bdd6e1c46
Convert test_opcodes to unittest.
Georg Brandl <georg@python.org>
parents:
24442
diff
changeset
|
57 else: |
|
7d0bdd6e1c46
Convert test_opcodes to unittest.
Georg Brandl <georg@python.org>
parents:
24442
diff
changeset
|
58 self.fail("no exception") |
|
7d0bdd6e1c46
Convert test_opcodes to unittest.
Georg Brandl <georg@python.org>
parents:
24442
diff
changeset
|
59 |
|
7d0bdd6e1c46
Convert test_opcodes to unittest.
Georg Brandl <georg@python.org>
parents:
24442
diff
changeset
|
60 # not enough arguments |
|
7d0bdd6e1c46
Convert test_opcodes to unittest.
Georg Brandl <georg@python.org>
parents:
24442
diff
changeset
|
61 try: raise BClass, a |
|
7d0bdd6e1c46
Convert test_opcodes to unittest.
Georg Brandl <georg@python.org>
parents:
24442
diff
changeset
|
62 except TypeError: pass |
|
7d0bdd6e1c46
Convert test_opcodes to unittest.
Georg Brandl <georg@python.org>
parents:
24442
diff
changeset
|
63 else: self.fail("no exception") |
|
7d0bdd6e1c46
Convert test_opcodes to unittest.
Georg Brandl <georg@python.org>
parents:
24442
diff
changeset
|
64 |
|
7d0bdd6e1c46
Convert test_opcodes to unittest.
Georg Brandl <georg@python.org>
parents:
24442
diff
changeset
|
65 try: raise DClass, a |
|
7d0bdd6e1c46
Convert test_opcodes to unittest.
Georg Brandl <georg@python.org>
parents:
24442
diff
changeset
|
66 except DClass, v: |
|
7d0bdd6e1c46
Convert test_opcodes to unittest.
Georg Brandl <georg@python.org>
parents:
24442
diff
changeset
|
67 self.assert_(isinstance(v, DClass)) |
|
7d0bdd6e1c46
Convert test_opcodes to unittest.
Georg Brandl <georg@python.org>
parents:
24442
diff
changeset
|
68 else: |
|
7d0bdd6e1c46
Convert test_opcodes to unittest.
Georg Brandl <georg@python.org>
parents:
24442
diff
changeset
|
69 self.fail("no exception") |
|
7d0bdd6e1c46
Convert test_opcodes to unittest.
Georg Brandl <georg@python.org>
parents:
24442
diff
changeset
|
70 |
|
7d0bdd6e1c46
Convert test_opcodes to unittest.
Georg Brandl <georg@python.org>
parents:
24442
diff
changeset
|
71 def test_compare_function_objects(self): |
|
7d0bdd6e1c46
Convert test_opcodes to unittest.
Georg Brandl <georg@python.org>
parents:
24442
diff
changeset
|
72 |
|
7d0bdd6e1c46
Convert test_opcodes to unittest.
Georg Brandl <georg@python.org>
parents:
24442
diff
changeset
|
73 f = eval('lambda: None') |
|
7d0bdd6e1c46
Convert test_opcodes to unittest.
Georg Brandl <georg@python.org>
parents:
24442
diff
changeset
|
74 g = eval('lambda: None') |
|
47210
2c34f19e3922
use more specific asserts in test_opcode
Benjamin Peterson <benjamin@python.org>
parents:
40220
diff
changeset
|
75 self.assertNotEquals(f, g) |
|
40220
7d0bdd6e1c46
Convert test_opcodes to unittest.
Georg Brandl <georg@python.org>
parents:
24442
diff
changeset
|
76 |
|
7d0bdd6e1c46
Convert test_opcodes to unittest.
Georg Brandl <georg@python.org>
parents:
24442
diff
changeset
|
77 f = eval('lambda a: a') |
|
7d0bdd6e1c46
Convert test_opcodes to unittest.
Georg Brandl <georg@python.org>
parents:
24442
diff
changeset
|
78 g = eval('lambda a: a') |
|
47210
2c34f19e3922
use more specific asserts in test_opcode
Benjamin Peterson <benjamin@python.org>
parents:
40220
diff
changeset
|
79 self.assertNotEquals(f, g) |
|
40220
7d0bdd6e1c46
Convert test_opcodes to unittest.
Georg Brandl <georg@python.org>
parents:
24442
diff
changeset
|
80 |
|
7d0bdd6e1c46
Convert test_opcodes to unittest.
Georg Brandl <georg@python.org>
parents:
24442
diff
changeset
|
81 f = eval('lambda a=1: a') |
|
7d0bdd6e1c46
Convert test_opcodes to unittest.
Georg Brandl <georg@python.org>
parents:
24442
diff
changeset
|
82 g = eval('lambda a=1: a') |
|
47210
2c34f19e3922
use more specific asserts in test_opcode
Benjamin Peterson <benjamin@python.org>
parents:
40220
diff
changeset
|
83 self.assertNotEquals(f, g) |
|
40220
7d0bdd6e1c46
Convert test_opcodes to unittest.
Georg Brandl <georg@python.org>
parents:
24442
diff
changeset
|
84 |
|
7d0bdd6e1c46
Convert test_opcodes to unittest.
Georg Brandl <georg@python.org>
parents:
24442
diff
changeset
|
85 f = eval('lambda: 0') |
|
7d0bdd6e1c46
Convert test_opcodes to unittest.
Georg Brandl <georg@python.org>
parents:
24442
diff
changeset
|
86 g = eval('lambda: 1') |
|
47210
2c34f19e3922
use more specific asserts in test_opcode
Benjamin Peterson <benjamin@python.org>
parents:
40220
diff
changeset
|
87 self.assertNotEquals(f, g) |
|
40220
7d0bdd6e1c46
Convert test_opcodes to unittest.
Georg Brandl <georg@python.org>
parents:
24442
diff
changeset
|
88 |
|
7d0bdd6e1c46
Convert test_opcodes to unittest.
Georg Brandl <georg@python.org>
parents:
24442
diff
changeset
|
89 f = eval('lambda: None') |
|
7d0bdd6e1c46
Convert test_opcodes to unittest.
Georg Brandl <georg@python.org>
parents:
24442
diff
changeset
|
90 g = eval('lambda a: None') |
|
47210
2c34f19e3922
use more specific asserts in test_opcode
Benjamin Peterson <benjamin@python.org>
parents:
40220
diff
changeset
|
91 self.assertNotEquals(f, g) |
|
40220
7d0bdd6e1c46
Convert test_opcodes to unittest.
Georg Brandl <georg@python.org>
parents:
24442
diff
changeset
|
92 |
|
7d0bdd6e1c46
Convert test_opcodes to unittest.
Georg Brandl <georg@python.org>
parents:
24442
diff
changeset
|
93 f = eval('lambda a: None') |
|
7d0bdd6e1c46
Convert test_opcodes to unittest.
Georg Brandl <georg@python.org>
parents:
24442
diff
changeset
|
94 g = eval('lambda b: None') |
|
47210
2c34f19e3922
use more specific asserts in test_opcode
Benjamin Peterson <benjamin@python.org>
parents:
40220
diff
changeset
|
95 self.assertNotEquals(f, g) |
|
40220
7d0bdd6e1c46
Convert test_opcodes to unittest.
Georg Brandl <georg@python.org>
parents:
24442
diff
changeset
|
96 |
|
7d0bdd6e1c46
Convert test_opcodes to unittest.
Georg Brandl <georg@python.org>
parents:
24442
diff
changeset
|
97 f = eval('lambda a: None') |
|
7d0bdd6e1c46
Convert test_opcodes to unittest.
Georg Brandl <georg@python.org>
parents:
24442
diff
changeset
|
98 g = eval('lambda a=None: None') |
|
47210
2c34f19e3922
use more specific asserts in test_opcode
Benjamin Peterson <benjamin@python.org>
parents:
40220
diff
changeset
|
99 self.assertNotEquals(f, g) |
|
40220
7d0bdd6e1c46
Convert test_opcodes to unittest.
Georg Brandl <georg@python.org>
parents:
24442
diff
changeset
|
100 |
|
7d0bdd6e1c46
Convert test_opcodes to unittest.
Georg Brandl <georg@python.org>
parents:
24442
diff
changeset
|
101 f = eval('lambda a=0: None') |
|
7d0bdd6e1c46
Convert test_opcodes to unittest.
Georg Brandl <georg@python.org>
parents:
24442
diff
changeset
|
102 g = eval('lambda a=1: None') |
|
47210
2c34f19e3922
use more specific asserts in test_opcode
Benjamin Peterson <benjamin@python.org>
parents:
40220
diff
changeset
|
103 self.assertNotEquals(f, g) |
| 2302 | 104 |
| 105 | |
|
40220
7d0bdd6e1c46
Convert test_opcodes to unittest.
Georg Brandl <georg@python.org>
parents:
24442
diff
changeset
|
106 def test_main(): |
|
7d0bdd6e1c46
Convert test_opcodes to unittest.
Georg Brandl <georg@python.org>
parents:
24442
diff
changeset
|
107 run_unittest(OpcodeTest) |
|
5946
9a56452c7e8e
Add test for function comparisons
Guido van Rossum <guido@python.org>
parents:
2302
diff
changeset
|
108 |
|
40220
7d0bdd6e1c46
Convert test_opcodes to unittest.
Georg Brandl <georg@python.org>
parents:
24442
diff
changeset
|
109 if __name__ == '__main__': |
|
7d0bdd6e1c46
Convert test_opcodes to unittest.
Georg Brandl <georg@python.org>
parents:
24442
diff
changeset
|
110 test_main() |
