33from types import MappingProxyType
44from test import support
55import _testcapi
6+ import _testlimitedcapi
67
78
89NULL = None
@@ -25,7 +26,7 @@ def gen():
2526class CAPITest (unittest .TestCase ):
2627
2728 def test_dict_check (self ):
28- check = _testcapi .dict_check
29+ check = _testlimitedcapi .dict_check
2930 self .assertTrue (check ({1 : 2 }))
3031 self .assertTrue (check (OrderedDict ({1 : 2 })))
3132 self .assertFalse (check (UserDict ({1 : 2 })))
@@ -34,7 +35,7 @@ def test_dict_check(self):
3435 # CRASHES check(NULL)
3536
3637 def test_dict_checkexact (self ):
37- check = _testcapi .dict_checkexact
38+ check = _testlimitedcapi .dict_checkexact
3839 self .assertTrue (check ({1 : 2 }))
3940 self .assertFalse (check (OrderedDict ({1 : 2 })))
4041 self .assertFalse (check (UserDict ({1 : 2 })))
@@ -43,15 +44,15 @@ def test_dict_checkexact(self):
4344 # CRASHES check(NULL)
4445
4546 def test_dict_new (self ):
46- dict_new = _testcapi .dict_new
47+ dict_new = _testlimitedcapi .dict_new
4748 dct = dict_new ()
4849 self .assertEqual (dct , {})
4950 self .assertIs (type (dct ), dict )
5051 dct2 = dict_new ()
5152 self .assertIsNot (dct2 , dct )
5253
5354 def test_dictproxy_new (self ):
54- dictproxy_new = _testcapi .dictproxy_new
55+ dictproxy_new = _testlimitedcapi .dictproxy_new
5556 for dct in {1 : 2 }, OrderedDict ({1 : 2 }), UserDict ({1 : 2 }):
5657 proxy = dictproxy_new (dct )
5758 self .assertIs (type (proxy ), MappingProxyType )
@@ -67,7 +68,7 @@ def test_dictproxy_new(self):
6768 # CRASHES dictproxy_new(NULL)
6869
6970 def test_dict_copy (self ):
70- copy = _testcapi .dict_copy
71+ copy = _testlimitedcapi .dict_copy
7172 for dct in {1 : 2 }, OrderedDict ({1 : 2 }):
7273 dct_copy = copy (dct )
7374 self .assertIs (type (dct_copy ), dict )
@@ -79,7 +80,7 @@ def test_dict_copy(self):
7980 self .assertRaises (SystemError , copy , NULL )
8081
8182 def test_dict_clear (self ):
82- clear = _testcapi .dict_clear
83+ clear = _testlimitedcapi .dict_clear
8384 dct = {1 : 2 }
8485 clear (dct )
8586 self .assertEqual (dct , {})
@@ -98,7 +99,7 @@ def test_dict_clear(self):
9899 # CRASHES? clear(NULL)
99100
100101 def test_dict_size (self ):
101- size = _testcapi .dict_size
102+ size = _testlimitedcapi .dict_size
102103 self .assertEqual (size ({1 : 2 }), 1 )
103104 self .assertEqual (size (OrderedDict ({1 : 2 })), 1 )
104105
@@ -109,7 +110,7 @@ def test_dict_size(self):
109110 self .assertRaises (SystemError , size , NULL )
110111
111112 def test_dict_getitem (self ):
112- getitem = _testcapi .dict_getitem
113+ getitem = _testlimitedcapi .dict_getitem
113114 dct = {'a' : 1 , '\U0001f40d ' : 2 }
114115 self .assertEqual (getitem (dct , 'a' ), 1 )
115116 self .assertIs (getitem (dct , 'b' ), KeyError )
@@ -131,7 +132,7 @@ def test_dict_getitem(self):
131132 # CRASHES getitem(NULL, 'a')
132133
133134 def test_dict_getitemstring (self ):
134- getitemstring = _testcapi .dict_getitemstring
135+ getitemstring = _testlimitedcapi .dict_getitemstring
135136 dct = {'a' : 1 , '\U0001f40d ' : 2 }
136137 self .assertEqual (getitemstring (dct , b'a' ), 1 )
137138 self .assertIs (getitemstring (dct , b'b' ), KeyError )
@@ -188,7 +189,7 @@ def test_dict_getitemstringref(self):
188189 # CRASHES getitemstring(NULL, b'a')
189190
190191 def test_dict_getitemwitherror (self ):
191- getitem = _testcapi .dict_getitemwitherror
192+ getitem = _testlimitedcapi .dict_getitemwitherror
192193 dct = {'a' : 1 , '\U0001f40d ' : 2 }
193194 self .assertEqual (getitem (dct , 'a' ), 1 )
194195 self .assertIs (getitem (dct , 'b' ), KeyError )
@@ -206,7 +207,7 @@ def test_dict_getitemwitherror(self):
206207 # CRASHES getitem(NULL, 'a')
207208
208209 def test_dict_contains (self ):
209- contains = _testcapi .dict_contains
210+ contains = _testlimitedcapi .dict_contains
210211 dct = {'a' : 1 , '\U0001f40d ' : 2 }
211212 self .assertTrue (contains (dct , 'a' ))
212213 self .assertFalse (contains (dct , 'b' ))
@@ -238,7 +239,7 @@ def test_dict_contains_string(self):
238239 # CRASHES contains(NULL, b'a')
239240
240241 def test_dict_setitem (self ):
241- setitem = _testcapi .dict_setitem
242+ setitem = _testlimitedcapi .dict_setitem
242243 dct = {}
243244 setitem (dct , 'a' , 5 )
244245 self .assertEqual (dct , {'a' : 5 })
@@ -258,7 +259,7 @@ def test_dict_setitem(self):
258259 # CRASHES setitem(NULL, 'a', 5)
259260
260261 def test_dict_setitemstring (self ):
261- setitemstring = _testcapi .dict_setitemstring
262+ setitemstring = _testlimitedcapi .dict_setitemstring
262263 dct = {}
263264 setitemstring (dct , b'a' , 5 )
264265 self .assertEqual (dct , {'a' : 5 })
@@ -277,7 +278,7 @@ def test_dict_setitemstring(self):
277278 # CRASHES setitemstring(NULL, b'a', 5)
278279
279280 def test_dict_delitem (self ):
280- delitem = _testcapi .dict_delitem
281+ delitem = _testlimitedcapi .dict_delitem
281282 dct = {'a' : 1 , 'c' : 2 , '\U0001f40d ' : 3 }
282283 delitem (dct , 'a' )
283284 self .assertEqual (dct , {'c' : 2 , '\U0001f40d ' : 3 })
@@ -298,7 +299,7 @@ def test_dict_delitem(self):
298299 # CRASHES delitem(NULL, 'a')
299300
300301 def test_dict_delitemstring (self ):
301- delitemstring = _testcapi .dict_delitemstring
302+ delitemstring = _testlimitedcapi .dict_delitemstring
302303 dct = {'a' : 1 , 'c' : 2 , '\U0001f40d ' : 3 }
303304 delitemstring (dct , b'a' )
304305 self .assertEqual (dct , {'c' : 2 , '\U0001f40d ' : 3 })
@@ -371,21 +372,21 @@ def items(self):
371372 return None
372373 dict_obj = {'foo' : 1 , 'bar' : 2 , 'spam' : 3 }
373374 for mapping in [dict_obj , DictSubclass (dict_obj ), BadMapping (dict_obj )]:
374- self .assertListEqual (_testcapi .dict_keys (mapping ),
375+ self .assertListEqual (_testlimitedcapi .dict_keys (mapping ),
375376 list (dict_obj .keys ()))
376- self .assertListEqual (_testcapi .dict_values (mapping ),
377+ self .assertListEqual (_testlimitedcapi .dict_values (mapping ),
377378 list (dict_obj .values ()))
378- self .assertListEqual (_testcapi .dict_items (mapping ),
379+ self .assertListEqual (_testlimitedcapi .dict_items (mapping ),
379380 list (dict_obj .items ()))
380381
381382 def test_dict_keys_valuesitems_bad_arg (self ):
382383 for mapping in UserDict (), [], object ():
383- self .assertRaises (SystemError , _testcapi .dict_keys , mapping )
384- self .assertRaises (SystemError , _testcapi .dict_values , mapping )
385- self .assertRaises (SystemError , _testcapi .dict_items , mapping )
384+ self .assertRaises (SystemError , _testlimitedcapi .dict_keys , mapping )
385+ self .assertRaises (SystemError , _testlimitedcapi .dict_values , mapping )
386+ self .assertRaises (SystemError , _testlimitedcapi .dict_items , mapping )
386387
387388 def test_dict_next (self ):
388- dict_next = _testcapi .dict_next
389+ dict_next = _testlimitedcapi .dict_next
389390 self .assertIsNone (dict_next ({}, 0 ))
390391 dct = {'a' : 1 , 'b' : 2 , 'c' : 3 }
391392 pos = 0
@@ -402,7 +403,7 @@ def test_dict_next(self):
402403 # CRASHES dict_next(NULL, 0)
403404
404405 def test_dict_update (self ):
405- update = _testcapi .dict_update
406+ update = _testlimitedcapi .dict_update
406407 for cls1 in dict , DictSubclass :
407408 for cls2 in dict , DictSubclass , UserDict :
408409 dct = cls1 ({'a' : 1 , 'b' : 2 })
@@ -417,7 +418,7 @@ def test_dict_update(self):
417418 self .assertRaises (SystemError , update , NULL , {})
418419
419420 def test_dict_merge (self ):
420- merge = _testcapi .dict_merge
421+ merge = _testlimitedcapi .dict_merge
421422 for cls1 in dict , DictSubclass :
422423 for cls2 in dict , DictSubclass , UserDict :
423424 dct = cls1 ({'a' : 1 , 'b' : 2 })
@@ -435,7 +436,7 @@ def test_dict_merge(self):
435436 self .assertRaises (SystemError , merge , NULL , {}, 0 )
436437
437438 def test_dict_mergefromseq2 (self ):
438- mergefromseq2 = _testcapi .dict_mergefromseq2
439+ mergefromseq2 = _testlimitedcapi .dict_mergefromseq2
439440 for cls1 in dict , DictSubclass :
440441 for cls2 in list , iter :
441442 dct = cls1 ({'a' : 1 , 'b' : 2 })
0 commit comments