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

Function test_histmanager_memory_fallback_reopens_db

tests/test_history.py:287–321  ·  view source on GitHub ↗
(hmmax3, tmp_path, caplog)

Source from the content-addressed store, hash-verified

285
286
287def test_histmanager_memory_fallback_reopens_db(hmmax3, tmp_path, caplog):
288 hist_file = tmp_path / "history.sqlite"
289 ip = get_ipython()
290 hm1 = None
291 hm2 = None
292 lock = None
293 try:
294 hm1 = HistoryManager(shell=ip, hist_file=hist_file)
295 hm1.end_session()
296 hm1.save_thread.stop()
297 hm1.db.close()
298
299 lock = sqlite3.connect(hist_file)
300 lock.execute("BEGIN IMMEDIATE")
301
302 hm2 = HistoryManager(shell=ip, hist_file=hist_file)
303 assert hm2.hist_file == ":memory:"
304 assert hm2.db.execute("PRAGMA database_list").fetchall() == [(0, "main", "")]
305
306 hm2.store_inputs(1, "a = 1")
307 hm2.writeout_cache()
308 assert list(hm2.get_tail(1, include_latest=True)) == [
309 (hm2.session_number, 1, "a = 1")
310 ]
311 finally:
312 if hm2 is not None:
313 hm2.end_session()
314 hm2.db.close()
315 if lock is not None:
316 lock.rollback()
317 lock.close()
318 hm1 = None
319 hm2 = None
320 caplog.clear()
321 gc.collect()
322
323
324def test_histmanager_thread_start_failure_uses_memory(

Callers

nothing calls this directly

Calls 11

end_sessionMethod · 0.95
store_inputsMethod · 0.95
writeout_cacheMethod · 0.95
get_tailMethod · 0.95
HistoryManagerClass · 0.90
stopMethod · 0.80
connectMethod · 0.80
executeMethod · 0.80
get_ipythonFunction · 0.70
closeMethod · 0.45
collectMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…