@@ -427,6 +427,33 @@ def test_relative_run_script(base_app, request):
427
427
assert script_out == manual_out
428
428
assert script_err == manual_err
429
429
430
+ def test_relative_run_script_with_odd_file_names (base_app , monkeypatch ):
431
+ """Test file names with various patterns"""
432
+ # Mock out the do_run_script call to see what args are passed
433
+ run_script_mock = mock .MagicMock (name = 'do_run_script' )
434
+ monkeypatch .setattr ("cmd2.Cmd.do_run_script" , run_script_mock )
435
+
436
+ file_name = utils .quote_string ('nothingweird.txt' )
437
+ out , err = run_cmd (base_app , "run_script {}" .format (file_name ))
438
+ run_script_mock .assert_called_once_with ('"nothingweird.txt"' )
439
+ run_script_mock .reset_mock ()
440
+
441
+ file_name = utils .quote_string ('has spaces.txt' )
442
+ out , err = run_cmd (base_app , "run_script {}" .format (file_name ))
443
+ run_script_mock .assert_called_once_with ('"has spaces.txt"' )
444
+ run_script_mock .reset_mock ()
445
+
446
+ file_name = utils .quote_string ('"is_double_quoted.txt"' )
447
+ out , err = run_cmd (base_app , "run_script {}" .format (file_name ))
448
+ run_script_mock .assert_called_once_with ('\' "is_double_quoted.txt"\' ' )
449
+ run_script_mock .reset_mock ()
450
+
451
+ file_name = utils .quote_string ("'is_single_quoted.txt'" )
452
+ out , err = run_cmd (base_app , "run_script {}" .format (file_name ))
453
+ run_script_mock .assert_called_once_with ('"\' is_single_quoted.txt\' "' )
454
+ run_script_mock .reset_mock ()
455
+
456
+
430
457
def test_relative_run_script_requires_an_argument (base_app ):
431
458
out , err = run_cmd (base_app , '_relative_run_script' )
432
459
assert 'Error: the following arguments' in err [1 ]
@@ -663,26 +690,26 @@ def test_edit_file_with_odd_file_names(base_app, monkeypatch):
663
690
monkeypatch .setattr ("cmd2.Cmd.do_shell" , shell_mock )
664
691
665
692
base_app .editor = 'fooedit'
666
- python_script = utils .quote_string ('nothingweird.py' )
667
- out , err = run_cmd (base_app , "edit {}" .format (python_script ))
693
+ file_name = utils .quote_string ('nothingweird.py' )
694
+ out , err = run_cmd (base_app , "edit {}" .format (file_name ))
668
695
shell_mock .assert_called_once_with ('"fooedit" "nothingweird.py"' )
669
696
shell_mock .reset_mock ()
670
697
671
698
base_app .editor = 'foo edit'
672
- python_script = utils .quote_string ('has spaces.py' )
673
- out , err = run_cmd (base_app , "edit {}" .format (python_script ))
699
+ file_name = utils .quote_string ('has spaces.py' )
700
+ out , err = run_cmd (base_app , "edit {}" .format (file_name ))
674
701
shell_mock .assert_called_once_with ('"foo edit" "has spaces.py"' )
675
702
shell_mock .reset_mock ()
676
703
677
704
base_app .editor = '"fooedit"'
678
- python_script = utils .quote_string ('"is_double_quoted.py"' )
679
- out , err = run_cmd (base_app , "edit {}" .format (python_script ))
705
+ file_name = utils .quote_string ('"is_double_quoted.py"' )
706
+ out , err = run_cmd (base_app , "edit {}" .format (file_name ))
680
707
shell_mock .assert_called_once_with ('\' "fooedit"\' \' "is_double_quoted.py"\' ' )
681
708
shell_mock .reset_mock ()
682
709
683
710
base_app .editor = "'fooedit'"
684
- python_script = utils .quote_string ("'is_single_quoted.py'" )
685
- out , err = run_cmd (base_app , "edit {}" .format (python_script ))
711
+ file_name = utils .quote_string ("'is_single_quoted.py'" )
712
+ out , err = run_cmd (base_app , "edit {}" .format (file_name ))
686
713
shell_mock .assert_called_once_with ('"\' fooedit\' " "\' is_single_quoted.py\' "' )
687
714
shell_mock .reset_mock ()
688
715
0 commit comments