From 590395388e83224cc43dda42e3808fe86f2e3821 2011-03-13 12:51:48 From: Thomas Kluyver Date: 2011-03-13 12:51:48 Subject: [PATCH] Add test code for history session offset. --- diff --git a/IPython/core/tests/test_history.py b/IPython/core/tests/test_history.py index 838cba7..650549f 100644 --- a/IPython/core/tests/test_history.py +++ b/IPython/core/tests/test_history.py @@ -30,11 +30,11 @@ def test_history(): ip.history_manager = HistoryManager(ip) ip.history_manager.hist_file = histfile print 'test',histfile - hist = ['a=1\n', 'def f():\n test = 1\n return test\n', 'b=2\n'] + hist = ['a=1', 'def f():\n test = 1\n return test', 'b=2'] # test save and load ip.history_manager.input_hist_raw[:] = [] for h in hist: - ip.history_manager.input_hist_raw.append(h) + ip.history_manager.store_inputs(h) ip.save_history() ip.history_manager.input_hist_raw[:] = [] ip.reload_history() @@ -43,6 +43,23 @@ def test_history(): nt.assert_equal(len(ip.history_manager.input_hist_raw), len(hist)) for i,h in enumerate(hist): nt.assert_equal(hist[i], ip.history_manager.input_hist_raw[i]) + + # Test that session offset works. + ip.history_manager.session_offset = \ + len(ip.history_manager.input_hist_raw) -1 + newcmds = ["z=5","class X(object):\n pass", "k='p'"] + for cmd in newcmds: + ip.history_manager.store_inputs(cmd) + gothist = ip.history_manager.get_history((1,4), + raw=True, output=False) + nt.assert_equal(gothist, dict(zip([1,2,3], newcmds))) + + # Cross testing: check that magic %save picks up on the session + # offset. + testfilename = os.path.realpath(os.path.join(tmpdir, "test.py")) + ip.magic_save(testfilename + " 1-3") + testfile = open(testfilename, "r") + nt.assert_equal(testfile.read(), "\n".join(newcmds)) finally: # Restore history manager ip.history_manager = hist_manager_ori