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-116417: Move limited C API long.c tests to _testlimitedcapi #117001

Merged
merged 1 commit into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
41 changes: 21 additions & 20 deletions Lib/test/test_capi/test_long.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@

from test.support import import_helper

# Skip this test if the _testcapi module isn't available.
# Skip this test if the _testcapi and _testlimitedcapi modules isn't available.
_testcapi = import_helper.import_module('_testcapi')
_testlimitedcapi = import_helper.import_module('_testlimitedcapi')

NULL = None

Expand Down Expand Up @@ -56,7 +57,7 @@ def test_compact_known(self):

def test_long_check(self):
# Test PyLong_Check()
check = _testcapi.pylong_check
check = _testlimitedcapi.pylong_check
self.assertTrue(check(1))
self.assertTrue(check(123456789012345678901234567890))
self.assertTrue(check(-1))
Expand All @@ -68,7 +69,7 @@ def test_long_check(self):

def test_long_checkexact(self):
# Test PyLong_CheckExact()
check = _testcapi.pylong_checkexact
check = _testlimitedcapi.pylong_checkexact
self.assertTrue(check(1))
self.assertTrue(check(123456789012345678901234567890))
self.assertTrue(check(-1))
Expand All @@ -80,7 +81,7 @@ def test_long_checkexact(self):

def test_long_fromdouble(self):
# Test PyLong_FromDouble()
fromdouble = _testcapi.pylong_fromdouble
fromdouble = _testlimitedcapi.pylong_fromdouble
float_max = sys.float_info.max
for value in (5.0, 5.1, 5.9, -5.1, -5.9, 0.0, -0.0, float_max, -float_max):
with self.subTest(value=value):
Expand All @@ -91,7 +92,7 @@ def test_long_fromdouble(self):

def test_long_fromvoidptr(self):
# Test PyLong_FromVoidPtr()
fromvoidptr = _testcapi.pylong_fromvoidptr
fromvoidptr = _testlimitedcapi.pylong_fromvoidptr
obj = object()
x = fromvoidptr(obj)
y = fromvoidptr(NULL)
Expand All @@ -103,7 +104,7 @@ def test_long_fromvoidptr(self):

def test_long_fromstring(self):
# Test PyLong_FromString()
fromstring = _testcapi.pylong_fromstring
fromstring = _testlimitedcapi.pylong_fromstring
self.assertEqual(fromstring(b'123', 10), (123, 3))
self.assertEqual(fromstring(b'cafe', 16), (0xcafe, 4))
self.assertEqual(fromstring(b'xyz', 36), (44027, 3))
Expand Down Expand Up @@ -163,7 +164,7 @@ def test_long_fromunicodeobject(self):

def test_long_asint(self):
# Test PyLong_AsInt()
PyLong_AsInt = _testcapi.PyLong_AsInt
PyLong_AsInt = _testlimitedcapi.PyLong_AsInt
from _testcapi import INT_MIN, INT_MAX

# round trip (object -> int -> object)
Expand All @@ -186,7 +187,7 @@ def test_long_asint(self):

def test_long_aslong(self):
# Test PyLong_AsLong() and PyLong_FromLong()
aslong = _testcapi.pylong_aslong
aslong = _testlimitedcapi.pylong_aslong
from _testcapi import LONG_MIN, LONG_MAX
# round trip (object -> long -> object)
for value in (LONG_MIN, LONG_MAX, -1, 0, 1, 1234):
Expand All @@ -206,7 +207,7 @@ def test_long_aslong(self):

def test_long_aslongandoverflow(self):
# Test PyLong_AsLongAndOverflow()
aslongandoverflow = _testcapi.pylong_aslongandoverflow
aslongandoverflow = _testlimitedcapi.pylong_aslongandoverflow
from _testcapi import LONG_MIN, LONG_MAX
# round trip (object -> long -> object)
for value in (LONG_MIN, LONG_MAX, -1, 0, 1, 1234):
Expand All @@ -224,7 +225,7 @@ def test_long_aslongandoverflow(self):

