Skip to content

gh-116417: Move limited C API dict.c tests to _testlimitedcapi #117006

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

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
51 changes: 26 additions & 25 deletions Lib/test/test_capi/test_dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from types import MappingProxyType
from test import support
import _testcapi
import _testlimitedcapi


NULL = None
Expand All @@ -25,7 +26,7 @@ def gen():
class CAPITest(unittest.TestCase):

def test_dict_check(self):
check = _testcapi.dict_check
check = _testlimitedcapi.dict_check
self.assertTrue(check({1: 2}))
self.assertTrue(check(OrderedDict({1: 2})))
self.assertFalse(check(UserDict({1: 2})))
Expand All @@ -34,7 +35,7 @@ def test_dict_check(self):
# CRASHES check(NULL)

def test_dict_checkexact(self):
check = _testcapi.dict_checkexact
check = _testlimitedcapi.dict_checkexact
self.assertTrue(check({1: 2}))
self.assertFalse(check(OrderedDict({1: 2})))
self.assertFalse(check(UserDict({1: 2})))
Expand All @@ -43,15 +44,15 @@ def test_dict_checkexact(self):
# CRASHES check(NULL)

def test_dict_new(self):
dict_new = _testcapi.dict_new
dict_new = _testlimitedcapi.dict_new
dct = dict_new()
self.assertEqual(dct, {})
self.assertIs(type(dct), dict)
dct2 = dict_new()
self.assertIsNot(dct2, dct)

def test_dictproxy_new(self):
dictproxy_new = _testcapi.dictproxy_new
dictproxy_new = _testlimitedcapi.dictproxy_new
for dct in {1: 2}, OrderedDict({1: 2}), UserDict({1: 2}):
proxy = dictproxy_new(dct)
self.assertIs(type(proxy), MappingProxyType)
Expand All @@ -67,7 +68,7 @@ def test_dictproxy_new(self):
# CRASHES dictproxy_new(NULL)

def test_dict_copy(self):
copy = _testcapi.dict_copy
copy = _testlimitedcapi.dict_copy
for dct in {1: 2}, OrderedDict({1: 2}):
dct_copy = copy(dct)
self.assertIs(type(dct_copy), dict)
Expand All @@ -79,7 +80,7 @@ def test_dict_copy(self):
self.assertRaises(SystemError, copy, NULL)

def test_dict_clear(self):
clear = _testcapi.dict_clear
clear = _testlimitedcapi.dict_clear
dct = {1: 2}
clear(dct)
self.assertEqual(dct, {})
Expand All @@ -98,7 +99,7 @@ def test_dict_clear(self):
# CRASHES? clear(NULL)

def test_dict_size(self):
size = _testcapi.dict_size
size = _testlimitedcapi.dict_size
self.assertEqual(size({1: 2}), 1)
self.assertEqual(size(OrderedDict({1: 2})), 1)

Expand All @@ -109,7 +110,7 @@ def test_dict_size(self):
self.assertRaises(SystemError, size, NULL)

def test_dict_getitem(self):
getitem = _testcapi.dict_getitem
getitem = _testlimitedcapi.dict_getitem
dct = {'a': 1, '\U0001f40d': 2}
self.assertEqual(getitem(dct, 'a'), 1)
self.assertIs(getitem(dct, 'b'), KeyError)
Expand All @@ -131,7 +132,7 @@ def test_dict_getitem(self):
# CRASHES getitem(NULL, 'a')

def test_dict_getitemstring(self):
getitemstring = _testcapi.dict_getitemstring
getitemstring = _testlimitedcapi.dict_getitemstring
dct = {'a': 1, '\U0001f40d': 2}
self.assertEqual(getitemstring(dct, b'a'), 1)
self.assertIs(getitemstring(dct, b'b'), KeyError)
Expand Down Expand Up @@ -188,7 +189,7 @@ def test_dict_getitemstringref(self):
# CRASHES getitemstring(NULL, b'a')

def test_dict_getitemwitherror(self):
getitem = _testcapi.dict_getitemwitherror
getitem = _testlimitedcapi.dict_getitemwitherror
dct = {'a': 1, '\U0001f40d': 2}
self.assertEqual(getitem(dct, 'a'), 1)
self.assertIs(getitem(dct, 'b'), KeyError)
Expand All @@ -206,7 +207,7 @@ def test_dict_getitemwitherror(self):
# CRASHES getitem(NULL, 'a')

def test_dict_contains(self):
contains = _testcapi.dict_contains
contains = _testlimitedcapi.dict_contains
dct = {'a': 1, '\U0001f40d': 2}
self.assertTrue(contains(dct, 'a'))
self.assertFalse(contains(dct, 'b'))
Expand Down Expand Up @@ -238,7 +239,7 @@ def test_dict_contains_string(self):
# CRASHES contains(NULL, b'a')

