@@ -656,6 +656,36 @@ def test_edit_file(base_app, request, monkeypatch):
656
656
# We think we have an editor, so should expect a Popen call
657
657
m .assert_called_once ()
658
658
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
+
659
689
def test_edit_file_with_spaces (base_app , request , monkeypatch ):
660
690
# Set a fake editor just to make sure we have one. We aren't really going to call it due to the mock
661
691
base_app .editor = 'fooedit'
@@ -986,7 +1016,7 @@ def do_study(self, arg):
986
1016
def do_procrastinate (self , arg ):
987
1017
"""Waste time in your manner of choice."""
988
1018
# 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' )],
990
1020
'How would you like to procrastinate? ' )
991
1021
result = 'Have fun procrasinating with {}!\n ' .format (leisure_activity )
992
1022
self .stdout .write (result )
@@ -1098,7 +1128,7 @@ def test_select_list_of_tuples(select_app):
1098
1128
1. Netflix
1099
1129
2. WebSurfing
1100
1130
Have fun procrasinating with {}!
1101
- """ .format ('Porn ' ))
1131
+ """ .format ('YouTube ' ))
1102
1132
1103
1133
# Make sure our mock was called with the expected arguments
1104
1134
m .assert_called_once_with ('How would you like to procrastinate? ' )
0 commit comments