Skip to content

Commit b4131a1

Browse files
pythongh-109050: Remove remaining tests for legacy Unicode C API (pythonGH-109068)
1 parent 17f9941 commit b4131a1

File tree

6 files changed

+1
-197
lines changed

6 files changed

+1
-197
lines changed

Lib/test/support/__init__.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -506,15 +506,6 @@ def has_no_debug_ranges():
506506
def requires_debug_ranges(reason='requires co_positions / debug_ranges'):
507507
return unittest.skipIf(has_no_debug_ranges(), reason)
508508

509-
def requires_legacy_unicode_capi():
510-
try:
511-
from _testcapi import unicode_legacy_string
512-
except ImportError:
513-
unicode_legacy_string = None
514-
515-
return unittest.skipUnless(unicode_legacy_string,
516-
'requires legacy Unicode C API')
517-
518509
# Is not actually used in tests, but is kept for compatibility.
519510
is_jython = sys.platform.startswith('java')
520511

Lib/test/test_capi/test_getargs.py

Lines changed: 0 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1004,70 +1004,6 @@ def test_et_hash(self):
10041004
buf = bytearray()
10051005
self.assertRaises(ValueError, getargs_et_hash, 'abc\xe9', 'latin1', buf)
10061006

1007-
@support.requires_legacy_unicode_capi()
1008-
def test_u(self):
1009-
from _testcapi import getargs_u
1010-
with self.assertWarns(DeprecationWarning):
1011-
self.assertEqual(getargs_u('abc\xe9'), 'abc\xe9')
1012-
with self.assertWarns(DeprecationWarning):
1013-
self.assertRaises(ValueError, getargs_u, 'nul:\0')
1014-
with self.assertWarns(DeprecationWarning):
1015-
self.assertRaises(TypeError, getargs_u, b'bytes')
1016-
with self.assertWarns(DeprecationWarning):
1017-
self.assertRaises(TypeError, getargs_u, bytearray(b'bytearray'))
1018-
with self.assertWarns(DeprecationWarning):
1019-
self.assertRaises(TypeError, getargs_u, memoryview(b'memoryview'))
1020-
with self.assertWarns(DeprecationWarning):
1021-
self.assertRaises(TypeError, getargs_u, None)
1022-
1023-
@support.requires_legacy_unicode_capi()
1024-
def test_u_hash(self):
1025-
from _testcapi import getargs_u_hash
1026-
with self.assertWarns(DeprecationWarning):
1027-
self.assertEqual(getargs_u_hash('abc\xe9'), 'abc\xe9')
1028-
with self.assertWarns(DeprecationWarning):
1029-
self.assertEqual(getargs_u_hash('nul:\0'), 'nul:\0')
1030-
with self.assertWarns(DeprecationWarning):
1031-
self.assertRaises(TypeError, getargs_u_hash, b'bytes')
1032-
with self.assertWarns(DeprecationWarning):
1033-
self.assertRaises(TypeError, getargs_u_hash, bytearray(b'bytearray'))
1034-
with self.assertWarns(DeprecationWarning):
1035-
self.assertRaises(TypeError, getargs_u_hash, memoryview(b'memoryview'))
1036-
with self.assertWarns(DeprecationWarning):
1037-
self.assertRaises(TypeError, getargs_u_hash, None)
1038-
1039-
@support.requires_legacy_unicode_capi()
1040-
def test_Z(self):
1041-
from _testcapi import getargs_Z
1042-
with self.assertWarns(DeprecationWarning):
1043-
self.assertEqual(getargs_Z('abc\xe9'), 'abc\xe9')
1044-
with self.assertWarns(DeprecationWarning):
1045-
self.assertRaises(ValueError, getargs_Z, 'nul:\0')
1046-
with self.assertWarns(DeprecationWarning):
1047-
self.assertRaises(TypeError, getargs_Z, b'bytes')
1048-
with self.assertWarns(DeprecationWarning):
1049-
self.assertRaises(TypeError, getargs_Z, bytearray(b'bytearray'))
1050-
with self.assertWarns(DeprecationWarning):
1051-
self.assertRaises(TypeError, getargs_Z, memoryview(b'memoryview'))
1052-
with self.assertWarns(DeprecationWarning):
1053-
self.assertIsNone(getargs_Z(None))
1054-
1055-
@support.requires_legacy_unicode_capi()
1056-
def test_Z_hash(self):
1057-
from _testcapi import getargs_Z_hash
1058-
with self.assertWarns(DeprecationWarning):
1059-
self.assertEqual(getargs_Z_hash('abc\xe9'), 'abc\xe9')
1060-
with self.assertWarns(DeprecationWarning):
1061-
self.assertEqual(getargs_Z_hash('nul:\0'), 'nul:\0')
1062-
with self.assertWarns(DeprecationWarning):
1063-
self.assertRaises(TypeError, getargs_Z_hash, b'bytes')
1064-
with self.assertWarns(DeprecationWarning):
1065-
self.assertRaises(TypeError, getargs_Z_hash, bytearray(b'bytearray'))
1066-
with self.assertWarns(DeprecationWarning):
1067-
self.assertRaises(TypeError, getargs_Z_hash, memoryview(b'memoryview'))
1068-
with self.assertWarns(DeprecationWarning):
1069-
self.assertIsNone(getargs_Z_hash(None))
1070-
10711007
def test_gh_99240_clear_args(self):
10721008
from _testcapi import gh_99240_clear_args
10731009
self.assertRaises(TypeError, gh_99240_clear_args, 'a', '\0b')

