Show More
@@ -0,0 +1,37 b'' | |||||
|
1 | """Test installing editor hooks""" | |||
|
2 | import sys | |||
|
3 | ||||
|
4 | try: | |||
|
5 | import mock | |||
|
6 | except ImportError: | |||
|
7 | from unittest import mock | |||
|
8 | ||||
|
9 | import nose.tools as nt | |||
|
10 | ||||
|
11 | from IPython import get_ipython | |||
|
12 | from IPython.lib import editorhooks | |||
|
13 | ||||
|
14 | def test_install_editor(): | |||
|
15 | called = [] | |||
|
16 | def fake_popen(*args, **kwargs): | |||
|
17 | called.append({ | |||
|
18 | 'args': args, | |||
|
19 | 'kwargs': kwargs, | |||
|
20 | }) | |||
|
21 | editorhooks.install_editor('foo -l {line} -f {filename}', wait=False) | |||
|
22 | ||||
|
23 | with mock.patch('subprocess.Popen', fake_popen): | |||
|
24 | get_ipython().hooks.editor('the file', 64) | |||
|
25 | ||||
|
26 | nt.assert_equal(len(called), 1) | |||
|
27 | args = called[0]['args'] | |||
|
28 | kwargs = called[0]['kwargs'] | |||
|
29 | ||||
|
30 | nt.assert_equal(kwargs, {'shell': True}) | |||
|
31 | ||||
|
32 | if sys.platform.startswith('win'): | |||
|
33 | expected = ['foo', '-l', '64', '-f', 'the file'] | |||
|
34 | else: | |||
|
35 | expected = "foo -l 64 -f 'the file'" | |||
|
36 | cmd = args[0] | |||
|
37 | nt.assert_equal(cmd, expected) |
@@ -10,13 +10,14 b' import os' | |||||
10 | import pipes |
|
10 | import pipes | |
11 | import shlex |
|
11 | import shlex | |
12 | import subprocess |
|
12 | import subprocess | |
|
13 | import sys | |||
13 |
|
14 | |||
14 | from IPython import get_ipython |
|
15 | from IPython import get_ipython | |
15 | from IPython.core.error import TryNext |
|
16 | from IPython.core.error import TryNext | |
16 | from IPython.utils import py3compat |
|
17 | from IPython.utils import py3compat | |
17 |
|
18 | |||
18 |
|
19 | |||
19 |
def install_editor(template |
|
20 | def install_editor(template, wait=False): | |
20 | """Installs the editor that is called by IPython for the %edit magic. |
|
21 | """Installs the editor that is called by IPython for the %edit magic. | |
21 |
|
22 | |||
22 | This overrides the default editor, which is generally set by your EDITOR |
|
23 | This overrides the default editor, which is generally set by your EDITOR |
General Comments 0
You need to be logged in to leave comments.
Login now