test_editorhooks.py 929 B

12345678910111213141516171819202122232425262728293031323334353637
  1. """Test installing editor hooks"""
  2. import sys
  3. try:
  4. import mock
  5. except ImportError:
  6. from unittest import mock
  7. import nose.tools as nt
  8. from IPython import get_ipython
  9. from IPython.lib import editorhooks
  10. def test_install_editor():
  11. called = []
  12. def fake_popen(*args, **kwargs):
  13. called.append({
  14. 'args': args,
  15. 'kwargs': kwargs,
  16. })
  17. editorhooks.install_editor('foo -l {line} -f {filename}', wait=False)
  18. with mock.patch('subprocess.Popen', fake_popen):
  19. get_ipython().hooks.editor('the file', 64)
  20. nt.assert_equal(len(called), 1)
  21. args = called[0]['args']
  22. kwargs = called[0]['kwargs']
  23. nt.assert_equal(kwargs, {'shell': True})
  24. if sys.platform.startswith('win'):
  25. expected = ['foo', '-l', '64', '-f', 'the file']
  26. else:
  27. expected = "foo -l 64 -f 'the file'"
  28. cmd = args[0]
  29. nt.assert_equal(cmd, expected)