def test_long_asunsignedlong(self):
# Test PyLong_AsUnsignedLong() and PyLong_FromUnsignedLong()
asunsignedlong = _testcapi.pylong_asunsignedlong
asunsignedlong = _testlimitedcapi.pylong_asunsignedlong
from _testcapi import ULONG_MAX
# round trip (object -> unsigned long -> object)
for value in (ULONG_MAX, 0, 1, 1234):
Expand All @@ -244,7 +245,7 @@ def test_long_asunsignedlong(self):

def test_long_asunsignedlongmask(self):
# Test PyLong_AsUnsignedLongMask()
asunsignedlongmask = _testcapi.pylong_asunsignedlongmask
asunsignedlongmask = _testlimitedcapi.pylong_asunsignedlongmask
from _testcapi import ULONG_MAX
# round trip (object -> unsigned long -> object)
for value in (ULONG_MAX, 0, 1, 1234):
Expand All @@ -264,7 +265,7 @@ def test_long_asunsignedlongmask(self):

def test_long_aslonglong(self):
# Test PyLong_AsLongLong() and PyLong_FromLongLong()
aslonglong = _testcapi.pylong_aslonglong
aslonglong = _testlimitedcapi.pylong_aslonglong
from _testcapi import LLONG_MIN, LLONG_MAX
# round trip (object -> long long -> object)
for value in (LLONG_MIN, LLONG_MAX, -1, 0, 1, 1234):
Expand All @@ -284,7 +285,7 @@ def test_long_aslonglong(self):

def test_long_aslonglongandoverflow(self):
# Test PyLong_AsLongLongAndOverflow()
aslonglongandoverflow = _testcapi.pylong_aslonglongandoverflow
aslonglongandoverflow = _testlimitedcapi.pylong_aslonglongandoverflow
from _testcapi import LLONG_MIN, LLONG_MAX
# round trip (object -> long long -> object)
for value in (LLONG_MIN, LLONG_MAX, -1, 0, 1, 1234):
Expand All @@ -302,7 +303,7 @@ def test_long_aslonglongandoverflow(self):

def test_long_asunsignedlonglong(self):
# Test PyLong_AsUnsignedLongLong() and PyLong_FromUnsignedLongLong()
asunsignedlonglong = _testcapi.pylong_asunsignedlonglong
asunsignedlonglong = _testlimitedcapi.pylong_asunsignedlonglong
from _testcapi import ULLONG_MAX
# round trip (object -> unsigned long long -> object)
for value in (ULLONG_MAX, 0, 1, 1234):
Expand All @@ -322,7 +323,7 @@ def test_long_asunsignedlonglong(self):

def test_long_asunsignedlonglongmask(self):
# Test PyLong_AsUnsignedLongLongMask()
asunsignedlonglongmask = _testcapi.pylong_asunsignedlonglongmask
asunsignedlonglongmask = _testlimitedcapi.pylong_asunsignedlonglongmask
from _testcapi import ULLONG_MAX
# round trip (object -> unsigned long long -> object)
for value in (ULLONG_MAX, 0, 1, 1234):
Expand All @@ -342,7 +343,7 @@ def test_long_asunsignedlonglongmask(self):

def test_long_as_ssize_t(self):
# Test PyLong_AsSsize_t() and PyLong_FromSsize_t()
as_ssize_t = _testcapi.pylong_as_ssize_t
as_ssize_t = _testlimitedcapi.pylong_as_ssize_t
from _testcapi import PY_SSIZE_T_MIN, PY_SSIZE_T_MAX
# round trip (object -> Py_ssize_t -> object)
for value in (PY_SSIZE_T_MIN, PY_SSIZE_T_MAX, -1, 0, 1, 1234):
Expand All @@ -362,7 +363,7 @@ def test_long_as_ssize_t(self):

