summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTodd Leonhardt <todd.leonhardt@gmail.com>2017-08-20 05:40:00 -0700
committerGitHub <noreply@github.com>2017-08-20 05:40:00 -0700
commit499fdd614f782de085054e2e50d926a0f0adb71f (patch)
tree9421eb4793bd062ca2f13c5586433b5803123805
parentf49d88a5bc5d981c78c2242a53ac34f8576b89ee (diff)
parentdc0ad81e6858aa9387c7dbd88f5721b6762f51b1 (diff)
downloadcmd2-git-499fdd614f782de085054e2e50d926a0f0adb71f.tar.gz
Merge pull request #212 from kotfu/fix/test_regex_transcript
Ensure editor and the file to edit can have spaces in them
-rwxr-xr-xcmd2.py2
-rw-r--r--examples/transcript_regex.txt5
-rw-r--r--tests/test_cmd2.py18
-rw-r--r--tests/transcript_regex.txt5
4 files changed, 24 insertions, 6 deletions
diff --git a/cmd2.py b/cmd2.py
index b885fa28..67f6c9bb 100755
--- a/cmd2.py
+++ b/cmd2.py
@@ -1633,7 +1633,7 @@ Edited files are run on close if the ``autorun_on_edit`` settable parameter is T
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)
diff --git a/examples/transcript_regex.txt b/examples/transcript_regex.txt
index 47357284..31e731a9 100644
--- a/examples/transcript_regex.txt
+++ b/examples/transcript_regex.txt
@@ -1,5 +1,6 @@
# 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
@@ -7,7 +8,7 @@ colors: /(True|False)/
continuation_prompt: >
debug: False
echo: False
-editor: /([^\s]+)/
+editor: /.*/
feedback_to_output: True
locals_in_py: True
maxrepeats: 3
diff --git a/tests/test_cmd2.py b/tests/test_cmd2.py
index 67dfacf4..9a88f45b 100644
--- a/tests/test_cmd2.py
+++ b/tests/test_cmd2.py
@@ -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
diff --git a/tests/transcript_regex.txt b/tests/transcript_regex.txt
index 47357284..c17638f4 100644
--- a/tests/transcript_regex.txt
+++ b/tests/transcript_regex.txt
@@ -1,5 +1,6 @@
# 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
@@ -7,7 +8,7 @@ colors: /(True|False)/
continuation_prompt: >
debug: False
echo: False
-editor: /([^\s]+)/
+editor: /.*/
feedback_to_output: True
locals_in_py: True
maxrepeats: 3