ยปCore Development>Code coverage>Lib/test/test_json/test_float.py

Python code coverage for Lib/test/test_json/test_float.py

#countcontent
1n/aimport math
2n/afrom test.test_json import PyTest, CTest
3n/a
4n/a
5n/aclass TestFloat:
6n/a def test_floats(self):
7n/a for num in [1617161771.7650001, math.pi, math.pi**100, math.pi**-100, 3.1]:
8n/a self.assertEqual(float(self.dumps(num)), num)
9n/a self.assertEqual(self.loads(self.dumps(num)), num)
10n/a
11n/a def test_ints(self):
12n/a for num in [1, 1<<32, 1<<64]:
13n/a self.assertEqual(self.dumps(num), str(num))
14n/a self.assertEqual(int(self.dumps(num)), num)
15n/a
16n/a def test_out_of_range(self):
17n/a self.assertEqual(self.loads('[23456789012E666]'), [float('inf')])
18n/a self.assertEqual(self.loads('[-23456789012E666]'), [float('-inf')])
19n/a
20n/a def test_allow_nan(self):
21n/a for val in (float('inf'), float('-inf'), float('nan')):
22n/a out = self.dumps([val])
23n/a if val == val: # inf
24n/a self.assertEqual(self.loads(out), [val])
25n/a else: # nan
26n/a res = self.loads(out)
27n/a self.assertEqual(len(res), 1)
28n/a self.assertNotEqual(res[0], res[0])
29n/a self.assertRaises(ValueError, self.dumps, [val], allow_nan=False)
30n/a
31n/a
32n/aclass TestPyFloat(TestFloat, PyTest): pass
33n/aclass TestCFloat(TestFloat, CTest): pass