3
3
from types import MappingProxyType
4
4
from test import support
5
5
import _testcapi
6
+ import _testlimitedcapi
6
7
7
8
8
9
NULL = None
@@ -25,7 +26,7 @@ def gen():
25
26
class CAPITest (unittest .TestCase ):
26
27
27
28
def test_dict_check (self ):
28
- check = _testcapi .dict_check
29
+ check = _testlimitedcapi .dict_check
29
30
self .assertTrue (check ({1 : 2 }))
30
31
self .assertTrue (check (OrderedDict ({1 : 2 })))
31
32
self .assertFalse (check (UserDict ({1 : 2 })))
@@ -34,7 +35,7 @@ def test_dict_check(self):
34
35
# CRASHES check(NULL)
35
36
36
37
def test_dict_checkexact (self ):
37
- check = _testcapi .dict_checkexact
38
+ check = _testlimitedcapi .dict_checkexact
38
39
self .assertTrue (check ({1 : 2 }))
39
40
self .assertFalse (check (OrderedDict ({1 : 2 })))
40
41
self .assertFalse (check (UserDict ({1 : 2 })))
@@ -43,15 +44,15 @@ def test_dict_checkexact(self):
43
44
# CRASHES check(NULL)
44
45
45
46
def test_dict_new (self ):
46
- dict_new = _testcapi .dict_new
47
+ dict_new = _testlimitedcapi .dict_new
47
48
dct = dict_new ()
48
49
self .assertEqual (dct , {})
49
50
self .assertIs (type (dct ), dict )
50
51
dct2 = dict_new ()
51
52
self .assertIsNot (dct2 , dct )
52
53
53
54
def test_dictproxy_new (self ):
54
- dictproxy_new = _testcapi .dictproxy_new
55
+ dictproxy_new = _testlimitedcapi .dictproxy_new
55
56
for dct in {1 : 2 }, OrderedDict ({1 : 2 }), UserDict ({1 : 2 }):
56
57
proxy = dictproxy_new (dct )
57
58
self .assertIs (type (proxy ), MappingProxyType )
@@ -67,7 +68,7 @@ def test_dictproxy_new(self):
67
68
# CRASHES dictproxy_new(NULL)
68
69
69
70
def test_dict_copy (self ):
70
- copy = _testcapi .dict_copy
71
+ copy = _testlimitedcapi .dict_copy
71
72
for dct in {1 : 2 }, OrderedDict ({1 : 2 }):
72
73
dct_copy = copy (dct )
73
74
self .assertIs (type (dct_copy ), dict )
@@ -79,7 +80,7 @@ def test_dict_copy(self):
79
80
self .assertRaises (SystemError , copy , NULL )
80
81
81
82
def test_dict_clear (self ):
82
- clear = _testcapi .dict_clear
83
+ clear = _testlimitedcapi .dict_clear
83
84
dct = {1 : 2 }
84
85
clear (dct )
85
86
self .assertEqual (dct , {})
@@ -98,7 +99,7 @@ def test_dict_clear(self):
98
99
# CRASHES? clear(NULL)
99
100
100
101
def test_dict_size (self ):
101
- size = _testcapi .dict_size
102
+ size = _testlimitedcapi .dict_size
102
103
self .assertEqual (size ({1 : 2 }), 1 )
103
104
self .assertEqual (size (OrderedDict ({1 : 2 })), 1 )
104
105
@@ -109,7 +110,7 @@ def test_dict_size(self):
109
110
self .assertRaises (SystemError , size , NULL )
110
111
111
112
def test_dict_getitem (self ):
112
- getitem = _testcapi .dict_getitem
113
+ getitem = _testlimitedcapi .dict_getitem
113
114
dct = {'a' : 1 , '\U0001f40d ' : 2 }
114
115
self .assertEqual (getitem (dct , 'a' ), 1 )
115
116
self .assertIs (getitem (dct , 'b' ), KeyError )
@@ -131,7 +132,7 @@ def test_dict_getitem(self):
131
132
# CRASHES getitem(NULL, 'a')
132
133
133
134
def test_dict_getitemstring (self ):
134
- getitemstring = _testcapi .dict_getitemstring
135
+ getitemstring = _testlimitedcapi .dict_getitemstring
135
136
dct = {'a' : 1 , '\U0001f40d ' : 2 }
136
137
self .assertEqual (getitemstring (dct , b'a' ), 1 )
137
138
self .assertIs (getitemstring (dct , b'b' ), KeyError )
@@ -188,7 +189,7 @@ def test_dict_getitemstringref(self):
188
189
# CRASHES getitemstring(NULL, b'a')
189
190
190
191
def test_dict_getitemwitherror (self ):
191
- getitem = _testcapi .dict_getitemwitherror
192
+ getitem = _testlimitedcapi .dict_getitemwitherror
192
193
dct = {'a' : 1 , '\U0001f40d ' : 2 }
193
194
self .assertEqual (getitem (dct , 'a' ), 1 )
194
195
self .assertIs (getitem (dct , 'b' ), KeyError )
@@ -206,7 +207,7 @@ def test_dict_getitemwitherror(self):
206
207
# CRASHES getitem(NULL, 'a')
207
208
208
209
def test_dict_contains (self ):
209
- contains = _testcapi .dict_contains
210
+ contains = _testlimitedcapi .dict_contains
210
211
dct = {'a' : 1 , '\U0001f40d ' : 2 }
211
212
self .assertTrue (contains (dct , 'a' ))
212
213
self .assertFalse (contains (dct , 'b' ))
@@ -238,7 +239,7 @@ def test_dict_contains_string(self):
238
239
# CRASHES contains(NULL, b'a')
239
240
240
241
def test_dict_setitem (self ):
241
- setitem = _testcapi .dict_setitem
242
+ setitem = _testlimitedcapi .dict_setitem
242
243
dct = {}
243
244
setitem (dct , 'a' , 5 )
244
245
self .assertEqual (dct , {'a' : 5 })
@@ -258,7 +259,7 @@ def test_dict_setitem(self):
258
259
# CRASHES setitem(NULL, 'a', 5)
259
260
260
261
def test_dict_setitemstring (self ):
261
- setitemstring = _testcapi .dict_setitemstring
262
+ setitemstring = _testlimitedcapi .dict_setitemstring
262
263
dct = {}
263
264
setitemstring (dct , b'a' , 5 )
264
265
self .assertEqual (dct , {'a' : 5 })
@@ -277,7 +278,7 @@ def test_dict_setitemstring(self):
277
278
# CRASHES setitemstring(NULL, b'a', 5)
278
279
279
280
def test_dict_delitem (self ):
280
- delitem = _testcapi .dict_delitem
281
+ delitem = _testlimitedcapi .dict_delitem
281
282
dct = {'a' : 1 , 'c' : 2 , '\U0001f40d ' : 3 }
282
283
delitem (dct , 'a' )
283
284
self .assertEqual (dct , {'c' : 2 , '\U0001f40d ' : 3 })
@@ -298,7 +299,7 @@ def test_dict_delitem(self):
298
299
# CRASHES delitem(NULL, 'a')
299
300
300
301
def test_dict_delitemstring (self ):
301
- delitemstring = _testcapi .dict_delitemstring
302
+ delitemstring = _testlimitedcapi .dict_delitemstring
302
303
dct = {'a' : 1 , 'c' : 2 , '\U0001f40d ' : 3 }
303
304
delitemstring (dct , b'a' )
304
305
self .assertEqual (dct , {'c' : 2 , '\U0001f40d ' : 3 })
@@ -371,21 +372,21 @@ def items(self):
371
372
return None
372
373
dict_obj = {'foo' : 1 , 'bar' : 2 , 'spam' : 3 }
373
374
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 ),
375
376
list (dict_obj .keys ()))
376
- self .assertListEqual (_testcapi .dict_values (mapping ),
377
+ self .assertListEqual (_testlimitedcapi .dict_values (mapping ),
377
378
list (dict_obj .values ()))
378
- self .assertListEqual (_testcapi .dict_items (mapping ),
379
+ self .assertListEqual (_testlimitedcapi .dict_items (mapping ),
379
380
list (dict_obj .items ()))
380
381
381
382
def test_dict_keys_valuesitems_bad_arg (self ):
382
383
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 )
386
387
387
388
def test_dict_next (self ):
388
- dict_next = _testcapi .dict_next
389
+ dict_next = _testlimitedcapi .dict_next
389
390
self .assertIsNone (dict_next ({}, 0 ))
390
391
dct = {'a' : 1 , 'b' : 2 , 'c' : 3 }
391
392
pos = 0
@@ -402,7 +403,7 @@ def test_dict_next(self):
402
403
# CRASHES dict_next(NULL, 0)
403
404
404
405
def test_dict_update (self ):
405
- update = _testcapi .dict_update
406
+ update = _testlimitedcapi .dict_update
406
407
for cls1 in dict , DictSubclass :
407
408
for cls2 in dict , DictSubclass , UserDict :
408
409
dct = cls1 ({'a' : 1 , 'b' : 2 })
@@ -417,7 +418,7 @@ def test_dict_update(self):
417
418
self .assertRaises (SystemError , update , NULL , {})
418
419
419
420
def test_dict_merge (self ):
420
- merge = _testcapi .dict_merge
421
+ merge = _testlimitedcapi .dict_merge
421
422
for cls1 in dict , DictSubclass :
422
423
for cls2 in dict , DictSubclass , UserDict :
423
424
dct = cls1 ({'a' : 1 , 'b' : 2 })
@@ -435,7 +436,7 @@ def test_dict_merge(self):
435
436
self .assertRaises (SystemError , merge , NULL , {}, 0 )
436
437
437
438
def test_dict_mergefromseq2 (self ):
438
- mergefromseq2 = _testcapi .dict_mergefromseq2
439
+ mergefromseq2 = _testlimitedcapi .dict_mergefromseq2
439
440
for cls1 in dict , DictSubclass :
440
441
for cls2 in list , iter :
441
442
dct = cls1 ({'a' : 1 , 'b' : 2 })
0 commit comments