Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-109050: Remove remaining tests for legacy Unicode C API #109068

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions Lib/test/support/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -506,15 +506,6 @@ def has_no_debug_ranges():
def requires_debug_ranges(reason='requires co_positions / debug_ranges'):
return unittest.skipIf(has_no_debug_ranges(), reason)

def requires_legacy_unicode_capi():
try:
from _testcapi import unicode_legacy_string
except ImportError:
unicode_legacy_string = None

return unittest.skipUnless(unicode_legacy_string,
'requires legacy Unicode C API')

# Is not actually used in tests, but is kept for compatibility.
is_jython = sys.platform.startswith('java')

Expand Down
63 changes: 0 additions & 63 deletions Lib/test/test_capi/test_getargs.py
Original file line number Diff line number Diff line change
Expand Up @@ -1004,69 +1004,6 @@ def test_et_hash(self):
buf = bytearray()
self.assertRaises(ValueError, getargs_et_hash, 'abc\xe9', 'latin1', buf)

@support.requires_legacy_unicode_capi()
def test_u(self):
from _testcapi import getargs_u
with self.assertWarns(DeprecationWarning):
self.assertEqual(getargs_u('abc\xe9'), 'abc\xe9')
with self.assertWarns(DeprecationWarning):
self.assertRaises(ValueError, getargs_u, 'nul:\0')
with self.assertWarns(DeprecationWarning):
self.assertRaises(TypeError, getargs_u, b'bytes')
with self.assertWarns(DeprecationWarning):
self.assertRaises(TypeError, getargs_u, bytearray(b'bytearray'))
with self.assertWarns(DeprecationWarning):
self.assertRaises(TypeError, getargs_u, memoryview(b'memoryview'))
with self.assertWarns(DeprecationWarning):
self.assertRaises(TypeError, getargs_u, None)

@support.requires_legacy_unicode_capi()
def test_u_hash(self):
from _testcapi import getargs_u_hash
with self.assertWarns(DeprecationWarning):
self.assertEqual(getargs_u_hash('abc\xe9'), 'abc\xe9')
with self.assertWarns(DeprecationWarning):
self.assertEqual(getargs_u_hash('nul:\0'), 'nul:\0')
with self.assertWarns(DeprecationWarning):
self.assertRaises(TypeError, getargs_u_hash, b'bytes')
with self.assertWarns(DeprecationWarning):
self.assertRaises(TypeError, getargs_u_hash, bytearray(b'bytearray'))
with self.assertWarns(DeprecationWarning):
self.assertRaises(TypeError, getargs_u_hash, memoryview(b'memoryview'))
with self.assertWarns(DeprecationWarning):
self.assertRaises(TypeError, getargs_u_hash, None)

@support.requires_legacy_unicode_capi()
def test_Z(self):
from _testcapi import getargs_Z
with self.assertWarns(DeprecationWarning):
self.assertEqual(getargs_Z('abc\xe9'), 'abc\xe9')
with self.assertWarns(DeprecationWarning):
self.assertRaises(ValueError, getargs_Z, 'nul:\0')
with self.assertWarns(DeprecationWarning):
self.assertRaises(TypeError, getargs_Z, b'bytes')
with self.assertWarns(DeprecationWarning):
self.assertRaises(TypeError, getargs_Z, bytearray(b'bytearray'))
with self.assertWarns(DeprecationWarning):
self.assertRaises(TypeError, getargs_Z, memoryview(b'memoryview'))
with self.assertWarns(DeprecationWarning):
self.assertIsNone(getargs_Z(None))

@support.requires_legacy_unicode_capi()
def test_Z_hash(self):
from _testcapi import getargs_Z_hash
with self.assertWarns(DeprecationWarning):
self.assertEqual(getargs_Z_hash('abc\xe9'), 'abc\xe9')
with self.assertWarns(DeprecationWarning):
self.assertEqual(getargs_Z_hash('nul:\0'), 'nul:\0')
with self.assertWarns(DeprecationWarning):
self.assertRaises(TypeError, getargs_Z_hash, b'bytes')
with self.assertWarns(DeprecationWarning):
self.assertRaises(TypeError, getargs_Z_hash, bytearray(b'bytearray'))
with self.assertWarns(DeprecationWarning):
self.assertRaises(TypeError, getargs_Z_hash, memoryview(b'memoryview'))
with self.assertWarns(DeprecationWarning):
self.assertIsNone(getargs_Z_hash(None))

