@@ -48,7 +48,18 @@ def _reference_get_item(args):
48
48
return d .get (args [1 ])
49
49
except Exception :
50
50
return None
51
-
51
+
52
+ def _reference_values (args ):
53
+ d = args [0 ]
54
+ return list (d .values ())
55
+
56
+ def _reference_pop (args ):
57
+ d = args [0 ]
58
+ if (len (args ) == 2 ):
59
+ return d .pop (args [1 ])
60
+ else :
61
+ return d .pop (args [1 ], args [2 ])
62
+
52
63
53
64
def _reference_get_item_with_error (args ):
54
65
d = args [0 ]
@@ -119,14 +130,20 @@ def _reference_clear(args):
119
130
120
131
121
132
def _reference_merge (args ):
122
- a , b , override = args
123
- if override :
124
- a .update (b )
125
- else :
126
- for k in b :
127
- if not k in a :
128
- a [k ] = b [k ]
129
- return 0
133
+ try :
134
+ a , b , override = args
135
+ if override :
136
+ a .update (b )
137
+ else :
138
+ for k in b .keys ():
139
+ if not k in a :
140
+ a [k ] = b [k ]
141
+ return 0
142
+ except :
143
+ if sys .version_info .minor >= 6 :
144
+ raise SystemError
145
+ else :
146
+ return - 1
130
147
131
148
class SubDict (dict ):
132
149
pass
@@ -151,13 +168,28 @@ def __eq__(self, other):
151
168
def __hash__ (self ):
152
169
return hash (self .s )
153
170
154
-
171
+ class MappingObj :
172
+ def keys (self ):
173
+ return "ab"
174
+ def __getitem__ (self , key ):
175
+ return key
176
+
155
177
class TestPyDict (CPyExtTestCase ):
156
178
157
179
def compile_module (self , name ):
158
180
type (self ).mro ()[1 ].__dict__ ["test_%s" % name ].create_module (name )
159
181
super (TestPyDict , self ).compile_module (name )
160
182
183
+ # PyDict_Pop
184
+ test__PyDict_Pop = CPyExtFunction (
185
+ _reference_pop ,
186
+ lambda : (({}, "a" , "42" ), ({'a' : "hello" }, "a" , "42" ), ({'a' : "hello" }, "b" , "42" ), ({BadEq ('a' ): "hello" }, "a" , "42" )),
187
+ resultspec = "O" ,
188
+ argspec = 'OOO' ,
189
+ arguments = ("PyObject* dict" , "PyObject* key" , "PyObject* deflt" ),
190
+ cmpfunc = unhandled_error_compare
191
+ )
192
+
161
193
# PyDict_SetItem
162
194
test_PyDict_SetItem = CPyExtFunction (
163
195
_reference_set_item ,
@@ -191,7 +223,7 @@ def compile_module(self, name):
191
223
callfunction = "wrap_PyDict_GetItem" ,
192
224
cmpfunc = unhandled_error_compare
193
225
)
194
-
226
+
195
227
# PyDict_GetItemWithError
196
228
test_PyDict_GetItemWithError = CPyExtFunction (
197
229
_reference_get_item_with_error ,
@@ -332,12 +364,10 @@ def compile_module(self, name):
332
364
Py_ssize_t ppos = 0;
333
365
PyObject* key;
334
366
PyObject* value;
335
- Py_hash_t phash;
336
-
337
- int res = 0;
367
+ Py_hash_t phash;
338
368
339
369
_PyDict_Next(dict, &ppos, &key, &value, &phash);
340
- res = _PyDict_SetItem_KnownHash(result, key, value, phash);
370
+ _PyDict_SetItem_KnownHash(result, key, value, phash);
341
371
return result;
342
372
}
343
373
''' ,
@@ -466,9 +496,22 @@ def compile_module(self, name):
466
496
(dict (), {"b" : 2 }, 0 ),
467
497
(dict ({"a" : 1 }), {"a" : 2 }, 0 ),
468
498
(dict ({"a" : 1 }), {"a" : 2 }, 1 ),
499
+ (dict ({"a" : 1 }), MappingObj (), 0 ),
500
+ (dict ({"a" : 1 }), MappingObj (), 1 ),
501
+ (dict ({"a" : 1 }), 1 , 1 ),
502
+ (dict ({"a" : 1 }), 1 , 1 ),
469
503
),
470
504
resultspec = "i" ,
471
505
argspec = "OOi" ,
472
506
arguments = ["PyObject* a" , "PyObject* b" , "int override" ],
473
507
cmpfunc = unhandled_error_compare
474
508
)
509
+
510
+ # PyDict_Values
511
+ test_PyDict_Values = CPyExtFunction (
512
+ _reference_values ,
513
+ lambda : (({},), ({'a' : "hello" },)),
514
+ resultspec = "O" ,
515
+ argspec = "O" ,
516
+ cmpfunc = unhandled_error_compare
517
+ )
0 commit comments