]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-116417: Move limited C API complex.c tests to _testlimitedcapi (#117014)
authorVictor Stinner <vstinner@python.org>
Tue, 19 Mar 2024 16:23:12 +0000 (17:23 +0100)
committerGitHub <noreply@github.com>
Tue, 19 Mar 2024 16:23:12 +0000 (17:23 +0100)
Split complex.c tests of _testcapi into two parts: limited C API
tests in _testlimitedcapi and non-limited C API tests in _testcapi.

Lib/test/test_capi/test_complex.py
Modules/Setup.stdlib.in
Modules/_testcapi/complex.c
Modules/_testlimitedcapi.c
Modules/_testlimitedcapi/complex.c [new file with mode: 0644]
Modules/_testlimitedcapi/parts.h
PCbuild/_testlimitedcapi.vcxproj
PCbuild/_testlimitedcapi.vcxproj.filters

index a5b59558e7f851c11ad8a1007e22e80dfc25ddff..328ea12f97462c1d5132784ebaca37f784a4f6d0 100644 (file)
@@ -10,6 +10,7 @@ from test.support import import_helper
 
 
 _testcapi = import_helper.import_module('_testcapi')
+_testlimitedcapi = import_helper.import_module('_testlimitedcapi')
 
 NULL = None
 INF = float("inf")
@@ -25,7 +26,7 @@ class BadComplex3:
 class CAPIComplexTest(unittest.TestCase):
     def test_check(self):
         # Test PyComplex_Check()
-        check = _testcapi.complex_check
+        check = _testlimitedcapi.complex_check
 
         self.assertTrue(check(1+2j))
         self.assertTrue(check(ComplexSubclass(1+2j)))
@@ -38,7 +39,7 @@ class CAPIComplexTest(unittest.TestCase):
 
     def test_checkexact(self):
         # PyComplex_CheckExact()
-        checkexact = _testcapi.complex_checkexact
+        checkexact = _testlimitedcapi.complex_checkexact
 
         self.assertTrue(checkexact(1+2j))
         self.assertFalse(checkexact(ComplexSubclass(1+2j)))
@@ -57,13 +58,13 @@ class CAPIComplexTest(unittest.TestCase):
 
     def test_fromdoubles(self):
         # Test PyComplex_FromDoubles()
-        fromdoubles = _testcapi.complex_fromdoubles
+        fromdoubles = _testlimitedcapi.complex_fromdoubles
 
         self.assertEqual(fromdoubles(1.0, 2.0), 1.0+2.0j)
 
     def test_realasdouble(self):
         # Test PyComplex_RealAsDouble()
-        realasdouble = _testcapi.complex_realasdouble
+        realasdouble = _testlimitedcapi.complex_realasdouble
 
         self.assertEqual(realasdouble(1+2j), 1.0)
         self.assertEqual(realasdouble(-1+0j), -1.0)
@@ -98,7 +99,7 @@ class CAPIComplexTest(unittest.TestCase):
 
     def test_imagasdouble(self):
         # Test PyComplex_ImagAsDouble()
-        imagasdouble = _testcapi.complex_imagasdouble
+        imagasdouble = _testlimitedcapi.complex_imagasdouble
 
         self.assertEqual(imagasdouble(1+2j), 2.0)
         self.assertEqual(imagasdouble(1-1j), -1.0)
index 2f98b3e500ab1821a48e1dfe3763befd0daa7e08..1b7ad0e5d95a13dac3d1e3575c459eba0defac07 100644 (file)
 @MODULE__TESTBUFFER_TRUE@_testbuffer _testbuffer.c
 @MODULE__TESTINTERNALCAPI_TRUE@_testinternalcapi _testinternalcapi.c _testinternalcapi/test_lock.c _testinternalcapi/pytime.c _testinternalcapi/set.c _testinternalcapi/test_critical_sections.c
 @MODULE__TESTCAPI_TRUE@_testcapi _testcapimodule.c _testcapi/vectorcall.c _testcapi/heaptype.c _testcapi/abstract.c _testcapi/unicode.c _testcapi/dict.c _testcapi/set.c _testcapi/list.c _testcapi/tuple.c _testcapi/getargs.c _testcapi/datetime.c _testcapi/docstring.c _testcapi/mem.c _testcapi/watchers.c _testcapi/long.c _testcapi/float.c _testcapi/complex.c _testcapi/numbers.c _testcapi/structmember.c _testcapi/exceptions.c _testcapi/code.c _testcapi/buffer.c _testcapi/pyatomic.c _testcapi/file.c _testcapi/codec.c _testcapi/immortal.c _testcapi/gc.c _testcapi/hash.c _testcapi/time.c
-@MODULE__TESTLIMITEDCAPI_TRUE@_testlimitedcapi _testlimitedcapi.c _testlimitedcapi/abstract.c _testlimitedcapi/bytearray.c _testlimitedcapi/bytes.c _testlimitedcapi/dict.c _testlimitedcapi/float.c _testlimitedcapi/heaptype_relative.c _testlimitedcapi/list.c _testlimitedcapi/long.c _testlimitedcapi/pyos.c _testlimitedcapi/set.c _testlimitedcapi/sys.c _testlimitedcapi/unicode.c _testlimitedcapi/vectorcall_limited.c
+@MODULE__TESTLIMITEDCAPI_TRUE@_testlimitedcapi _testlimitedcapi.c _testlimitedcapi/abstract.c _testlimitedcapi/bytearray.c _testlimitedcapi/bytes.c _testlimitedcapi/complex.c _testlimitedcapi/dict.c _testlimitedcapi/float.c _testlimitedcapi/heaptype_relative.c _testlimitedcapi/list.c _testlimitedcapi/long.c _testlimitedcapi/pyos.c _testlimitedcapi/set.c _testlimitedcapi/sys.c _testlimitedcapi/unicode.c _testlimitedcapi/vectorcall_limited.c
 @MODULE__TESTCLINIC_TRUE@_testclinic _testclinic.c
 @MODULE__TESTCLINIC_LIMITED_TRUE@_testclinic_limited _testclinic_limited.c
 
index 4a70217eb90d629655dd52dbe1b31538ee0026a2..eceb1310bfe874a6895f60eefd6ae380e2b69228 100644 (file)
@@ -2,20 +2,6 @@
 #include "util.h"
 
 
-static PyObject *
-complex_check(PyObject *Py_UNUSED(module), PyObject *obj)
-{
-    NULLABLE(obj);
-    return PyLong_FromLong(PyComplex_Check(obj));
-}
-
-static PyObject *
-complex_checkexact(PyObject *Py_UNUSED(module), PyObject *obj)
-{
-    NULLABLE(obj);
-    return PyLong_FromLong(PyComplex_CheckExact(obj));
-}
-
 static PyObject *
 complex_fromccomplex(PyObject *Py_UNUSED(module), PyObject *obj)
 {
@@ -28,48 +14,6 @@ complex_fromccomplex(PyObject *Py_UNUSED(module), PyObject *obj)
     return PyComplex_FromCComplex(complex);
 }
 
-static PyObject *
-complex_fromdoubles(PyObject *Py_UNUSED(module), PyObject *args)
-{
-    double real, imag;
-
-    if (!PyArg_ParseTuple(args, "dd", &real, &imag)) {
-        return NULL;
-    }
-
-    return PyComplex_FromDoubles(real, imag);
-}
-
-static PyObject *
-complex_realasdouble(PyObject *Py_UNUSED(module), PyObject *obj)
-{
-    double real;
-
-    NULLABLE(obj);
-    real = PyComplex_RealAsDouble(obj);
-
-    if (real == -1. && PyErr_Occurred()) {
-        return NULL;
-    }
-
-    return PyFloat_FromDouble(real);
-}
-
-static PyObject *
-complex_imagasdouble(PyObject *Py_UNUSED(module), PyObject *obj)
-{
-    double imag;
-
-    NULLABLE(obj);
-    imag = PyComplex_ImagAsDouble(obj);
-
-    if (imag == -1. && PyErr_Occurred()) {
-        return NULL;
-    }
-
-    return PyFloat_FromDouble(imag);
-}
-
 static PyObject *
 complex_asccomplex(PyObject *Py_UNUSED(module), PyObject *obj)
 {
@@ -139,12 +83,7 @@ _py_c_abs(PyObject *Py_UNUSED(module), PyObject* obj)
 
 
 static PyMethodDef test_methods[] = {
-    {"complex_check", complex_check, METH_O},
-    {"complex_checkexact", complex_checkexact, METH_O},
     {"complex_fromccomplex", complex_fromccomplex, METH_O},
-    {"complex_fromdoubles", complex_fromdoubles, METH_VARARGS},
-    {"complex_realasdouble", complex_realasdouble, METH_O},
-    {"complex_imagasdouble", complex_imagasdouble, METH_O},
     {"complex_asccomplex", complex_asccomplex, METH_O},
     {"_py_c_sum", _py_c_sum, METH_VARARGS},
     {"_py_c_diff", _py_c_diff, METH_VARARGS},
index 3820d5d1a9fde67833e3cf73bb66cf7bdaf08ff3..bfd41070eedd551187db2ff9f53c37b637679854 100644 (file)
@@ -35,6 +35,9 @@ PyInit__testlimitedcapi(void)
     if (_PyTestLimitedCAPI_Init_Bytes(mod) < 0) {
         return NULL;
     }
+    if (_PyTestLimitedCAPI_Init_Complex(mod) < 0) {
+        return NULL;
+    }
     if (_PyTestLimitedCAPI_Init_Dict(mod) < 0) {
         return NULL;
     }
diff --git a/Modules/_testlimitedcapi/complex.c b/Modules/_testlimitedcapi/complex.c
new file mode 100644 (file)
index 0000000..e4c244e
--- /dev/null
@@ -0,0 +1,79 @@
+#include "parts.h"
+#include "util.h"
+
+
+static PyObject *
+complex_check(PyObject *Py_UNUSED(module), PyObject *obj)
+{
+    NULLABLE(obj);
+    return PyLong_FromLong(PyComplex_Check(obj));
+}
+
+static PyObject *
+complex_checkexact(PyObject *Py_UNUSED(module), PyObject *obj)
+{
+    NULLABLE(obj);
+    return PyLong_FromLong(PyComplex_CheckExact(obj));
+}
+
+static PyObject *
+complex_fromdoubles(PyObject *Py_UNUSED(module), PyObject *args)
+{
+    double real, imag;
+
+    if (!PyArg_ParseTuple(args, "dd", &real, &imag)) {
+        return NULL;
+    }
+
+    return PyComplex_FromDoubles(real, imag);
+}
+
+static PyObject *
+complex_realasdouble(PyObject *Py_UNUSED(module), PyObject *obj)
+{
+    double real;
+
+    NULLABLE(obj);
+    real = PyComplex_RealAsDouble(obj);
+
+    if (real == -1. && PyErr_Occurred()) {
+        return NULL;
+    }
+
+    return PyFloat_FromDouble(real);
+}
+
+static PyObject *
+complex_imagasdouble(PyObject *Py_UNUSED(module), PyObject *obj)
+{
+    double imag;
+
+    NULLABLE(obj);
+    imag = PyComplex_ImagAsDouble(obj);
+
+    if (imag == -1. && PyErr_Occurred()) {
+        return NULL;
+    }
+
+    return PyFloat_FromDouble(imag);
+}
+
+
+static PyMethodDef test_methods[] = {
+    {"complex_check", complex_check, METH_O},
+    {"complex_checkexact", complex_checkexact, METH_O},
+    {"complex_fromdoubles", complex_fromdoubles, METH_VARARGS},
+    {"complex_realasdouble", complex_realasdouble, METH_O},
+    {"complex_imagasdouble", complex_imagasdouble, METH_O},
+    {NULL},
+};
+
+int
+_PyTestLimitedCAPI_Init_Complex(PyObject *mod)
+{
+    if (PyModule_AddFunctions(mod, test_methods) < 0) {
+        return -1;
+    }
+
+    return 0;
+}
index 4de9f8903f186a6306b13aca9609d973e6a35f53..4b65912489661b5d76c82889b08f6b4e82593437 100644 (file)
@@ -25,6 +25,7 @@
 int _PyTestLimitedCAPI_Init_Abstract(PyObject *module);
 int _PyTestLimitedCAPI_Init_ByteArray(PyObject *module);
 int _PyTestLimitedCAPI_Init_Bytes(PyObject *module);
+int _PyTestLimitedCAPI_Init_Complex(PyObject *module);
 int _PyTestLimitedCAPI_Init_Dict(PyObject *module);
 int _PyTestLimitedCAPI_Init_Float(PyObject *module);
 int _PyTestLimitedCAPI_Init_HeaptypeRelative(PyObject *module);
index e793b93a6c13180a1f2ba78f6190c2fd9e9ebe5f..58a8bcbdbce4e839c6f076fa8f0bacb3a0cd4ddb 100644 (file)
@@ -97,6 +97,7 @@
     <ClCompile Include="..\Modules\_testlimitedcapi\abstract.c" />
     <ClCompile Include="..\Modules\_testlimitedcapi\bytearray.c" />
     <ClCompile Include="..\Modules\_testlimitedcapi\bytes.c" />
+    <ClCompile Include="..\Modules\_testlimitedcapi\complex.c" />
     <ClCompile Include="..\Modules\_testlimitedcapi\dict.c" />
     <ClCompile Include="..\Modules\_testlimitedcapi\float.c" />
     <ClCompile Include="..\Modules\_testlimitedcapi\heaptype_relative.c" />
index 7c1226bc2796cb6edbde20d8b58fdae276080431..e203edaf123e8d6f4a6d7831dabcc2f4afb6dfbd 100644 (file)
@@ -12,6 +12,7 @@
     <ClCompile Include="..\Modules\_testlimitedcapi\abstract.c" />
     <ClCompile Include="..\Modules\_testlimitedcapi\bytearray.c" />
     <ClCompile Include="..\Modules\_testlimitedcapi\bytes.c" />
+    <ClCompile Include="..\Modules\_testlimitedcapi\complex.c" />
     <ClCompile Include="..\Modules\_testlimitedcapi\dict.c" />
     <ClCompile Include="..\Modules\_testlimitedcapi\float.c" />
     <ClCompile Include="..\Modules\_testlimitedcapi\heaptype_relative.c" />