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

Method test_new

Lib/test/test_capi/test_unicode.py:35–52  ·  view source on GitHub ↗

Test PyUnicode_New()

(self)

Source from the content-addressed store, hash-verified

33 @support.cpython_only
34 @unittest.skipIf(_testcapi is None, 'need _testcapi module')
35 def test_new(self):
36 """Test PyUnicode_New()"""
37 from _testcapi import unicode_new as new
38
39 for maxchar in 0, 0x61, 0xa1, 0x4f60, 0x1f600, 0x10ffff:
40 self.assertEqual(new(0, maxchar), '')
41 self.assertEqual(new(5, maxchar), chr(maxchar)*5)
42 self.assertRaises(MemoryError, new, PY_SSIZE_T_MAX, maxchar)
43 self.assertEqual(new(0, 0x110000), '')
44 self.assertRaises(MemoryError, new, PY_SSIZE_T_MAX//2, 0x4f60)
45 self.assertRaises(MemoryError, new, PY_SSIZE_T_MAX//2+1, 0x4f60)
46 self.assertRaises(MemoryError, new, PY_SSIZE_T_MAX//2, 0x1f600)
47 self.assertRaises(MemoryError, new, PY_SSIZE_T_MAX//2+1, 0x1f600)
48 self.assertRaises(MemoryError, new, PY_SSIZE_T_MAX//4, 0x1f600)
49 self.assertRaises(MemoryError, new, PY_SSIZE_T_MAX//4+1, 0x1f600)
50 self.assertRaises(SystemError, new, 5, 0x110000)
51 self.assertRaises(SystemError, new, -1, 0)
52 self.assertRaises(SystemError, new, PY_SSIZE_T_MIN, 0)
53
54 @support.cpython_only
55 @unittest.skipIf(_testcapi is None, 'need _testcapi module')

Callers

nothing calls this directly

Calls 3

newFunction · 0.85
assertEqualMethod · 0.45
assertRaisesMethod · 0.45

Tested by

no test coverage detected