@@ -276,26 +276,56 @@ def test_use(self):
276276 for opt in '-u' , '--use' :
277277 with self .subTest (opt = opt ):
278278 ns = self .parse_args ([opt , 'gui,network' ])
279- self .assertEqual (ns .use_resources , ['gui' , 'network' ])
279+ self .assertEqual (ns .use_resources , {'gui' : None , 'network' : None })
280+ ns = self .parse_args ([opt , 'gui' , opt , 'network' ])
281+ self .assertEqual (ns .use_resources , {'gui' : None , 'network' : None })
280282
281283 ns = self .parse_args ([opt , 'gui,none,network' ])
282- self .assertEqual (ns .use_resources , ['network' ])
284+ self .assertEqual (ns .use_resources , {'network' : None })
285+ ns = self .parse_args ([opt , 'gui' , opt , 'none' , opt , 'network' ])
286+ self .assertEqual (ns .use_resources , {'network' : None })
283287
284- expected = list (cmdline .ALL_RESOURCES )
285- expected . remove ( 'gui' )
288+ expected = dict . fromkeys (cmdline .ALL_RESOURCES )
289+ del expected [ 'gui' ]
286290 ns = self .parse_args ([opt , 'all,-gui' ])
287291 self .assertEqual (ns .use_resources , expected )
292+
288293 self .checkError ([opt ], 'expected one argument' )
289294 self .checkError ([opt , 'foo' ], 'invalid resource' )
290295
291296 # all + a resource not part of "all"
297+ expected = dict .fromkeys (cmdline .ALL_RESOURCES )
298+ expected ['tzdata' ] = None
292299 ns = self .parse_args ([opt , 'all,tzdata' ])
293- self .assertEqual (ns .use_resources ,
294- list (cmdline .ALL_RESOURCES ) + ['tzdata' ])
300+ self .assertEqual (ns .use_resources , expected )
301+ ns = self .parse_args ([opt , 'all' , opt , 'tzdata' ])
302+ self .assertEqual (ns .use_resources , expected )
295303
296304 # test another resource which is not part of "all"
297305 ns = self .parse_args ([opt , 'extralargefile' ])
298- self .assertEqual (ns .use_resources , ['extralargefile' ])
306+ self .assertEqual (ns .use_resources , {'extralargefile' : None })
307+
308+ # test resource with value
309+ ns = self .parse_args ([opt , 'xpickle=2.7' ])
310+ self .assertEqual (ns .use_resources , {'xpickle' : '2.7' })
311+ ns = self .parse_args ([opt , 'xpickle=2.7,xpickle=3.3' ])
312+ self .assertEqual (ns .use_resources , {'xpickle' : '3.3' })
313+ ns = self .parse_args ([opt , 'xpickle=2.7,none' ])
314+ self .assertEqual (ns .use_resources , {})
315+ ns = self .parse_args ([opt , 'xpickle=2.7,-xpickle' ])
316+ self .assertEqual (ns .use_resources , {})
317+
318+ expected = dict .fromkeys (cmdline .ALL_RESOURCES )
319+ expected ['xpickle' ] = '2.7'
320+ ns = self .parse_args ([opt , 'all,xpickle=2.7' ])
321+ self .assertEqual (ns .use_resources , expected )
322+ ns = self .parse_args ([opt , 'all' , opt , 'xpickle=2.7' ])
323+ self .assertEqual (ns .use_resources , expected )
324+
325+ # test invalid resources with value
326+ self .checkError ([opt , 'all=0' ], 'invalid resource: all=0' )
327+ self .checkError ([opt , 'none=0' ], 'invalid resource: none=0' )
328+ self .checkError ([opt , 'all,-gui=0' ], 'invalid resource: -gui=0' )
299329
300330 def test_memlimit (self ):
301331 for opt in '-M' , '--memlimit' :
@@ -456,53 +486,54 @@ def check_ci_mode(self, args, use_resources,
456486 self .assertTrue (regrtest .fail_env_changed )
457487 self .assertTrue (regrtest .print_slowest )
458488 self .assertEqual (regrtest .output_on_failure , output_on_failure )
459- self .assertEqual (sorted ( regrtest .use_resources ), sorted ( use_resources ) )
489+ self .assertEqual (regrtest .use_resources , use_resources )
460490 return regrtest
461491
462492 def test_fast_ci (self ):
463493 args = ['--fast-ci' ]
464- use_resources = sorted (cmdline .ALL_RESOURCES )
465- use_resources . remove ( 'cpu' )
494+ use_resources = dict . fromkeys (cmdline .ALL_RESOURCES )
495+ del use_resources [ 'cpu' ]
466496 regrtest = self .check_ci_mode (args , use_resources )
467497 self .assertEqual (regrtest .timeout , 10 * 60 )
468498
469499 def test_fast_ci_python_cmd (self ):
470500 args = ['--fast-ci' , '--python' , 'python -X dev' ]
471- use_resources = sorted (cmdline .ALL_RESOURCES )
472- use_resources . remove ( 'cpu' )
501+ use_resources = dict . fromkeys (cmdline .ALL_RESOURCES )
502+ del use_resources [ 'cpu' ]
473503 regrtest = self .check_ci_mode (args , use_resources , rerun = False )
474504 self .assertEqual (regrtest .timeout , 10 * 60 )
475505 self .assertEqual (regrtest .python_cmd , ('python' , '-X' , 'dev' ))
476506
477507 def test_fast_ci_resource (self ):
478508 # it should be possible to override resources individually
479509 args = ['--fast-ci' , '-u-network' ]
480- use_resources = sorted (cmdline .ALL_RESOURCES )
481- use_resources . remove ( 'cpu' )
482- use_resources . remove ( 'network' )
510+ use_resources = dict . fromkeys (cmdline .ALL_RESOURCES )
511+ del use_resources [ 'cpu' ]
512+ del use_resources [ 'network' ]
483513 self .check_ci_mode (args , use_resources )
484514
485515 def test_fast_ci_verbose (self ):
486516 args = ['--fast-ci' , '--verbose' ]
487- use_resources = sorted (cmdline .ALL_RESOURCES )
488- use_resources . remove ( 'cpu' )
517+ use_resources = dict . fromkeys (cmdline .ALL_RESOURCES )
518+ del use_resources [ 'cpu' ]
489519 regrtest = self .check_ci_mode (args , use_resources ,
490520 output_on_failure = False )
491521 self .assertEqual (regrtest .verbose , True )
492522
493523 def test_slow_ci (self ):
494524 args = ['--slow-ci' ]
495- use_resources = sorted (cmdline .ALL_RESOURCES )
525+ use_resources = dict . fromkeys (cmdline .ALL_RESOURCES )
496526 regrtest = self .check_ci_mode (args , use_resources )
497527 self .assertEqual (regrtest .timeout , 20 * 60 )
498528
499529 def test_ci_no_randomize (self ):
500- all_resources = set (cmdline .ALL_RESOURCES )
530+ use_resources = dict . fromkeys (cmdline .ALL_RESOURCES )
501531 self .check_ci_mode (
502- ["--slow-ci" , "--no-randomize" ], all_resources , randomize = False
532+ ["--slow-ci" , "--no-randomize" ], use_resources , randomize = False
503533 )
534+ del use_resources ['cpu' ]
504535 self .check_ci_mode (
505- ["--fast-ci" , "--no-randomize" ], all_resources - { 'cpu' } , randomize = False
536+ ["--fast-ci" , "--no-randomize" ], use_resources , randomize = False
506537 )
507538
508539 def test_dont_add_python_opts (self ):
@@ -2445,20 +2476,20 @@ def test_format_resources(self):
24452476 format_resources = utils .format_resources
24462477 ALL_RESOURCES = utils .ALL_RESOURCES
24472478 self .assertEqual (
2448- format_resources (( "network" ,) ),
2479+ format_resources ({ "network" : None } ),
24492480 'resources (1): network' )
24502481 self .assertEqual (
2451- format_resources (( "audio" , "decimal" , "network" )),
2482+ format_resources (dict . fromkeys (( "audio" , "decimal" , "network" ) )),
24522483 'resources (3): audio,decimal,network' )
24532484 self .assertEqual (
2454- format_resources (ALL_RESOURCES ),
2485+ format_resources (dict . fromkeys ( ALL_RESOURCES ) ),
24552486 'resources: all' )
24562487 self .assertEqual (
2457- format_resources (tuple ( name for name in ALL_RESOURCES
2458- if name != "cpu" ) ),
2488+ format_resources ({ name : None for name in ALL_RESOURCES
2489+ if name != "cpu" } ),
24592490 'resources: all,-cpu' )
24602491 self .assertEqual (
2461- format_resources (( * ALL_RESOURCES , "tzdata" ) ),
2492+ format_resources ({ ** dict . fromkeys ( ALL_RESOURCES ) , "tzdata" : None } ),
24622493 'resources: all,tzdata' )
24632494
24642495 def test_match_test (self ):
0 commit comments