##// END OF EJS Templates
test %edit magic on interactively defined objects
MinRK -
Show More
@@ -28,7 +28,7 b' from IPython.core.magic import (Magics, magics_class, line_magic,'
28 cell_magic, line_cell_magic,
28 cell_magic, line_cell_magic,
29 register_line_magic, register_cell_magic,
29 register_line_magic, register_cell_magic,
30 register_line_cell_magic)
30 register_line_cell_magic)
31 from IPython.core.magics import execution, script
31 from IPython.core.magics import execution, script, code
32 from IPython.nbformat.v3.tests.nbexamples import nb0
32 from IPython.nbformat.v3.tests.nbexamples import nb0
33 from IPython.nbformat import current
33 from IPython.nbformat import current
34 from IPython.testing import decorators as dec
34 from IPython.testing import decorators as dec
@@ -792,3 +792,49 b' def test_store():'
792 ip.user_ns['var'] = 39
792 ip.user_ns['var'] = 39
793 ip.run_line_magic('store' , '-r')
793 ip.run_line_magic('store' , '-r')
794 nt.assert_equal(ip.user_ns['var'], 39)
794 nt.assert_equal(ip.user_ns['var'], 39)
795
796
797 def _run_edit_test(arg_s, exp_filename=None,
798 exp_lineno=-1,
799 exp_contents=None,
800 exp_is_temp=None):
801 ip = get_ipython()
802 M = code.CodeMagics(ip)
803 last_call = ['','']
804 opts,args = M.parse_options(arg_s,'prxn:')
805 filename, lineno, is_temp = M._find_edit_target(ip, args, opts, last_call)
806
807 if exp_filename is not None:
808 nt.assert_equal(exp_filename, filename)
809 if exp_contents is not None:
810 with io.open(filename, 'r') as f:
811 contents = f.read()
812 nt.assert_equal(exp_contents, contents)
813 if exp_lineno != -1:
814 nt.assert_equal(exp_lineno, lineno)
815 if exp_is_temp is not None:
816 nt.assert_equal(exp_is_temp, is_temp)
817
818
819 def test_edit_interactive():
820 """%edit on interactively defined objects"""
821 ip = get_ipython()
822 n = ip.execution_count
823 ip.run_cell(u"def foo(): return 1", store_history=True)
824
825 try:
826 _run_edit_test("foo")
827 except code.InteractivelyDefined as e:
828 nt.assert_equal(e.index, n)
829 else:
830 nt.fail("Should have raised InteractivelyDefined")
831
832
833 def test_edit_cell():
834 """%edit [cell id]"""
835 ip = get_ipython()
836
837 ip.run_cell(u"def foo(): return 1", store_history=True)
838
839 # test
840 _run_edit_test("1", exp_contents=ip.user_ns['In'][1], exp_is_temp=True)
General Comments 0
You need to be logged in to leave comments. Login now