serhiy-storchaka marked this conversation as resolved.
Show resolved Hide resolved
def test_gh_99240_clear_args(self):
from _testcapi import gh_99240_clear_args
Expand Down
12 changes: 0 additions & 12 deletions Lib/test/test_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,18 +281,6 @@ def test_writerows_errors(self):
self.assertRaises(TypeError, writer.writerows, None)
self.assertRaises(OSError, writer.writerows, BadIterable())

@support.cpython_only
@support.requires_legacy_unicode_capi()
@warnings_helper.ignore_warnings(category=DeprecationWarning)
def test_writerows_legacy_strings(self):
import _testcapi
c = _testcapi.unicode_legacy_string('a')
with TemporaryFile("w+", encoding="utf-8", newline='') as fileobj:
writer = csv.writer(fileobj)
writer.writerows([[c]])
fileobj.seek(0)
self.assertEqual(fileobj.read(), "a\r\n")

def _read_test(self, input, expect, **kwargs):
reader = csv.reader(input, **kwargs)
result = list(reader)
Expand Down
31 changes: 1 addition & 30 deletions Lib/test/test_decimal.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
import locale
from test.support import (is_resource_enabled,
requires_IEEE_754, requires_docstrings,
requires_legacy_unicode_capi, check_sanitizer,
check_sanitizer,
check_disallow_instantiation)
from test.support import (TestFailed,
run_with_locale, cpython_only,
Expand Down Expand Up @@ -587,18 +587,6 @@ def test_explicit_from_string(self):
# underscores don't prevent errors
self.assertRaises(InvalidOperation, Decimal, "1_2_\u00003")

@cpython_only
@requires_legacy_unicode_capi()
@warnings_helper.ignore_warnings(category=DeprecationWarning)
def test_from_legacy_strings(self):
import _testcapi
Decimal = self.decimal.Decimal
context = self.decimal.Context()

s = _testcapi.unicode_legacy_string('9.999999')
self.assertEqual(str(Decimal(s)), '9.999999')
self.assertEqual(str(context.create_decimal(s)), '9.999999')

def test_explicit_from_tuples(self):
Decimal = self.decimal.Decimal

Expand Down Expand Up @@ -2919,23 +2907,6 @@ def test_none_args(self):
assert_signals(self, c, 'traps', [InvalidOperation, DivisionByZero,
Overflow])

@cpython_only
@requires_legacy_unicode_capi()
@warnings_helper.ignore_warnings(category=DeprecationWarning)
def test_from_legacy_strings(self):
import _testcapi
c = self.decimal.Context()

for rnd in RoundingModes:
c.rounding = _testcapi.unicode_legacy_string(rnd)
self.assertEqual(c.rounding, rnd)

s = _testcapi.unicode_legacy_string('')
self.assertRaises(TypeError, setattr, c, 'rounding', s)

s = _testcapi.unicode_legacy_string('ROUND_\x00UP')
self.assertRaises(TypeError, setattr, c, 'rounding', s)

def test_pickle(self):

for proto in range(pickle.HIGHEST_PROTOCOL + 1):
Expand Down
30 changes: 0 additions & 30 deletions Lib/test/test_str.py
Original file line number Diff line number Diff line change
Expand Up @@ -812,16 +812,6 @@ def test_isidentifier(self):
self.assertFalse("©".isidentifier())
self.assertFalse("0".isidentifier())

@support.cpython_only
@support.requires_legacy_unicode_capi()
@unittest.skipIf(_testcapi is None, 'need _testcapi module')
def test_isidentifier_legacy(self):
u = '𝖀𝖓𝖎𝖈𝖔𝖉𝖊'
self.assertTrue(u.isidentifier())
with warnings_helper.check_warnings():
warnings.simplefilter('ignore', DeprecationWarning)
self.assertTrue(_testcapi.unicode_legacy_string(u).isidentifier())

def test_isprintable(self):
self.assertTrue("".isprintable())
self.assertTrue(" ".isprintable())
Expand Down Expand Up @@ -2489,26 +2479,6 @@ def test_getnewargs(self):
self.assertEqual(args[0], text)
self.assertEqual(len(args), 1)

@support.cpython_only
@support.requires_legacy_unicode_capi()
@unittest.skipIf(_testcapi is None, 'need _testcapi module')
def test_resize(self):
for length in range(1, 100, 7):
# generate a fresh string (refcount=1)
text = 'a' * length + 'b'

# fill wstr internal field
with self.assertWarns(DeprecationWarning):
abc = _testcapi.getargs_u(text)
self.assertEqual(abc, text)

# resize text: wstr field must be cleared and then recomputed
text += 'c'
with self.assertWarns(DeprecationWarning):
abcdef = _testcapi.getargs_u(text)
self.assertNotEqual(abc, abcdef)
self.assertEqual(abcdef, text)

def test_compare(self):
# Issue #17615
N = 10
Expand Down
52 changes: 0 additions & 52 deletions Modules/_testcapi/getargs.c
Original file line number Diff line number Diff line change
Expand Up @@ -589,54 +589,6 @@ getargs_y_hash(PyObject *self, PyObject *args)
return PyBytes_FromStringAndSize(str, size);
}

