@@ -656,6 +656,36 @@ def test_edit_file(base_app, request, monkeypatch):
656656 # We think we have an editor, so should expect a Popen call
657657 m .assert_called_once ()
658658
659+ def test_edit_file_with_odd_file_names (base_app , monkeypatch ):
660+ """Test editor and file names with various patterns"""
661+ # Mock out the do_shell call to see what args are passed
662+ shell_mock = mock .MagicMock (name = 'do_shell' )
663+ monkeypatch .setattr ("cmd2.Cmd.do_shell" , shell_mock )
664+
665+ base_app .editor = 'fooedit'
666+ python_script = utils .quote_string ('nothingweird.py' )
667+ out , err = run_cmd (base_app , "edit {}" .format (python_script ))
668+ shell_mock .assert_called_once_with ('"fooedit" "nothingweird.py"' )
669+ shell_mock .reset_mock ()
670+
671+ 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 ))
674+ shell_mock .assert_called_once_with ('"foo edit" "has spaces.py"' )
675+ shell_mock .reset_mock ()
676+
677+ 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 ))
680+ shell_mock .assert_called_once_with ('\' "fooedit"\' \' "is_double_quoted.py"\' ' )
681+ shell_mock .reset_mock ()
682+
683+ 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 ))
686+ shell_mock .assert_called_once_with ('"\' fooedit\' " "\' is_single_quoted.py\' "' )
687+ shell_mock .reset_mock ()
688+
659689def test_edit_file_with_spaces (base_app , request , monkeypatch ):
660690 # Set a fake editor just to make sure we have one. We aren't really going to call it due to the mock
661691 base_app .editor = 'fooedit'
@@ -986,7 +1016,7 @@ def do_study(self, arg):
9861016 def do_procrastinate (self , arg ):
9871017 """Waste time in your manner of choice."""
9881018 # Pass in a list of tuples for selections
989- leisure_activity = self .select ([('Netflix and chill' , 'Netflix' ), ('Porn ' , 'WebSurfing' )],
1019+ leisure_activity = self .select ([('Netflix and chill' , 'Netflix' ), ('YouTube ' , 'WebSurfing' )],
9901020 'How would you like to procrastinate? ' )
9911021 result = 'Have fun procrasinating with {}!\n ' .format (leisure_activity )
9921022 self .stdout .write (result )
@@ -1098,7 +1128,7 @@ def test_select_list_of_tuples(select_app):
10981128 1. Netflix
10991129 2. WebSurfing
11001130Have fun procrasinating with {}!
1101- """ .format ('Porn ' ))
1131+ """ .format ('YouTube ' ))
11021132
11031133 # Make sure our mock was called with the expected arguments
11041134 m .assert_called_once_with ('How would you like to procrastinate? ' )
0 commit comments