26
26
import cylc .flow .flags
27
27
from cylc .flow .option_parsers import (
28
28
CylcOptionParser as COP , Options , combine_options , combine_options_pair ,
29
- OptionSettings , cleanup_sysargv
29
+ OptionSettings , cleanup_sysargv , filter_sysargv
30
30
)
31
31
32
32
@@ -321,20 +321,6 @@ def test_combine_options(inputs, expect):
321
321
@pytest .mark .parametrize (
322
322
'argv_before, kwargs, expect' ,
323
323
[
324
- param (
325
- 'vip myworkflow --foo something' .split (),
326
- {
327
- 'script_name' : 'play' ,
328
- 'workflow_id' : 'myworkflow' ,
329
- 'compound_script_opts' : [
330
- OptionSettings (['--foo' , '-f' ]),
331
- ],
332
- 'script_opts' : [
333
- OptionSettings (['--foo' , '-f' ])]
334
- },
335
- 'play myworkflow --foo something' .split (),
336
- id = 'no opts to remove'
337
- ),
338
324
param (
339
325
'vip myworkflow -f something -b something_else --baz' .split (),
340
326
{
@@ -397,35 +383,6 @@ def test_combine_options(inputs, expect):
397
383
'play --foo something myworkflow' .split (),
398
384
id = 'no path given'
399
385
),
400
- param (
401
- 'vip --bar=something' .split (),
402
- {
403
- 'script_name' : 'play' ,
404
- 'workflow_id' : 'myworkflow' ,
405
- 'compound_script_opts' : [
406
- OptionSettings (['--bar' , '-b' ])],
407
- 'script_opts' : [],
408
- 'source' : './myworkflow' ,
409
- },
410
- 'play myworkflow' .split (),
411
- id = 'removes --key=value'
412
- ),
413
- param (
414
- # Test for https://github.com/cylc/cylc-flow/issues/5905
415
- 'vip ./myworkflow --no-run-name --workflow-name=hi' .split (),
416
- {
417
- 'script_name' : 'play' ,
418
- 'workflow_id' : 'myworkflow' ,
419
- 'compound_script_opts' : [
420
- OptionSettings (['--no-run-name' ], action = 'store_true' ),
421
- OptionSettings (['--workflow-name' ], action = 'store' )
422
- ],
423
- 'script_opts' : [],
424
- 'source' : './myworkflow' ,
425
- },
426
- 'play myworkflow' .split (),
427
- id = 'equals-bug'
428
- ),
429
386
]
430
387
)
431
388
def test_cleanup_sysargv (monkeypatch , argv_before , kwargs , expect ):
@@ -448,6 +405,53 @@ def test_cleanup_sysargv(monkeypatch, argv_before, kwargs, expect):
448
405
assert sys .argv == dummy_cylc_path + expect
449
406
450
407
408
+ @pytest .mark .parametrize (
409
+ 'sysargs, simple, compound, expect' , (
410
+ param (
411
+ # Test for https://github.com/cylc/cylc-flow/issues/5905
412
+ '--no-run-name --workflow-name=name' .split (),
413
+ ['--no-run-name' ],
414
+ ['--workflow-name' ],
415
+ [],
416
+ id = '--workflow-name=name'
417
+ ),
418
+ param (
419
+ '--foo something' .split (),
420
+ [], [], '--foo something' .split (),
421
+ id = 'no-opts-removed'
422
+ ),
423
+ param (
424
+ [], ['--foo' ], ['--bar' ], [],
425
+ id = 'Null-check'
426
+ ),
427
+ param (
428
+ '''--keep1 --keep2 42 --keep3=Hi
429
+ --throw1 --throw2 84 --throw3=There
430
+ ''' .split (),
431
+ ['--throw1' ],
432
+ '--throw2 --throw3' .split (),
433
+ '--keep1 --keep2 42 --keep3=Hi' .split (),
434
+ id = 'complex'
435
+ ),
436
+ param (
437
+ "--foo 'foo=42' --bar='foo=94'" .split (),
438
+ [], ['--foo' ],
439
+ ['--bar=\' foo=94\' ' ],
440
+ id = '--bar=\' foo=94\' '
441
+ )
442
+ )
443
+ )
444
+ def test_filter_sysargv (
445
+ sysargs , simple , compound , expect
446
+ ):
447
+ """It returns the subset of sys.argv that we ask for.
448
+
449
+ n.b. The three most basic cases for this function are stored in
450
+ its own docstring.
451
+ """
452
+ assert filter_sysargv (sysargs , simple , compound ) == expect
453
+
454
+
451
455
class TestOptionSettings ():
452
456
@staticmethod
453
457
def test_init ():
0 commit comments