@@ -279,26 +279,56 @@ def test_use(self):
279279 for opt in '-u' , '--use' :
280280 with self .subTest (opt = opt ):
281281 ns = self .parse_args ([opt , 'gui,network' ])
282- self .assertEqual (ns .use_resources , ['gui' , 'network' ])
282+ self .assertEqual (ns .use_resources , {'gui' : None , 'network' : None })
283+ ns = self .parse_args ([opt , 'gui' , opt , 'network' ])
284+ self .assertEqual (ns .use_resources , {'gui' : None , 'network' : None })
283285
284286 ns = self .parse_args ([opt , 'gui,none,network' ])
285- self .assertEqual (ns .use_resources , ['network' ])
287+ self .assertEqual (ns .use_resources , {'network' : None })
288+ ns = self .parse_args ([opt , 'gui' , opt , 'none' , opt , 'network' ])
289+ self .assertEqual (ns .use_resources , {'network' : None })
286290
287- expected = list (cmdline .ALL_RESOURCES )
288- expected . remove ( 'gui' )
291+ expected = dict . fromkeys (cmdline .ALL_RESOURCES )
292+ del expected [ 'gui' ]
289293 ns = self .parse_args ([opt , 'all,-gui' ])
290294 self .assertEqual (ns .use_resources , expected )
295+
291296 self .checkError ([opt ], 'expected one argument' )
292297 self .checkError ([opt , 'foo' ], 'invalid resource' )
293298
294299 # all + a resource not part of "all"
300+ expected = dict .fromkeys (cmdline .ALL_RESOURCES )
301+ expected ['tzdata' ] = None
295302 ns = self .parse_args ([opt , 'all,tzdata' ])
296- self .assertEqual (ns .use_resources ,
297- list (cmdline .ALL_RESOURCES ) + ['tzdata' ])
303+ self .assertEqual (ns .use_resources , expected )
304+ ns = self .parse_args ([opt , 'all' , opt , 'tzdata' ])
305+ self .assertEqual (ns .use_resources , expected )
298306
299307 # test another resource which is not part of "all"
300308 ns = self .parse_args ([opt , 'extralargefile' ])
301- self .assertEqual (ns .use_resources , ['extralargefile' ])
309+ self .assertEqual (ns .use_resources , {'extralargefile' : None })
310+
311+ # test resource with value
312+ ns = self .parse_args ([opt , 'xpickle=2.7' ])
313+ self .assertEqual (ns .use_resources , {'xpickle' : '2.7' })
314+ ns = self .parse_args ([opt , 'xpickle=2.7,xpickle=3.3' ])
315+ self .assertEqual (ns .use_resources , {'xpickle' : '3.3' })
316+ ns = self .parse_args ([opt , 'xpickle=2.7,none' ])
317+ self .assertEqual (ns .use_resources , {})
318+ ns = self .parse_args ([opt , 'xpickle=2.7,-xpickle' ])
319+ self .assertEqual (ns .use_resources , {})
320+
321+ expected = dict .fromkeys (cmdline .ALL_RESOURCES )
322+ expected ['xpickle' ] = '2.7'
323+ ns = self .parse_args ([opt , 'all,xpickle=2.7' ])
324+ self .assertEqual (ns .use_resources , expected )
325+ ns = self .parse_args ([opt , 'all' , opt , 'xpickle=2.7' ])
326+ self .assertEqual (ns .use_resources , expected )
327+
328+ # test invalid resources with value
329+ self .checkError ([opt , 'all=0' ], 'invalid resource: all=0' )
330+ self .checkError ([opt , 'none=0' ], 'invalid resource: none=0' )
331+ self .checkError ([opt , 'all,-gui=0' ], 'invalid resource: -gui=0' )
302332
303333 def test_memlimit (self ):
304334 for opt in '-M' , '--memlimit' :
@@ -459,53 +489,54 @@ def check_ci_mode(self, args, use_resources,
459489 self .assertTrue (regrtest .fail_env_changed )
460490 self .assertTrue (regrtest .print_slowest )
461491 self .assertEqual (regrtest .output_on_failure , output_on_failure )
462- self .assertEqual (sorted ( regrtest .use_resources ), sorted ( use_resources ) )
492+ self .assertEqual (regrtest .use_resources , use_resources )
463493 return regrtest
464494
465495 def test_fast_ci (self ):
466496 args = ['--fast-ci' ]
467- use_resources = sorted (cmdline .ALL_RESOURCES )
468- use_resources . remove ( 'cpu' )
497+ use_resources = dict . fromkeys (cmdline .ALL_RESOURCES )
498+ del use_resources [ 'cpu' ]
469499 regrtest = self .check_ci_mode (args , use_resources )
470500 self .assertEqual (regrtest .timeout , 10 * 60 )
471501
472502 def test_fast_ci_python_cmd (self ):
473503 args = ['--fast-ci' , '--python' , 'python -X dev' ]
474- use_resources = sorted (cmdline .ALL_RESOURCES )
475- use_resources . remove ( 'cpu' )
504+ use_resources = dict . fromkeys (cmdline .ALL_RESOURCES )
505+ del use_resources [ 'cpu' ]
476506 regrtest = self .check_ci_mode (args , use_resources , rerun = False )
477507 self .assertEqual (regrtest .timeout , 10 * 60 )
478508 self .assertEqual (regrtest .python_cmd , ('python' , '-X' , 'dev' ))
479509
480510 def test_fast_ci_resource (self ):
481511 # it should be possible to override resources individually
482512 args = ['--fast-ci' , '-u-network' ]
483- use_resources = sorted (cmdline .ALL_RESOURCES )
484- use_resources . remove ( 'cpu' )
485- use_resources . remove ( 'network' )
513+ use_resources = dict . fromkeys (cmdline .ALL_RESOURCES )
514+ del use_resources [ 'cpu' ]
515+ del use_resources [ 'network' ]
486516 self .check_ci_mode (args , use_resources )
487517
488518 def test_fast_ci_verbose (self ):
489519 args = ['--fast-ci' , '--verbose' ]
490- use_resources = sorted (cmdline .ALL_RESOURCES )
491- use_resources . remove ( 'cpu' )
520+ use_resources = dict . fromkeys (cmdline .ALL_RESOURCES )
521+ del use_resources [ 'cpu' ]
492522 regrtest = self .check_ci_mode (args , use_resources ,
493523 output_on_failure = False )
494524 self .assertEqual (regrtest .verbose , True )
495525
496526 def test_slow_ci (self ):
497527 args = ['--slow-ci' ]
498- use_resources = sorted (cmdline .ALL_RESOURCES )
528+ use_resources = dict . fromkeys (cmdline .ALL_RESOURCES )
499529 regrtest = self .check_ci_mode (args , use_resources )
500530 self .assertEqual (regrtest .timeout , 20 * 60 )
501531
502532 def test_ci_no_randomize (self ):
503- all_resources = set (cmdline .ALL_RESOURCES )
533+ use_resources = dict . fromkeys (cmdline .ALL_RESOURCES )
504534 self .check_ci_mode (
505- ["--slow-ci" , "--no-randomize" ], all_resources , randomize = False
535+ ["--slow-ci" , "--no-randomize" ], use_resources , randomize = False
506536 )
537+ del use_resources ['cpu' ]
507538 self .check_ci_mode (
508- ["--fast-ci" , "--no-randomize" ], all_resources - { 'cpu' } , randomize = False
539+ ["--fast-ci" , "--no-randomize" ], use_resources , randomize = False
509540 )
510541
511542 def test_dont_add_python_opts (self ):
@@ -2435,20 +2466,20 @@ def test_format_resources(self):
24352466 format_resources = utils .format_resources
24362467 ALL_RESOURCES = utils .ALL_RESOURCES
24372468 self .assertEqual (
2438- format_resources (( "network" ,) ),
2469+ format_resources ({ "network" : None } ),
24392470 'resources (1): network' )
24402471 self .assertEqual (
2441- format_resources (( "audio" , "decimal" , "network" )),
2472+ format_resources (dict . fromkeys (( "audio" , "decimal" , "network" ) )),
24422473 'resources (3): audio,decimal,network' )
24432474 self .assertEqual (
2444- format_resources (ALL_RESOURCES ),
2475+ format_resources (dict . fromkeys ( ALL_RESOURCES ) ),
24452476 'resources: all' )
24462477 self .assertEqual (
2447- format_resources (tuple ( name for name in ALL_RESOURCES
2448- if name != "cpu" ) ),
2478+ format_resources ({ name : None for name in ALL_RESOURCES
2479+ if name != "cpu" } ),
24492480 'resources: all,-cpu' )
24502481 self .assertEqual (
2451- format_resources (( * ALL_RESOURCES , "tzdata" ) ),
2482+ format_resources ({ ** dict . fromkeys ( ALL_RESOURCES ) , "tzdata" : None } ),
24522483 'resources: all,tzdata' )
24532484
24542485 def test_match_test (self ):
0 commit comments