Lib/test/test_csv.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -281,18 +281,6 @@ def test_writerows_errors(self):
281281
self.assertRaises(TypeError, writer.writerows, None)
282282
self.assertRaises(OSError, writer.writerows, BadIterable())
283283

284-
@support.cpython_only
285-
@support.requires_legacy_unicode_capi()
286-
@warnings_helper.ignore_warnings(category=DeprecationWarning)
287-
def test_writerows_legacy_strings(self):
288-
import _testcapi
289-
c = _testcapi.unicode_legacy_string('a')
290-
with TemporaryFile("w+", encoding="utf-8", newline='') as fileobj:
291-
writer = csv.writer(fileobj)
292-
writer.writerows([[c]])
293-
fileobj.seek(0)
294-
self.assertEqual(fileobj.read(), "a\r\n")
295-
296284
def _read_test(self, input, expect, **kwargs):
297285
reader = csv.reader(input, **kwargs)
298286
result = list(reader)

Lib/test/test_decimal.py

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
import locale
3535
from test.support import (is_resource_enabled,
3636
requires_IEEE_754, requires_docstrings,
37-
requires_legacy_unicode_capi, check_sanitizer,
37+
check_sanitizer,
3838
check_disallow_instantiation)
3939
from test.support import (TestFailed,
4040
run_with_locale, cpython_only,
@@ -587,18 +587,6 @@ def test_explicit_from_string(self):
587587
# underscores don't prevent errors
588588
self.assertRaises(InvalidOperation, Decimal, "1_2_\u00003")
589589

590-
@cpython_only
591-
@requires_legacy_unicode_capi()
592-
@warnings_helper.ignore_warnings(category=DeprecationWarning)
593-
def test_from_legacy_strings(self):
594-
import _testcapi
595-
Decimal = self.decimal.Decimal
596-
context = self.decimal.Context()
597-
598-
s = _testcapi.unicode_legacy_string('9.999999')
599-
self.assertEqual(str(Decimal(s)), '9.999999')
600-
self.assertEqual(str(context.create_decimal(s)), '9.999999')
601-
602590
def test_explicit_from_tuples(self):
603591
Decimal = self.decimal.Decimal
604592

@@ -2919,23 +2907,6 @@ def test_none_args(self):
29192907
assert_signals(self, c, 'traps', [InvalidOperation, DivisionByZero,
29202908
Overflow])
29212909

2922-
@cpython_only
2923-
@requires_legacy_unicode_capi()
2924-
@warnings_helper.ignore_warnings(category=DeprecationWarning)
2925-
def test_from_legacy_strings(self):
2926-
import _testcapi
2927-
c = self.decimal.Context()
2928-
2929-
for rnd in RoundingModes:
2930-
c.rounding = _testcapi.unicode_legacy_string(rnd)
2931-
self.assertEqual(c.rounding, rnd)
2932-
2933-
s = _testcapi.unicode_legacy_string('')
2934-
self.assertRaises(TypeError, setattr, c, 'rounding', s)
2935-
2936-
s = _testcapi.unicode_legacy_string('ROUND_\x00UP')
2937-
self.assertRaises(TypeError, setattr, c, 'rounding', s)
2938-
29392910
def test_pickle(self):
29402911

29412912
for proto in range(pickle.HIGHEST_PROTOCOL + 1):

Lib/test/test_str.py

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -812,16 +812,6 @@ def test_isidentifier(self):
812812
self.assertFalse("©".isidentifier())
813813
self.assertFalse("0".isidentifier())
814814

815-
@support.cpython_only
816-
@support.requires_legacy_unicode_capi()
817-
@unittest.skipIf(_testcapi is None, 'need _testcapi module')
818-
def test_isidentifier_legacy(self):
819-
u = '𝖀𝖓𝖎𝖈𝖔𝖉𝖊'
820-
self.assertTrue(u.isidentifier())
821-
with warnings_helper.check_warnings():
822-
warnings.simplefilter('ignore', DeprecationWarning)
823-
self.assertTrue(_testcapi.unicode_legacy_string(u).isidentifier())
824-
825815
def test_isprintable(self):
826816
self.assertTrue("".isprintable())
827817
self.assertTrue(" ".isprintable())
@@ -2489,26 +2479,6 @@ def test_getnewargs(self):
24892479
self.assertEqual(args[0], text)
24902480
self.assertEqual(len(args), 1)
24912481

2492-
@support.cpython_only
2493-
@support.requires_legacy_unicode_capi()
2494-
@unittest.skipIf(_testcapi is None, 'need _testcapi module')
2495-
def test_resize(self):
2496-
for length in range(1, 100, 7):
2497-
# generate a fresh string (refcount=1)
2498-
text = 'a' * length + 'b'
2499-
2500-
# fill wstr internal field
2501-
with self.assertWarns(DeprecationWarning):
2502-
abc = _testcapi.getargs_u(text)
2503-
self.assertEqual(abc, text)
2504-
2505-
# resize text: wstr field must be cleared and then recomputed
2506-
text += 'c'
2507-
with self.assertWarns(DeprecationWarning):
2508-
abcdef = _testcapi.getargs_u(text)
2509-
self.assertNotEqual(abc, abcdef)
2510-
self.assertEqual(abcdef, text)
2511-
25122482
def test_compare(self):
25132483
# Issue #17615
25142484
N = 10

Modules/_testcapi/getargs.c

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -589,54 +589,6 @@ getargs_y_hash(PyObject *self, PyObject *args)
589589
return PyBytes_FromStringAndSize(str, size);
590590
}
591591

