Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(261857)

Delta Between Two Patch Sets: Lib/test/test_json/test_decode.py

Issue 16510: Using appropriate checks in tests
Left Patch Set: Created 6 years, 9 months ago
Right Patch Set: Created 5 years, 6 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Right: Side by side diff | Download
« no previous file with change/comment | « Lib/test/test_itertools.py ('k') | Lib/test/test_kqueue.py » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
(no file at all)
1 import decimal 1 import decimal
2 from io import StringIO, BytesIO 2 from io import StringIO, BytesIO
3 from collections import OrderedDict 3 from collections import OrderedDict
4 from test.test_json import PyTest, CTest 4 from test.test_json import PyTest, CTest
5 5
6 6
7 class TestDecode: 7 class TestDecode:
8 def test_decimal(self): 8 def test_decimal(self):
9 rval = self.loads('1.1', parse_float=decimal.Decimal) 9 rval = self.loads('1.1', parse_float=decimal.Decimal)
10 self.assertTrue(isinstance(rval, decimal.Decimal)) 10 self.assertIsInstance(rval, decimal.Decimal)
11 self.assertEqual(rval, decimal.Decimal('1.1')) 11 self.assertEqual(rval, decimal.Decimal('1.1'))
12 12
13 def test_float(self): 13 def test_float(self):
14 rval = self.loads('1', parse_int=float) 14 rval = self.loads('1', parse_int=float)
15 self.assertTrue(isinstance(rval, float)) 15 self.assertIsInstance(rval, float)
16 self.assertEqual(rval, 1.0) 16 self.assertEqual(rval, 1.0)
17 17
18 def test_empty_objects(self): 18 def test_empty_objects(self):
19 self.assertEqual(self.loads('{}'), {}) 19 self.assertEqual(self.loads('{}'), {})
20 self.assertEqual(self.loads('[]'), []) 20 self.assertEqual(self.loads('[]'), [])
21 self.assertEqual(self.loads('""'), "") 21 self.assertEqual(self.loads('""'), "")
22 22
23 def test_object_pairs_hook(self): 23 def test_object_pairs_hook(self):
24 s = '{"xkd":1, "kcw":2, "art":3, "hxm":4, "qrt":5, "pad":6, "hoy":7}' 24 s = '{"xkd":1, "kcw":2, "art":3, "hxm":4, "qrt":5, "pad":6, "hoy":7}'
25 p = [("xkd", 1), ("kcw", 2), ("art", 3), ("hxm", 4), 25 p = [("xkd", 1), ("kcw", 2), ("art", 3), ("hxm", 4),
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 with self.assertRaises(ValueError) as cm: 86 with self.assertRaises(ValueError) as cm:
87 self.json.load(StringIO(bom_json)) 87 self.json.load(StringIO(bom_json))
88 self.assertIn('BOM', str(cm.exception)) 88 self.assertIn('BOM', str(cm.exception))
89 # make sure that the BOM is not detected in the middle of a string 89 # make sure that the BOM is not detected in the middle of a string
90 bom_in_str = '"{}"'.format(''.encode('utf-8-sig').decode('utf-8')) 90 bom_in_str = '"{}"'.format(''.encode('utf-8-sig').decode('utf-8'))
91 self.assertEqual(self.loads(bom_in_str), '\ufeff') 91 self.assertEqual(self.loads(bom_in_str), '\ufeff')
92 self.assertEqual(self.json.load(StringIO(bom_in_str)), '\ufeff') 92 self.assertEqual(self.json.load(StringIO(bom_in_str)), '\ufeff')
93 93
94 class TestPyDecode(TestDecode, PyTest): pass 94 class TestPyDecode(TestDecode, PyTest): pass
95 class TestCDecode(TestDecode, CTest): pass 95 class TestCDecode(TestDecode, CTest): pass
LEFTRIGHT

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+