MCPcopy Index your code
hub / github.com/ipython/ipython / test_get_tail_session_awareness

Function test_get_tail_session_awareness

tests/test_history.py:378–453  ·  view source on GitHub ↗

Test .get_tail() is: - session specific in HistoryManager - session agnostic in HistoryAccessor same for .get_last_session_id()

(hmmax3)

Source from the content-addressed store, hash-verified

376
377
378def test_get_tail_session_awareness(hmmax3):
379 """Test .get_tail() is:
380 - session specific in HistoryManager
381 - session agnostic in HistoryAccessor
382 same for .get_last_session_id()
383 """
384 with TemporaryDirectory() as tmpdir:
385 ip = get_ipython()
386 tmp_path = Path(tmpdir)
387 hist_file = tmp_path / "history.sqlite"
388 get_source = lambda x: x[2]
389 hm1 = None
390 hm2 = None
391 ha = None
392 try:
393 # hm1 creates a new session and adds history entries,
394 # ha catches up
395 hm1 = HistoryManager(shell=ip, hist_file=hist_file)
396 hm1_last_sid = hm1.get_last_session_id
397 ha = HistoryAccessor(hist_file=hist_file)
398 ha_last_sid = ha.get_last_session_id
399
400 hist1 = ["a=1", "b=1", "c=1"]
401 for i, h in enumerate(hist1 + [""], start=1):
402 hm1.store_inputs(i, h)
403 assert list(map(get_source, hm1.get_tail())) == hist1
404 assert list(map(get_source, ha.get_tail())) == hist1
405 sid1 = hm1_last_sid()
406 assert sid1 is not None
407 assert ha_last_sid() == sid1
408
409 # hm2 creates a new session and adds entries,
410 # ha catches up
411 hm2 = HistoryManager(shell=ip, hist_file=hist_file)
412 hm2_last_sid = hm2.get_last_session_id
413
414 hist2 = ["a=2", "b=2", "c=2"]
415 for i, h in enumerate(hist2 + [""], start=1):
416 hm2.store_inputs(i, h)
417 tail = hm2.get_tail(n=3)
418 assert list(map(get_source, tail)) == hist2
419 tail = ha.get_tail(n=3)
420 assert list(map(get_source, tail)) == hist2
421 sid2 = hm2_last_sid()
422 assert sid2 is not None
423 assert ha_last_sid() == sid2
424 assert sid2 != sid1
425
426 # but hm1 still maintains its point of reference
427 # and adding more entries to it doesn't change others
428 # immediate perspective
429 assert hm1_last_sid() == sid1
430 tail = hm1.get_tail(n=3)
431 assert list(map(get_source, tail)) == hist1
432
433 hist3 = ["a=3", "b=3", "c=3"]
434 for i, h in enumerate(hist3 + [""], start=5):
435 hm1.store_inputs(i, h)

Callers

nothing calls this directly

Calls 8

store_inputsMethod · 0.95
get_tailMethod · 0.95
get_tailMethod · 0.95
HistoryManagerClass · 0.90
HistoryAccessorClass · 0.90
stopMethod · 0.80
get_ipythonFunction · 0.70
closeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…