MCPcopy Create free account
hub / github.com/simplejson/simplejson / TestBitSizeIntAsString

Class TestBitSizeIntAsString

simplejson/tests/test_bitsize_int_as_string.py:6–120  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4
5
6class TestBitSizeIntAsString(TestCase):
7 # Python 2.5, at least the one that ships on Mac OS X, calculates
8 # 2 ** 31 as 0! It manages to calculate 1 << 31 correctly.
9 values = [
10 (200, 200),
11 ((1 << 31) - 1, (1 << 31) - 1),
12 ((1 << 31), str(1 << 31)),
13 ((1 << 31) + 1, str((1 << 31) + 1)),
14 (-100, -100),
15 ((-1 << 31), str(-1 << 31)),
16 ((-1 << 31) - 1, str((-1 << 31) - 1)),
17 ((-1 << 31) + 1, (-1 << 31) + 1),
18 ]
19
20 def test_invalid_counts(self):
21 for n in ['foo', -1, 0, 1.0]:
22 self.assertRaises(
23 TypeError,
24 json.dumps, 0, int_as_string_bitcount=n)
25
26 def test_ints_outside_range_fails(self):
27 self.assertNotEqual(
28 str(1 << 15),
29 json.loads(json.dumps(1 << 15, int_as_string_bitcount=16)),
30 )
31
32 def test_ints(self):
33 for val, expect in self.values:
34 self.assertEqual(
35 val,
36 json.loads(json.dumps(val)))
37 self.assertEqual(
38 expect,
39 json.loads(json.dumps(val, int_as_string_bitcount=31)),
40 )
41
42 def test_lists(self):
43 for val, expect in self.values:
44 val = [val, val]
45 expect = [expect, expect]
46 self.assertEqual(
47 val,
48 json.loads(json.dumps(val)))
49 self.assertEqual(
50 expect,
51 json.loads(json.dumps(val, int_as_string_bitcount=31)))
52
53 def test_dicts(self):
54 for val, expect in self.values:
55 val = {'k': val}
56 expect = {'k': expect}
57 self.assertEqual(
58 val,
59 json.loads(json.dumps(val)))
60 self.assertEqual(
61 expect,
62 json.loads(json.dumps(val, int_as_string_bitcount=31)))
63

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…