static PyObject *
getargs_u(PyObject *self, PyObject *args)
{
wchar_t *str;
if (!PyArg_ParseTuple(args, "u", &str)) {
return NULL;
}
return PyUnicode_FromWideChar(str, -1);
}

static PyObject *
getargs_u_hash(PyObject *self, PyObject *args)
{
wchar_t *str;
Py_ssize_t size;
if (!PyArg_ParseTuple(args, "u#", &str, &size)) {
return NULL;
}
return PyUnicode_FromWideChar(str, size);
}

static PyObject *
getargs_Z(PyObject *self, PyObject *args)
{
wchar_t *str;
if (!PyArg_ParseTuple(args, "Z", &str)) {
return NULL;
}
if (str != NULL) {
return PyUnicode_FromWideChar(str, -1);
}
Py_RETURN_NONE;
}

static PyObject *
getargs_Z_hash(PyObject *self, PyObject *args)
{
wchar_t *str;
Py_ssize_t size;
if (!PyArg_ParseTuple(args, "Z#", &str, &size)) {
return NULL;
}
if (str != NULL) {
return PyUnicode_FromWideChar(str, size);
}
Py_RETURN_NONE;
}

static PyObject *
getargs_es(PyObject *self, PyObject *args)
{
Expand Down Expand Up @@ -845,8 +797,6 @@ static PyMethodDef test_methods[] = {
{"getargs_S", getargs_S, METH_VARARGS},
{"getargs_U", getargs_U, METH_VARARGS},
{"getargs_Y", getargs_Y, METH_VARARGS},
{"getargs_Z", getargs_Z, METH_VARARGS},
{"getargs_Z_hash", getargs_Z_hash, METH_VARARGS},
{"getargs_b", getargs_b, METH_VARARGS},
{"getargs_c", getargs_c, METH_VARARGS},
{"getargs_d", getargs_d, METH_VARARGS},
Expand All @@ -868,8 +818,6 @@ static PyMethodDef test_methods[] = {
{"getargs_s_hash", getargs_s_hash, METH_VARARGS},
{"getargs_s_star", getargs_s_star, METH_VARARGS},
{"getargs_tuple", getargs_tuple, METH_VARARGS},
{"getargs_u", getargs_u, METH_VARARGS},
{"getargs_u_hash", getargs_u_hash, METH_VARARGS},
{"getargs_w_star", getargs_w_star, METH_VARARGS},
{"getargs_y", getargs_y, METH_VARARGS},
{"getargs_y_hash", getargs_y_hash, METH_VARARGS},
Expand Down