592-
static PyObject *
593-
getargs_u(PyObject *self, PyObject *args)
594-
{
595-
wchar_t *str;
596-
if (!PyArg_ParseTuple(args, "u", &str)) {
597-
return NULL;
598-
}
599-
return PyUnicode_FromWideChar(str, -1);
600-
}
601-
602-
static PyObject *
603-
getargs_u_hash(PyObject *self, PyObject *args)
604-
{
605-
wchar_t *str;
606-
Py_ssize_t size;
607-
if (!PyArg_ParseTuple(args, "u#", &str, &size)) {
608-
return NULL;
609-
}
610-
return PyUnicode_FromWideChar(str, size);
611-
}
612-
613-
static PyObject *
614-
getargs_Z(PyObject *self, PyObject *args)
615-
{
616-
wchar_t *str;
617-
if (!PyArg_ParseTuple(args, "Z", &str)) {
618-
return NULL;
619-
}
620-
if (str != NULL) {
621-
return PyUnicode_FromWideChar(str, -1);
622-
}
623-
Py_RETURN_NONE;
624-
}
625-
626-
static PyObject *
627-
getargs_Z_hash(PyObject *self, PyObject *args)
628-
{
629-
wchar_t *str;
630-
Py_ssize_t size;
631-
if (!PyArg_ParseTuple(args, "Z#", &str, &size)) {
632-
return NULL;
633-
}
634-
if (str != NULL) {
635-
return PyUnicode_FromWideChar(str, size);
636-
}
637-
Py_RETURN_NONE;
638-
}
639-
640592
static PyObject *
641593
getargs_es(PyObject *self, PyObject *args)
642594
{
@@ -845,8 +797,6 @@ static PyMethodDef test_methods[] = {
845797
{"getargs_S", getargs_S, METH_VARARGS},
846798
{"getargs_U", getargs_U, METH_VARARGS},
847799
{"getargs_Y", getargs_Y, METH_VARARGS},
848-
{"getargs_Z", getargs_Z, METH_VARARGS},
849-
{"getargs_Z_hash", getargs_Z_hash, METH_VARARGS},
850800
{"getargs_b", getargs_b, METH_VARARGS},
851801
{"getargs_c", getargs_c, METH_VARARGS},
852802
{"getargs_d", getargs_d, METH_VARARGS},
@@ -868,8 +818,6 @@ static PyMethodDef test_methods[] = {
868818
{"getargs_s_hash", getargs_s_hash, METH_VARARGS},
869819
{"getargs_s_star", getargs_s_star, METH_VARARGS},
870820
{"getargs_tuple", getargs_tuple, METH_VARARGS},
871-
{"getargs_u", getargs_u, METH_VARARGS},
872-
{"getargs_u_hash", getargs_u_hash, METH_VARARGS},
873821
{"getargs_w_star", getargs_w_star, METH_VARARGS},
874822
{"getargs_y", getargs_y, METH_VARARGS},
875823
{"getargs_y_hash", getargs_y_hash, METH_VARARGS},

0 commit comments

Comments
 (0)