]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-109050: Remove remaining tests for legacy Unicode C API (GH-109068)
authorSerhiy Storchaka <storchaka@gmail.com>
Sat, 9 Sep 2023 05:44:46 +0000 (08:44 +0300)
committerGitHub <noreply@github.com>
Sat, 9 Sep 2023 05:44:46 +0000 (05:44 +0000)
Lib/test/support/__init__.py
Lib/test/test_capi/test_getargs.py
Lib/test/test_csv.py
Lib/test/test_decimal.py
Lib/test/test_str.py
Modules/_testcapi/getargs.c

index 84b74ee2c298e937e3344f6b47e9244d1ec086eb..f40b73b0a799f199f2f4455e75847c03a6ad1770 100644 (file)
@@ -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')
 
index 246206af86101c0f639fa6b55ca977c80082a426..e10f679eeb71c84fb94bc2a66b880aa6829332ae 100644 (file)
@@ -1004,70 +1004,6 @@ class String_TestCase(unittest.TestCase):
         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))
-
     def test_gh_99240_clear_args(self):
         from _testcapi import gh_99240_clear_args
         self.assertRaises(TypeError, gh_99240_clear_args, 'a', '\0b')
index bc6879176cd85ee7d79864f1e15da123f3143199..27f4978ca66a88ac9b0b341a962afc3f0674e579 100644 (file)
@@ -281,18 +281,6 @@ class Test_Csv(unittest.TestCase):
             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)
index abfd71c868d009ecf06f862a1929b6696ad7c94f..d806eeac25fb2f64a74a3454da34ee0ccfcf7900 100644 (file)
@@ -34,7 +34,7 @@ import numbers
 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,
@@ -587,18 +587,6 @@ class ExplicitConstructionTest:
             # 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
 
@@ -2919,23 +2907,6 @@ class ContextAPItests:
             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):
index 3ae2f45ef6bddc179dae3fadd78f74d0f34f962c..814ef111c5bec8d3fcdc154706d3f806b09e3bd9 100644 (file)
@@ -812,16 +812,6 @@ class StrTest(string_tests.StringLikeTest,
         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())
@@ -2489,26 +2479,6 @@ class StrTest(string_tests.StringLikeTest,
         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
index 10a1c1dd05253df0e702898a1dab9c669aa52170..5f4a6dc8ca7672a668b0bcc063805ea22a5fc96f 100644 (file)
@@ -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)
 {
@@ -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},
@@ -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},