Mercurial > cpython-lru_cache-weakref
annotate Lib/test/test_opcodes.py @ 80661:94de77bd0b4b 2.7
Issue #16194: document imp.load_dynamic problems
when read several extension modules from the same binary object file.
| author | Andrew Svetlov <andrew.svetlov@gmail.com> |
|---|---|
| date | Thu, 29 Nov 2012 19:51:28 +0200 |
| parents | b36cb4602e21 |
| children |
| rev | line source |
|---|---|
| 653 | 1 # Python test set -- part 2, opcodes |
| 2 | |
|
59663
5b888f590fe2
#7092: silence some more py3k warnings.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
58472
diff
changeset
|
3 from test.test_support import run_unittest, check_py3k_warnings |
|
40220
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 |
|
63556
dba99828d91c
Merged revisions 77942,79023 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
47210
diff
changeset
|
12 try: 1 // 0 |
|
40220
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: |
|
58472
6ffcdafa0118
use assert[Not]IsInstance where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents:
58198
diff
changeset
|
67 self.assertIsInstance(v, DClass) |
|
40220
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') |
|
66348
614c84670c63
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
59663
diff
changeset
|
75 self.assertNotEqual(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') |
|
66348
614c84670c63
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
59663
diff
changeset
|
79 self.assertNotEqual(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') |
|
66348
614c84670c63
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
59663
diff
changeset
|
83 self.assertNotEqual(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') |
|
66348
614c84670c63
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
59663
diff
changeset
|
87 self.assertNotEqual(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') |
|
66348
614c84670c63
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
59663
diff
changeset
|
91 self.assertNotEqual(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') |
|
66348
614c84670c63
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
59663
diff
changeset
|
95 self.assertNotEqual(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') |
|
66348
614c84670c63
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
59663
diff
changeset
|
99 self.assertNotEqual(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') |
|
66348
614c84670c63
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
59663
diff
changeset
|
103 self.assertNotEqual(f, g) |
| 2302 | 104 |
|
51759
0848ebb8f9c8
Issue 5176: special-case string formatting in BINARY_MODULO implementation. This shows a modest (1-3%) speed-up in templating systems, for example.
Collin Winter <collinw@gmail.com>
parents:
47210
diff
changeset
|
105 def test_modulo_of_string_subclasses(self): |
|
0848ebb8f9c8
Issue 5176: special-case string formatting in BINARY_MODULO implementation. This shows a modest (1-3%) speed-up in templating systems, for example.
Collin Winter <collinw@gmail.com>
parents:
47210
diff
changeset
|
106 class MyString(str): |
|
0848ebb8f9c8
Issue 5176: special-case string formatting in BINARY_MODULO implementation. This shows a modest (1-3%) speed-up in templating systems, for example.
Collin Winter <collinw@gmail.com>
parents:
47210
diff
changeset
|
107 def __mod__(self, value): |
|
0848ebb8f9c8
Issue 5176: special-case string formatting in BINARY_MODULO implementation. This shows a modest (1-3%) speed-up in templating systems, for example.
Collin Winter <collinw@gmail.com>
parents:
47210
diff
changeset
|
108 return 42 |
|
0848ebb8f9c8
Issue 5176: special-case string formatting in BINARY_MODULO implementation. This shows a modest (1-3%) speed-up in templating systems, for example.
Collin Winter <collinw@gmail.com>
parents:
47210
diff
changeset
|
109 self.assertEqual(MyString() % 3, 42) |
| 2302 | 110 |
| 111 | |
|
40220
7d0bdd6e1c46
Convert test_opcodes to unittest.
Georg Brandl <georg@python.org>
parents:
24442
diff
changeset
|
112 def test_main(): |
|
59663
5b888f590fe2
#7092: silence some more py3k warnings.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
58472
diff
changeset
|
113 with check_py3k_warnings(("exceptions must derive from BaseException", |
|
63556
dba99828d91c
Merged revisions 77942,79023 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
47210
diff
changeset
|
114 DeprecationWarning), |
|
dba99828d91c
Merged revisions 77942,79023 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
47210
diff
changeset
|
115 ("catching classes that don't inherit " |
|
dba99828d91c
Merged revisions 77942,79023 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
47210
diff
changeset
|
116 "from BaseException is not allowed", |
|
dba99828d91c
Merged revisions 77942,79023 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
47210
diff
changeset
|
117 DeprecationWarning)): |
|
dba99828d91c
Merged revisions 77942,79023 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
47210
diff
changeset
|
118 run_unittest(OpcodeTest) |
|
5946
9a56452c7e8e
Add test for function comparisons
Guido van Rossum <guido@python.org>
parents:
2302
diff
changeset
|
119 |
|
40220
7d0bdd6e1c46
Convert test_opcodes to unittest.
Georg Brandl <georg@python.org>
parents:
24442
diff
changeset
|
120 if __name__ == '__main__': |
|
7d0bdd6e1c46
Convert test_opcodes to unittest.
Georg Brandl <georg@python.org>
parents:
24442
diff
changeset
|
121 test_main() |
