Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd2.py
Original file line number Diff line number Diff line change
Expand Up @@ -1633,7 +1633,7 @@ def do_edit(self, arg):
f.write(history_item or '')
f.close()

os.system('%s %s' % (self.editor, filename))
os.system('"{}" "{}"'.format(self.editor, filename))

if self.autorun_on_edit or history_item:
self.do_load(filename)
Expand Down
5 changes: 3 additions & 2 deletions examples/transcript_regex.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
# Run this transcript with "python example.py -t transcript_regex.txt"
# The regex for editor matches any word until first space. The one for colors is because no color on Windows.
# The regex for colors is because no color on Windows.
# The regex for editor will match whatever program you use.
(Cmd) set
abbrev: True
autorun_on_edit: False
colors: /(True|False)/
continuation_prompt: >
debug: False
echo: False
editor: /([^\s]+)/
editor: /.*/
feedback_to_output: True
locals_in_py: True
maxrepeats: 3
Expand Down
18 changes: 17 additions & 1 deletion tests/test_cmd2.py
Original file line number Diff line number Diff line change
Expand Up @@ -736,7 +736,23 @@ def test_edit_file(base_app, request, monkeypatch):
run_cmd(base_app, 'edit {}'.format(filename))

# We think we have an editor, so should expect a system call
m.assert_called_once_with('{} {}'.format(base_app.editor, filename))
m.assert_called_once_with('"{}" "{}"'.format(base_app.editor, filename))

def test_edit_file_with_spaces(base_app, request, monkeypatch):
# Set a fake editor just to make sure we have one. We aren't really going to call it due to the mock
base_app.editor = 'fooedit'

# Mock out the os.system call so we don't actually open an editor
m = mock.MagicMock(name='system')
monkeypatch.setattr("os.system", m)

test_dir = os.path.dirname(request.module.__file__)
filename = os.path.join(test_dir, 'my commands.txt')

run_cmd(base_app, 'edit {}'.format(filename))

# We think we have an editor, so should expect a system call
m.assert_called_once_with('"{}" "{}"'.format(base_app.editor, filename))

def test_edit_number(base_app, monkeypatch):
# Set a fake editor just to make sure we have one. We aren't really going to call it due to the mock
Expand Down
5 changes: 3 additions & 2 deletions tests/transcript_regex.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
# Run this transcript with "python example.py -t transcript_regex.txt"
# The regex for editor matches any word until first space. The one for colors is because no color on Windows.
# The regex for colors is because no color on Windows.
# The regex for editor will match whatever program you use.
(Cmd) set
abbrev: True
autorun_on_edit: False
colors: /(True|False)/
continuation_prompt: >
debug: False
echo: False
editor: /([^\s]+)/
editor: /.*/
feedback_to_output: True
locals_in_py: True
maxrepeats: 3
Expand Down