annotate Lib/test/test__opcode.py @ 87690:66c1c9f32567 default tip

Add use_weakref option to functools.lru_cache The use_weakref option makes lru_cache create weak references to the function arguments when creating the cache key, which prevents them from staying in the memory forever even after all other references to them are gone. This is a proof of concept for http://bugs.python.org/issue19859
author Radomir Dopieralski <devel@sheep.art.pl>
date Tue, 03 Dec 2013 16:02:48 +0100
parents 895cf5801f4c
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
87465
5fe72b9ed48e Issue #19722: Added opcode.stack_effect(), which accurately
Larry Hastings <larry@hastings.org>
parents:
diff changeset
1 import dis
87472
895cf5801f4c Don't attempt to run the _opcode test if it wasn't built.
Larry Hastings <larry@hastings.org>
parents: 87465
diff changeset
2 from test.support import run_unittest, import_module
87465
5fe72b9ed48e Issue #19722: Added opcode.stack_effect(), which accurately
Larry Hastings <larry@hastings.org>
parents:
diff changeset
3 import unittest
5fe72b9ed48e Issue #19722: Added opcode.stack_effect(), which accurately
Larry Hastings <larry@hastings.org>
parents:
diff changeset
4
87472
895cf5801f4c Don't attempt to run the _opcode test if it wasn't built.
Larry Hastings <larry@hastings.org>
parents: 87465
diff changeset
5 _opcode = import_module("_opcode")
895cf5801f4c Don't attempt to run the _opcode test if it wasn't built.
Larry Hastings <larry@hastings.org>
parents: 87465
diff changeset
6
87465
5fe72b9ed48e Issue #19722: Added opcode.stack_effect(), which accurately
Larry Hastings <larry@hastings.org>
parents:
diff changeset
7 class OpcodeTests(unittest.TestCase):
5fe72b9ed48e Issue #19722: Added opcode.stack_effect(), which accurately
Larry Hastings <larry@hastings.org>
parents:
diff changeset
8
5fe72b9ed48e Issue #19722: Added opcode.stack_effect(), which accurately
Larry Hastings <larry@hastings.org>
parents:
diff changeset
9 def test_stack_effect(self):
5fe72b9ed48e Issue #19722: Added opcode.stack_effect(), which accurately
Larry Hastings <larry@hastings.org>
parents:
diff changeset
10 self.assertEqual(_opcode.stack_effect(dis.opmap['POP_TOP']), -1)
5fe72b9ed48e Issue #19722: Added opcode.stack_effect(), which accurately
Larry Hastings <larry@hastings.org>
parents:
diff changeset
11 self.assertEqual(_opcode.stack_effect(dis.opmap['DUP_TOP_TWO']), 2)
5fe72b9ed48e Issue #19722: Added opcode.stack_effect(), which accurately
Larry Hastings <larry@hastings.org>
parents:
diff changeset
12 self.assertEqual(_opcode.stack_effect(dis.opmap['BUILD_SLICE'], 0), -1)
5fe72b9ed48e Issue #19722: Added opcode.stack_effect(), which accurately
Larry Hastings <larry@hastings.org>
parents:
diff changeset
13 self.assertEqual(_opcode.stack_effect(dis.opmap['BUILD_SLICE'], 1), -1)
5fe72b9ed48e Issue #19722: Added opcode.stack_effect(), which accurately
Larry Hastings <larry@hastings.org>
parents:
diff changeset
14 self.assertEqual(_opcode.stack_effect(dis.opmap['BUILD_SLICE'], 3), -2)
5fe72b9ed48e Issue #19722: Added opcode.stack_effect(), which accurately
Larry Hastings <larry@hastings.org>
parents:
diff changeset
15 self.assertRaises(ValueError, _opcode.stack_effect, 30000)
5fe72b9ed48e Issue #19722: Added opcode.stack_effect(), which accurately
Larry Hastings <larry@hastings.org>
parents:
diff changeset
16 self.assertRaises(ValueError, _opcode.stack_effect, dis.opmap['BUILD_SLICE'])
5fe72b9ed48e Issue #19722: Added opcode.stack_effect(), which accurately
Larry Hastings <larry@hastings.org>
parents:
diff changeset
17 self.assertRaises(ValueError, _opcode.stack_effect, dis.opmap['POP_TOP'], 0)
5fe72b9ed48e Issue #19722: Added opcode.stack_effect(), which accurately
Larry Hastings <larry@hastings.org>
parents:
diff changeset
18
5fe72b9ed48e Issue #19722: Added opcode.stack_effect(), which accurately
Larry Hastings <larry@hastings.org>
parents:
diff changeset
19 def test_main():
5fe72b9ed48e Issue #19722: Added opcode.stack_effect(), which accurately
Larry Hastings <larry@hastings.org>
parents:
diff changeset
20 run_unittest(OpcodeTests)
5fe72b9ed48e Issue #19722: Added opcode.stack_effect(), which accurately
Larry Hastings <larry@hastings.org>
parents:
diff changeset
21
5fe72b9ed48e Issue #19722: Added opcode.stack_effect(), which accurately
Larry Hastings <larry@hastings.org>
parents:
diff changeset
22 if __name__ == "__main__":
5fe72b9ed48e Issue #19722: Added opcode.stack_effect(), which accurately
Larry Hastings <larry@hastings.org>
parents:
diff changeset
23 test_main()