Permalink
Browse files

Add test code for history session offset.

  • Loading branch information...
1 parent 79c72b7 commit 5b4858664c186462ae18f182c0b53741ec0a7cfb @takluyver committed Feb 9, 2011
Showing with 19 additions and 2 deletions.
  1. +19 −2 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

0 comments on commit 5b48586

Please sign in to comment.