def test_long_as_size_t(self):
# Test PyLong_AsSize_t() and PyLong_FromSize_t()
as_size_t = _testcapi.pylong_as_size_t
as_size_t = _testlimitedcapi.pylong_as_size_t
from _testcapi import SIZE_MAX
# round trip (object -> size_t -> object)
for value in (SIZE_MAX, 0, 1, 1234):
Expand All @@ -382,7 +383,7 @@ def test_long_as_size_t(self):

def test_long_asdouble(self):
# Test PyLong_AsDouble()
asdouble = _testcapi.pylong_asdouble
asdouble = _testlimitedcapi.pylong_asdouble
MAX = int(sys.float_info.max)
for value in (-MAX, MAX, -1, 0, 1, 1234):
with self.subTest(value=value):
Expand All @@ -402,8 +403,8 @@ def test_long_asdouble(self):

def test_long_asvoidptr(self):
# Test PyLong_AsVoidPtr()
fromvoidptr = _testcapi.pylong_fromvoidptr
asvoidptr = _testcapi.pylong_asvoidptr
fromvoidptr = _testlimitedcapi.pylong_fromvoidptr
asvoidptr = _testlimitedcapi.pylong_asvoidptr
obj = object()
x = fromvoidptr(obj)
y = fromvoidptr(NULL)
Expand Down
3 changes: 2 additions & 1 deletion Makefile.pre.in
Original file line number Diff line number Diff line change
Expand Up @@ -3051,7 +3051,8 @@ MODULE__SHA2_DEPS=$(srcdir)/Modules/hashlib.h $(LIBHACL_SHA2_HEADERS) $(LIBHACL_
MODULE__SHA3_DEPS=$(srcdir)/Modules/hashlib.h $(LIBHACL_HEADERS) Modules/_hacl/Hacl_Hash_SHA3.h Modules/_hacl/Hacl_Hash_SHA3.c
MODULE__SOCKET_DEPS=$(srcdir)/Modules/socketmodule.h $(srcdir)/Modules/addrinfo.h $(srcdir)/Modules/getaddrinfo.c $(srcdir)/Modules/getnameinfo.c
MODULE__SSL_DEPS=$(srcdir)/Modules/_ssl.h $(srcdir)/Modules/_ssl/cert.c $(srcdir)/Modules/_ssl/debughelpers.c $(srcdir)/Modules/_ssl/misc.c $(srcdir)/Modules/_ssl_data_111.h $(srcdir)/Modules/_ssl_data_300.h $(srcdir)/Modules/socketmodule.h
MODULE__TESTCAPI_DEPS=$(srcdir)/Modules/_testcapi/testcapi_long.h $(srcdir)/Modules/_testcapi/parts.h $(srcdir)/Modules/_testcapi/util.h
MODULE__TESTCAPI_DEPS=$(srcdir)/Modules/_testcapi/parts.h $(srcdir)/Modules/_testcapi/util.h
MODULE__TESTLIMITEDCAPI_DEPS=$(srcdir)/Modules/_testlimitedcapi/testcapi_long.h $(srcdir)/Modules/_testlimitedcapi/parts.h $(srcdir)/Modules/_testlimitedcapi/util.h
MODULE__TESTINTERNALCAPI_DEPS=$(srcdir)/Modules/_testinternalcapi/parts.h
MODULE__SQLITE3_DEPS=$(srcdir)/Modules/_sqlite/connection.h $(srcdir)/Modules/_sqlite/cursor.h $(srcdir)/Modules/_sqlite/microprotocols.h $(srcdir)/Modules/_sqlite/module.h $(srcdir)/Modules/_sqlite/prepare_protocol.h $(srcdir)/Modules/_sqlite/row.h $(srcdir)/Modules/_sqlite/util.h

Expand Down
2 changes: 1 addition & 1 deletion Modules/Setup.stdlib.in
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@
@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/float.c _testlimitedcapi/heaptype_relative.c _testlimitedcapi/list.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/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

Expand Down
141 changes: 1 addition & 140 deletions Modules/_testcapi/clinic/long.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading