annotate Lib/json/tests/test_float.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 e092ff374721
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
70084
5b0fecd2eba0 #5723: Improve json tests to be executed with and without accelerations.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 66348
diff changeset
2 from json.tests 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
70084
5b0fecd2eba0 #5723: Improve json tests to be executed with and without accelerations.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 66348
diff changeset
5 class TestFloat(object):
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):
52427
685f1791fbc5 Issue 5381: fix regression in pure python code path, Issue 5584: fix a decoder bug for unicode float literals outside of a container
Bob Ippolito <bob@redivi.com>
parents: 52199
diff changeset
7 for num in [1617161771.7650001, math.pi, math.pi**100,
685f1791fbc5 Issue 5381: fix regression in pure python code path, Issue 5584: fix a decoder bug for unicode float literals outside of a container
Bob Ippolito <bob@redivi.com>
parents: 52199
diff changeset
8 math.pi**-100, 3.1]:
70084
5b0fecd2eba0 #5723: Improve json tests to be executed with and without accelerations.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 66348
diff changeset
9 self.assertEqual(float(self.dumps(num)), num)
5b0fecd2eba0 #5723: Improve json tests to be executed with and without accelerations.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 66348
diff changeset
10 self.assertEqual(self.loads(self.dumps(num)), num)
5b0fecd2eba0 #5723: Improve json tests to be executed with and without accelerations.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 66348
diff changeset
11 self.assertEqual(self.loads(unicode(self.dumps(num))), num)
52199
d95e5add3ca4 merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents: 46676
diff changeset
12
d95e5add3ca4 merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents: 46676
diff changeset
13 def test_ints(self):
d95e5add3ca4 merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents: 46676
diff changeset
14 for num in [1, 1L, 1<<32, 1<<64]:
70084
5b0fecd2eba0 #5723: Improve json tests to be executed with and without accelerations.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 66348
diff changeset
15 self.assertEqual(self.dumps(num), str(num))
5b0fecd2eba0 #5723: Improve json tests to be executed with and without accelerations.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 66348
diff changeset
16 self.assertEqual(int(self.dumps(num)), num)
5b0fecd2eba0 #5723: Improve json tests to be executed with and without accelerations.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 66348
diff changeset
17 self.assertEqual(self.loads(self.dumps(num)), num)
5b0fecd2eba0 #5723: Improve json tests to be executed with and without accelerations.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 66348
diff changeset
18 self.assertEqual(self.loads(unicode(self.dumps(num))), num)
5b0fecd2eba0 #5723: Improve json tests to be executed with and without accelerations.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 66348
diff changeset
19
80598
e092ff374721 #16559: Add more tests for the json module. Patch by Serhiy Storchaka.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 70084
diff changeset
20 def test_out_of_range(self):
e092ff374721 #16559: Add more tests for the json module. Patch by Serhiy Storchaka.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 70084
diff changeset
21 self.assertEqual(self.loads('[23456789012E666]'), [float('inf')])
e092ff374721 #16559: Add more tests for the json module. Patch by Serhiy Storchaka.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 70084
diff changeset
22 self.assertEqual(self.loads('[-23456789012E666]'), [float('-inf')])
e092ff374721 #16559: Add more tests for the json module. Patch by Serhiy Storchaka.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 70084
diff changeset
23
e092ff374721 #16559: Add more tests for the json module. Patch by Serhiy Storchaka.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 70084
diff changeset
24 def test_allow_nan(self):
e092ff374721 #16559: Add more tests for the json module. Patch by Serhiy Storchaka.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 70084
diff changeset
25 for val in (float('inf'), float('-inf'), float('nan')):
e092ff374721 #16559: Add more tests for the json module. Patch by Serhiy Storchaka.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 70084
diff changeset
26 out = self.dumps([val])
e092ff374721 #16559: Add more tests for the json module. Patch by Serhiy Storchaka.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 70084
diff changeset
27 if val == val: # inf
e092ff374721 #16559: Add more tests for the json module. Patch by Serhiy Storchaka.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 70084
diff changeset
28 self.assertEqual(self.loads(out), [val])
e092ff374721 #16559: Add more tests for the json module. Patch by Serhiy Storchaka.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 70084
diff changeset
29 else: # nan
e092ff374721 #16559: Add more tests for the json module. Patch by Serhiy Storchaka.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 70084
diff changeset
30 res = self.loads(out)
e092ff374721 #16559: Add more tests for the json module. Patch by Serhiy Storchaka.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 70084
diff changeset
31 self.assertEqual(len(res), 1)
e092ff374721 #16559: Add more tests for the json module. Patch by Serhiy Storchaka.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 70084
diff changeset
32 self.assertNotEqual(res[0], res[0])
e092ff374721 #16559: Add more tests for the json module. Patch by Serhiy Storchaka.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 70084
diff changeset
33 self.assertRaises(ValueError, self.dumps, [val], allow_nan=False)
e092ff374721 #16559: Add more tests for the json module. Patch by Serhiy Storchaka.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 70084
diff changeset
34
70084
5b0fecd2eba0 #5723: Improve json tests to be executed with and without accelerations.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 66348
diff changeset
35
5b0fecd2eba0 #5723: Improve json tests to be executed with and without accelerations.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 66348
diff changeset
36 class TestPyFloat(TestFloat, PyTest): pass
5b0fecd2eba0 #5723: Improve json tests to be executed with and without accelerations.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 66348
diff changeset
37 class TestCFloat(TestFloat, CTest): pass