MCPcopy Index your code
hub / github.com/python/cpython / test_string_with_utf8_bom

Method test_string_with_utf8_bom

Lib/test/test_json/test_decode.py:125–138  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

123 self.assertRaisesRegex(TypeError, msg, self.loads, value)
124
125 def test_string_with_utf8_bom(self):
126 # see #18958
127 bom_json = "[1,2,3]".encode('utf-8-sig').decode('utf-8')
128 with self.assertRaises(self.JSONDecodeError) as cm:
129 self.loads(bom_json)
130 self.assertIn('BOM', str(cm.exception))
131 with self.assertRaises(self.JSONDecodeError) as cm:
132 self.json.load(StringIO(bom_json))
133 self.assertIn('BOM', str(cm.exception))
134 # make sure that the BOM is not detected in the middle of a string
135 bom = ''.encode('utf-8-sig').decode('utf-8')
136 bom_in_str = f'"{bom}"'
137 self.assertEqual(self.loads(bom_in_str), '\ufeff')
138 self.assertEqual(self.json.load(StringIO(bom_in_str)), '\ufeff')
139
140 def test_negative_index(self):
141 d = self.json.JSONDecoder()

Callers

nothing calls this directly

Calls 9

StringIOClass · 0.90
strFunction · 0.85
assertInMethod · 0.80
decodeMethod · 0.45
encodeMethod · 0.45
assertRaisesMethod · 0.45
loadsMethod · 0.45
loadMethod · 0.45
assertEqualMethod · 0.45

Tested by

no test coverage detected