Mercurial > cpython-lru_cache-weakref
annotate Lib/test/test_json/test_float.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 | 95cf8640b271 |
| children |
| rev | line source |
|---|---|
|
46676
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
1 import math |
|
85064
95cf8640b271
#18273: move the tests in Lib/test/json_tests to Lib/test/test_json and make them discoverable by unittest. Patch by Zachary Ware.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
80599
diff
changeset
|
2 from test.test_json import PyTest, CTest |
|
46676
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
3 |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
4 |
| 70086 | 5 class TestFloat: |
|
46676
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
6 def test_floats(self): |
|
53667
f686aced02a3
port simplejson upgrade from the trunk #4136
Benjamin Peterson <benjamin@python.org>
parents:
46676
diff
changeset
|
7 for num in [1617161771.7650001, math.pi, math.pi**100, math.pi**-100, 3.1]: |
| 70086 | 8 self.assertEqual(float(self.dumps(num)), num) |
| 9 self.assertEqual(self.loads(self.dumps(num)), num) | |
|
53667
f686aced02a3
port simplejson upgrade from the trunk #4136
Benjamin Peterson <benjamin@python.org>
parents:
46676
diff
changeset
|
10 |
|
f686aced02a3
port simplejson upgrade from the trunk #4136
Benjamin Peterson <benjamin@python.org>
parents:
46676
diff
changeset
|
11 def test_ints(self): |
|
f686aced02a3
port simplejson upgrade from the trunk #4136
Benjamin Peterson <benjamin@python.org>
parents:
46676
diff
changeset
|
12 for num in [1, 1<<32, 1<<64]: |
| 70086 | 13 self.assertEqual(self.dumps(num), str(num)) |
| 14 self.assertEqual(int(self.dumps(num)), num) | |
| 15 | |
|
80599
4f21a9b7decf
#16559: Add more tests for the json module. Patch by Serhiy Storchaka.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
70090
diff
changeset
|
16 def test_out_of_range(self): |
|
4f21a9b7decf
#16559: Add more tests for the json module. Patch by Serhiy Storchaka.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
70090
diff
changeset
|
17 self.assertEqual(self.loads('[23456789012E666]'), [float('inf')]) |
|
4f21a9b7decf
#16559: Add more tests for the json module. Patch by Serhiy Storchaka.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
70090
diff
changeset
|
18 self.assertEqual(self.loads('[-23456789012E666]'), [float('-inf')]) |
|
4f21a9b7decf
#16559: Add more tests for the json module. Patch by Serhiy Storchaka.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
70090
diff
changeset
|
19 |
|
4f21a9b7decf
#16559: Add more tests for the json module. Patch by Serhiy Storchaka.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
70090
diff
changeset
|
20 def test_allow_nan(self): |
|
4f21a9b7decf
#16559: Add more tests for the json module. Patch by Serhiy Storchaka.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
70090
diff
changeset
|
21 for val in (float('inf'), float('-inf'), float('nan')): |
|
4f21a9b7decf
#16559: Add more tests for the json module. Patch by Serhiy Storchaka.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
70090
diff
changeset
|
22 out = self.dumps([val]) |
|
4f21a9b7decf
#16559: Add more tests for the json module. Patch by Serhiy Storchaka.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
70090
diff
changeset
|
23 if val == val: # inf |
|
4f21a9b7decf
#16559: Add more tests for the json module. Patch by Serhiy Storchaka.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
70090
diff
changeset
|
24 self.assertEqual(self.loads(out), [val]) |
|
4f21a9b7decf
#16559: Add more tests for the json module. Patch by Serhiy Storchaka.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
70090
diff
changeset
|
25 else: # nan |
|
4f21a9b7decf
#16559: Add more tests for the json module. Patch by Serhiy Storchaka.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
70090
diff
changeset
|
26 res = self.loads(out) |
|
4f21a9b7decf
#16559: Add more tests for the json module. Patch by Serhiy Storchaka.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
70090
diff
changeset
|
27 self.assertEqual(len(res), 1) |
|
4f21a9b7decf
#16559: Add more tests for the json module. Patch by Serhiy Storchaka.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
70090
diff
changeset
|
28 self.assertNotEqual(res[0], res[0]) |
|
4f21a9b7decf
#16559: Add more tests for the json module. Patch by Serhiy Storchaka.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
70090
diff
changeset
|
29 self.assertRaises(ValueError, self.dumps, [val], allow_nan=False) |
|
4f21a9b7decf
#16559: Add more tests for the json module. Patch by Serhiy Storchaka.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
70090
diff
changeset
|
30 |
| 70086 | 31 |
| 32 class TestPyFloat(TestFloat, PyTest): pass | |
| 33 class TestCFloat(TestFloat, CTest): pass |
