mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
gh-109050: Remove remaining tests for legacy Unicode C API (GH-109068)
This commit is contained in:
parent
17f994174d
commit
b4131a13cb
6 changed files with 1 additions and 197 deletions
|
@ -506,15 +506,6 @@ def has_no_debug_ranges():
|
||||||
def requires_debug_ranges(reason='requires co_positions / debug_ranges'):
|
def requires_debug_ranges(reason='requires co_positions / debug_ranges'):
|
||||||
return unittest.skipIf(has_no_debug_ranges(), reason)
|
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 not actually used in tests, but is kept for compatibility.
|
||||||
is_jython = sys.platform.startswith('java')
|
is_jython = sys.platform.startswith('java')
|
||||||
|
|
||||||
|
|
|
@ -1004,70 +1004,6 @@ class String_TestCase(unittest.TestCase):
|
||||||
buf = bytearray()
|
buf = bytearray()
|
||||||
self.assertRaises(ValueError, getargs_et_hash, 'abc\xe9', 'latin1', buf)
|
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))
|
|
||||||
|
|
||||||
def test_gh_99240_clear_args(self):
|
def test_gh_99240_clear_args(self):
|
||||||
from _testcapi import gh_99240_clear_args
|
from _testcapi import gh_99240_clear_args
|
||||||
self.assertRaises(TypeError, gh_99240_clear_args, 'a', '\0b')
|
self.assertRaises(TypeError, gh_99240_clear_args, 'a', '\0b')
|
||||||
|
|
|
@ -281,18 +281,6 @@ class Test_Csv(unittest.TestCase):
|
||||||
self.assertRaises(TypeError, writer.writerows, None)
|
self.assertRaises(TypeError, writer.writerows, None)
|
||||||
self.assertRaises(OSError, writer.writerows, BadIterable())
|
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):
|
def _read_test(self, input, expect, **kwargs):
|
||||||
reader = csv.reader(input, **kwargs)
|
reader = csv.reader(input, **kwargs)
|
||||||
result = list(reader)
|
result = list(reader)
|
||||||
|
|
|
@ -34,7 +34,7 @@ import numbers
|
||||||
import locale
|
import locale
|
||||||
from test.support import (is_resource_enabled,
|
from test.support import (is_resource_enabled,
|
||||||
requires_IEEE_754, requires_docstrings,
|
requires_IEEE_754, requires_docstrings,
|
||||||
requires_legacy_unicode_capi, check_sanitizer,
|
check_sanitizer,
|
||||||
check_disallow_instantiation)
|
check_disallow_instantiation)
|
||||||
from test.support import (TestFailed,
|
from test.support import (TestFailed,
|
||||||
run_with_locale, cpython_only,
|
run_with_locale, cpython_only,
|
||||||
|
@ -587,18 +587,6 @@ class ExplicitConstructionTest:
|
||||||
# underscores don't prevent errors
|
# underscores don't prevent errors
|
||||||
self.assertRaises(InvalidOperation, Decimal, "1_2_\u00003")
|
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):
|
def test_explicit_from_tuples(self):
|
||||||
Decimal = self.decimal.Decimal
|
Decimal = self.decimal.Decimal
|
||||||
|
|
||||||
|
@ -2919,23 +2907,6 @@ class ContextAPItests:
|
||||||
assert_signals(self, c, 'traps', [InvalidOperation, DivisionByZero,
|
assert_signals(self, c, 'traps', [InvalidOperation, DivisionByZero,
|
||||||
Overflow])
|
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):
|
def test_pickle(self):
|
||||||
|
|
||||||
for proto in range(pickle.HIGHEST_PROTOCOL + 1):
|
for proto in range(pickle.HIGHEST_PROTOCOL + 1):
|
||||||
|
|
|
@ -812,16 +812,6 @@ class StrTest(string_tests.StringLikeTest,
|
||||||
self.assertFalse("©".isidentifier())
|
self.assertFalse("©".isidentifier())
|
||||||
self.assertFalse("0".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):
|
def test_isprintable(self):
|
||||||
self.assertTrue("".isprintable())
|
self.assertTrue("".isprintable())
|
||||||
self.assertTrue(" ".isprintable())
|
self.assertTrue(" ".isprintable())
|
||||||
|
@ -2489,26 +2479,6 @@ class StrTest(string_tests.StringLikeTest,
|
||||||
self.assertEqual(args[0], text)
|
self.assertEqual(args[0], text)
|
||||||
self.assertEqual(len(args), 1)
|
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):
|
def test_compare(self):
|
||||||
# Issue #17615
|
# Issue #17615
|
||||||
N = 10
|
N = 10
|
||||||
|
|
|
@ -589,54 +589,6 @@ getargs_y_hash(PyObject *self, PyObject *args)
|
||||||
return PyBytes_FromStringAndSize(str, size);
|
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 *
|
static PyObject *
|
||||||
getargs_es(PyObject *self, PyObject *args)
|
getargs_es(PyObject *self, PyObject *args)
|
||||||
{
|
{
|
||||||
|
@ -845,8 +797,6 @@ static PyMethodDef test_methods[] = {
|
||||||
{"getargs_S", getargs_S, METH_VARARGS},
|
{"getargs_S", getargs_S, METH_VARARGS},
|
||||||
{"getargs_U", getargs_U, METH_VARARGS},
|
{"getargs_U", getargs_U, METH_VARARGS},
|
||||||
{"getargs_Y", getargs_Y, 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_b", getargs_b, METH_VARARGS},
|
||||||
{"getargs_c", getargs_c, METH_VARARGS},
|
{"getargs_c", getargs_c, METH_VARARGS},
|
||||||
{"getargs_d", getargs_d, METH_VARARGS},
|
{"getargs_d", getargs_d, METH_VARARGS},
|
||||||
|
@ -868,8 +818,6 @@ static PyMethodDef test_methods[] = {
|
||||||
{"getargs_s_hash", getargs_s_hash, METH_VARARGS},
|
{"getargs_s_hash", getargs_s_hash, METH_VARARGS},
|
||||||
{"getargs_s_star", getargs_s_star, METH_VARARGS},
|
{"getargs_s_star", getargs_s_star, METH_VARARGS},
|
||||||
{"getargs_tuple", getargs_tuple, 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_w_star", getargs_w_star, METH_VARARGS},
|
||||||
{"getargs_y", getargs_y, METH_VARARGS},
|
{"getargs_y", getargs_y, METH_VARARGS},
|
||||||
{"getargs_y_hash", getargs_y_hash, METH_VARARGS},
|
{"getargs_y_hash", getargs_y_hash, METH_VARARGS},
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue