diff --git a/IPython/lib/editorhooks.py b/IPython/lib/editorhooks.py index 173ba92..b76a89b 100644 --- a/IPython/lib/editorhooks.py +++ b/IPython/lib/editorhooks.py @@ -10,13 +10,14 @@ import os import pipes import shlex import subprocess +import sys from IPython import get_ipython from IPython.core.error import TryNext from IPython.utils import py3compat -def install_editor(template_list, wait=False): +def install_editor(template, wait=False): """Installs the editor that is called by IPython for the %edit magic. This overrides the default editor, which is generally set by your EDITOR diff --git a/IPython/lib/tests/test_editorhooks.py b/IPython/lib/tests/test_editorhooks.py new file mode 100644 index 0000000..56085cf --- /dev/null +++ b/IPython/lib/tests/test_editorhooks.py @@ -0,0 +1,37 @@ +"""Test installing editor hooks""" +import sys + +try: + import mock +except ImportError: + from unittest import mock + +import nose.tools as nt + +from IPython import get_ipython +from IPython.lib import editorhooks + +def test_install_editor(): + called = [] + def fake_popen(*args, **kwargs): + called.append({ + 'args': args, + 'kwargs': kwargs, + }) + editorhooks.install_editor('foo -l {line} -f {filename}', wait=False) + + with mock.patch('subprocess.Popen', fake_popen): + get_ipython().hooks.editor('the file', 64) + + nt.assert_equal(len(called), 1) + args = called[0]['args'] + kwargs = called[0]['kwargs'] + + nt.assert_equal(kwargs, {'shell': True}) + + if sys.platform.startswith('win'): + expected = ['foo', '-l', '64', '-f', 'the file'] + else: + expected = "foo -l 64 -f 'the file'" + cmd = args[0] + nt.assert_equal(cmd, expected)