Mercurial > cpython-lru_cache-weakref
annotate Lib/test/test_future3.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 | 83ae10bf608c |
| children |
| rev | line source |
|---|---|
|
19409
bc9c8cebc2ef
Add test case to cover multiple future statements on separate lines of
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
1 from __future__ import nested_scopes |
|
bc9c8cebc2ef
Add test case to cover multiple future statements on separate lines of
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
2 from __future__ import division |
|
29872
1a42b128c581
Fixed test and converted to unittest format.
Raymond Hettinger <python@rcn.com>
parents:
19409
diff
changeset
|
3 |
|
1a42b128c581
Fixed test and converted to unittest format.
Raymond Hettinger <python@rcn.com>
parents:
19409
diff
changeset
|
4 import unittest |
|
19409
bc9c8cebc2ef
Add test case to cover multiple future statements on separate lines of
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
5 |
|
29872
1a42b128c581
Fixed test and converted to unittest format.
Raymond Hettinger <python@rcn.com>
parents:
19409
diff
changeset
|
6 x = 2 |
|
1a42b128c581
Fixed test and converted to unittest format.
Raymond Hettinger <python@rcn.com>
parents:
19409
diff
changeset
|
7 def nester(): |
|
1a42b128c581
Fixed test and converted to unittest format.
Raymond Hettinger <python@rcn.com>
parents:
19409
diff
changeset
|
8 x = 3 |
|
1a42b128c581
Fixed test and converted to unittest format.
Raymond Hettinger <python@rcn.com>
parents:
19409
diff
changeset
|
9 def inner(): |
|
1a42b128c581
Fixed test and converted to unittest format.
Raymond Hettinger <python@rcn.com>
parents:
19409
diff
changeset
|
10 return x |
|
1a42b128c581
Fixed test and converted to unittest format.
Raymond Hettinger <python@rcn.com>
parents:
19409
diff
changeset
|
11 return inner() |
|
19409
bc9c8cebc2ef
Add test case to cover multiple future statements on separate lines of
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
12 |
|
bc9c8cebc2ef
Add test case to cover multiple future statements on separate lines of
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
13 |
|
29872
1a42b128c581
Fixed test and converted to unittest format.
Raymond Hettinger <python@rcn.com>
parents:
19409
diff
changeset
|
14 class TestFuture(unittest.TestCase): |
|
1a42b128c581
Fixed test and converted to unittest format.
Raymond Hettinger <python@rcn.com>
parents:
19409
diff
changeset
|
15 |
|
1a42b128c581
Fixed test and converted to unittest format.
Raymond Hettinger <python@rcn.com>
parents:
19409
diff
changeset
|
16 def test_floor_div_operator(self): |
|
1a42b128c581
Fixed test and converted to unittest format.
Raymond Hettinger <python@rcn.com>
parents:
19409
diff
changeset
|
17 self.assertEqual(7 // 2, 3) |
|
1a42b128c581
Fixed test and converted to unittest format.
Raymond Hettinger <python@rcn.com>
parents:
19409
diff
changeset
|
18 |
|
1a42b128c581
Fixed test and converted to unittest format.
Raymond Hettinger <python@rcn.com>
parents:
19409
diff
changeset
|
19 def test_true_div_as_default(self): |
|
1a42b128c581
Fixed test and converted to unittest format.
Raymond Hettinger <python@rcn.com>
parents:
19409
diff
changeset
|
20 self.assertAlmostEqual(7 / 2, 3.5) |
|
1a42b128c581
Fixed test and converted to unittest format.
Raymond Hettinger <python@rcn.com>
parents:
19409
diff
changeset
|
21 |
|
1a42b128c581
Fixed test and converted to unittest format.
Raymond Hettinger <python@rcn.com>
parents:
19409
diff
changeset
|
22 def test_nested_scopes(self): |
|
1a42b128c581
Fixed test and converted to unittest format.
Raymond Hettinger <python@rcn.com>
parents:
19409
diff
changeset
|
23 self.assertEqual(nester(), 3) |
|
1a42b128c581
Fixed test and converted to unittest format.
Raymond Hettinger <python@rcn.com>
parents:
19409
diff
changeset
|
24 |
|
1a42b128c581
Fixed test and converted to unittest format.
Raymond Hettinger <python@rcn.com>
parents:
19409
diff
changeset
|
25 if __name__ == "__main__": |
|
82409
83ae10bf608c
#17303: test_future* now work with unittest test discovery. Patch by Zachary Ware.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
47201
diff
changeset
|
26 unittest.main() |