def test_dict_setitem(self):
setitem = _testcapi.dict_setitem
setitem = _testlimitedcapi.dict_setitem
dct = {}
setitem(dct, 'a', 5)
self.assertEqual(dct, {'a': 5})
Expand All @@ -258,7 +259,7 @@ def test_dict_setitem(self):
# CRASHES setitem(NULL, 'a', 5)

def test_dict_setitemstring(self):
setitemstring = _testcapi.dict_setitemstring
setitemstring = _testlimitedcapi.dict_setitemstring
dct = {}
setitemstring(dct, b'a', 5)
self.assertEqual(dct, {'a': 5})
Expand All @@ -277,7 +278,7 @@ def test_dict_setitemstring(self):
# CRASHES setitemstring(NULL, b'a', 5)

def test_dict_delitem(self):
delitem = _testcapi.dict_delitem
delitem = _testlimitedcapi.dict_delitem
dct = {'a': 1, 'c': 2, '\U0001f40d': 3}
delitem(dct, 'a')
self.assertEqual(dct, {'c': 2, '\U0001f40d': 3})
Expand All @@ -298,7 +299,7 @@ def test_dict_delitem(self):
# CRASHES delitem(NULL, 'a')

def test_dict_delitemstring(self):
delitemstring = _testcapi.dict_delitemstring
delitemstring = _testlimitedcapi.dict_delitemstring
dct = {'a': 1, 'c': 2, '\U0001f40d': 3}
delitemstring(dct, b'a')
self.assertEqual(dct, {'c': 2, '\U0001f40d': 3})
Expand Down Expand Up @@ -371,21 +372,21 @@ def items(self):
return None
dict_obj = {'foo': 1, 'bar': 2, 'spam': 3}
for mapping in [dict_obj, DictSubclass(dict_obj), BadMapping(dict_obj)]:
self.assertListEqual(_testcapi.dict_keys(mapping),
self.assertListEqual(_testlimitedcapi.dict_keys(mapping),
list(dict_obj.keys()))
self.assertListEqual(_testcapi.dict_values(mapping),
self.assertListEqual(_testlimitedcapi.dict_values(mapping),
list(dict_obj.values()))
self.assertListEqual(_testcapi.dict_items(mapping),
self.assertListEqual(_testlimitedcapi.dict_items(mapping),
list(dict_obj.items()))

def test_dict_keys_valuesitems_bad_arg(self):
for mapping in UserDict(), [], object():
self.assertRaises(SystemError, _testcapi.dict_keys, mapping)
self.assertRaises(SystemError, _testcapi.dict_values, mapping)
self.assertRaises(SystemError, _testcapi.dict_items, mapping)
self.assertRaises(SystemError, _testlimitedcapi.dict_keys, mapping)
self.assertRaises(SystemError, _testlimitedcapi.dict_values, mapping)
self.assertRaises(SystemError, _testlimitedcapi.dict_items, mapping)

def test_dict_next(self):
dict_next = _testcapi.dict_next
dict_next = _testlimitedcapi.dict_next
self.assertIsNone(dict_next({}, 0))
dct = {'a': 1, 'b': 2, 'c': 3}
pos = 0
Expand All @@ -402,7 +403,7 @@ def test_dict_next(self):
# CRASHES dict_next(NULL, 0)

def test_dict_update(self):
update = _testcapi.dict_update
update = _testlimitedcapi.dict_update
for cls1 in dict, DictSubclass:
for cls2 in dict, DictSubclass, UserDict:
dct = cls1({'a': 1, 'b': 2})
Expand All @@ -417,7 +418,7 @@ def test_dict_update(self):
self.assertRaises(SystemError, update, NULL, {})

def test_dict_merge(self):
merge = _testcapi.dict_merge
merge = _testlimitedcapi.dict_merge
for cls1 in dict, DictSubclass:
for cls2 in dict, DictSubclass, UserDict:
dct = cls1({'a': 1, 'b': 2})
Expand All @@ -435,7 +436,7 @@ def test_dict_merge(self):
self.assertRaises(SystemError, merge, NULL, {}, 0)

def test_dict_mergefromseq2(self):
mergefromseq2 = _testcapi.dict_mergefromseq2
mergefromseq2 = _testlimitedcapi.dict_mergefromseq2
for cls1 in dict, DictSubclass:
for cls2 in list, iter:
dct = cls1({'a': 1, 'b': 2})
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/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/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

Expand Down
Loading