@@ -286,34 +286,121 @@ def test_keys_is_set_less(self, cls: Type[MutableMultiMapping[str]]) -> None:
286
286
287
287
assert d .keys () < {"key" , "key2" }
288
288
289
- def test_keys_is_set_less_equal (self , cls : Type [MutableMultiMapping [str ]]) -> None :
290
- d = cls ([("key" , "value1" )])
289
+ @pytest .mark .parametrize (
290
+ ("contents" , "expected" ),
291
+ (
292
+ ([("key" , "value1" )], True ),
293
+ ([("key" , "value1" ), ("key2" , "value2" )], True ),
294
+ ([("key" , "value1" ), ("key2" , "value2" ), ("key3" , "value3" )], False ),
295
+ ([("key" , "value1" ), ("key3" , "value3" )], False ),
296
+ ),
297
+ )
298
+ def test_keys_is_set_less_equal (
299
+ self ,
300
+ cls : Type [MutableMultiMapping [str ]],
301
+ contents : List [Tuple [str , str ]],
302
+ expected : bool ,
303
+ ) -> None :
304
+ d = cls (contents )
291
305
292
- assert d .keys () <= {"key" }
306
+ result = d .keys () <= {"key" , "key2" }
307
+ assert result is expected
293
308
294
309
def test_keys_is_set_equal (self , cls : Type [MutableMultiMapping [str ]]) -> None :
295
310
d = cls ([("key" , "value1" )])
296
311
297
312
assert d .keys () == {"key" }
298
313
299
314
def test_keys_is_set_greater (self , cls : Type [MutableMultiMapping [str ]]) -> None :
300
- d = cls ([("key" , "value1" )])
315
+ d = cls ([("key" , "value1" ), ( "key2" , "value2" ) ])
301
316
302
- assert { "key" , "key2" } > d .keys ()
317
+ assert d .keys () > { "key" }
303
318
319
+ @pytest .mark .parametrize (
320
+ ("set_" , "expected" ),
321
+ (
322
+ ({"key" }, True ),
323
+ ({"key" , "key2" }, True ),
324
+ ({"key" , "key2" , "key3" }, False ),
325
+ ({"key3" }, False ),
326
+ ),
327
+ )
304
328
def test_keys_is_set_greater_equal (
305
- self ,
306
- cls : Type [MutableMultiMapping [str ]],
329
+ self , cls : Type [MutableMultiMapping [str ]], set_ : Set [str ], expected : bool
330
+ ) -> None :
331
+ d = cls ([("key" , "value1" ), ("key2" , "value2" )])
332
+
333
+ result = d .keys () >= set_
334
+ assert result is expected
335
+
336
+ def test_keys_less_than_not_implemented (
337
+ self , cls : Type [MutableMultiMapping [str ]]
338
+ ) -> None :
339
+ d = cls ([("key" , "value1" )])
340
+
341
+ sentinel_operation_result = object ()
342
+
343
+ class RightOperand :
344
+ def __gt__ (self , other : KeysView [str ]) -> object :
345
+ assert isinstance (other , KeysView )
346
+ return sentinel_operation_result
347
+
348
+ assert (d .keys () < RightOperand ()) is sentinel_operation_result
349
+
350
+ def test_keys_less_than_or_equal_not_implemented (
351
+ self , cls : Type [MutableMultiMapping [str ]]
307
352
) -> None :
308
353
d = cls ([("key" , "value1" )])
309
354
310
- assert {"key" } >= d .keys ()
355
+ sentinel_operation_result = object ()
356
+
357
+ class RightOperand :
358
+ def __ge__ (self , other : KeysView [str ]) -> object :
359
+ assert isinstance (other , KeysView )
360
+ return sentinel_operation_result
361
+
362
+ assert (d .keys () <= RightOperand ()) is sentinel_operation_result
363
+
364
+ def test_keys_greater_than_not_implemented (
365
+ self , cls : Type [MutableMultiMapping [str ]]
366
+ ) -> None :
367
+ d = cls ([("key" , "value1" )])
368
+
369
+ sentinel_operation_result = object ()
370
+
371
+ class RightOperand :
372
+ def __lt__ (self , other : KeysView [str ]) -> object :
373
+ assert isinstance (other , KeysView )
374
+ return sentinel_operation_result
375
+
376
+ assert (d .keys () > RightOperand ()) is sentinel_operation_result
377
+
378
+ def test_keys_greater_than_or_equal_not_implemented (
379
+ self , cls : Type [MutableMultiMapping [str ]]
380
+ ) -> None :
381
+ d = cls ([("key" , "value1" )])
382
+
383
+ sentinel_operation_result = object ()
384
+
385
+ class RightOperand :
386
+ def __le__ (self , other : KeysView [str ]) -> object :
387
+ assert isinstance (other , KeysView )
388
+ return sentinel_operation_result
389
+
390
+ assert (d .keys () >= RightOperand ()) is sentinel_operation_result
311
391
312
392
def test_keys_is_set_not_equal (self , cls : Type [MutableMultiMapping [str ]]) -> None :
313
393
d = cls ([("key" , "value1" )])
314
394
315
395
assert d .keys () != {"key2" }
316
396
397
+ def test_keys_not_equal_unrelated_type (
398
+ self , cls : Type [MutableMultiMapping [str ]]
399
+ ) -> None :
400
+ d = cls ([("key" , "value1" )])
401
+
402
+ assert d .keys () != "other"
403
+
317
404
def test_eq (self , cls : Type [MutableMultiMapping [str ]]) -> None :
318
405
d = cls ([("key" , "value1" )])
319
406
0 commit comments