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

Method test_null_terminator

Lib/test/multibytecodec_support.py:285–300  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

283 del e.errors
284
285 def test_null_terminator(self):
286 # see gh-101828
287 text = "フルーツ"
288 try:
289 text.encode(self.encoding)
290 except UnicodeEncodeError:
291 text = "Python is cool"
292 encode_w_null = (text + "\0").encode(self.encoding)
293 encode_plus_null = text.encode(self.encoding) + "\0".encode(self.encoding)
294 self.assertTrue(encode_w_null.endswith(b'\x00'))
295 self.assertEqual(encode_w_null, encode_plus_null)
296
297 encode_w_null_2 = (text + "\0" + text + "\0").encode(self.encoding)
298 encode_plus_null_2 = encode_plus_null + encode_plus_null
299 self.assertEqual(encode_w_null_2.count(b'\x00'), 2)
300 self.assertEqual(encode_w_null_2, encode_plus_null_2)
301
302
303class TestBase_Mapping(unittest.TestCase):

Callers

nothing calls this directly

Calls 5

assertTrueMethod · 0.80
encodeMethod · 0.45
endswithMethod · 0.45
assertEqualMethod · 0.45
countMethod · 0.45

Tested by

no test coverage detected