From 30528a19e0e0dbee58e584577d632af1c559dbcd 2022-08-07 10:15:15 From: Aleksey Bogdanov Date: 2022-08-07 10:15:15 Subject: [PATCH] wrap db before host dir is gone in new test --- diff --git a/IPython/core/tests/test_history.py b/IPython/core/tests/test_history.py index 46c0ea8..be15297 100644 --- a/IPython/core/tests/test_history.py +++ b/IPython/core/tests/test_history.py @@ -240,56 +240,66 @@ def test_get_tail_session_awareness(): tmp_path = Path(tmpdir) hist_file = tmp_path / "history.sqlite" get_source = lambda x: x[2] - - # hm1 creates a new session and adds history entries, - # ha catches up - hm1 = HistoryManager(shell=ip, hist_file=hist_file) - hm1_last_sid = hm1.get_last_session_id - ha = HistoryAccessor(hist_file=hist_file) - ha_last_sid = ha.get_last_session_id - - hist1 = ["a=1", "b=1", "c=1"] - for i, h in enumerate(hist1 + [""], start=1): - hm1.store_inputs(i, h) - assert list(map(get_source, hm1.get_tail())) == hist1 - assert list(map(get_source, ha.get_tail())) == hist1 - sid1 = hm1_last_sid() - assert sid1 is not None - assert ha_last_sid() == sid1 - - # hm2 creates a new session and adds entries, - # ha catches up - hm2 = HistoryManager(shell=ip, hist_file=hist_file) - hm2_last_sid = hm2.get_last_session_id - - hist2 = ["a=2", "b=2", "c=2"] - for i, h in enumerate(hist2 + [""], start=1): - hm2.store_inputs(i, h) - tail = hm2.get_tail(n=3) - assert list(map(get_source, tail)) == hist2 - tail = ha.get_tail(n=3) - assert list(map(get_source, tail)) == hist2 - sid2 = hm2_last_sid() - assert sid2 is not None - assert ha_last_sid() == sid2 - assert sid2 != sid1 - - # but hm1 still maintains its point of reference - # and adding more entries to it doesn't change others - # immediate perspective - assert hm1_last_sid() == sid1 - tail = hm1.get_tail(n=3) - assert list(map(get_source, tail)) == hist1 - - hist3 = ["a=3", "b=3", "c=3"] - for i, h in enumerate(hist3 + [""], start=5): - hm1.store_inputs(i, h) - tail = hm1.get_tail(n=7) - assert list(map(get_source, tail)) == hist1 + [""] + hist3 - tail = hm2.get_tail(n=3) - assert list(map(get_source, tail)) == hist2 - tail = ha.get_tail(n=3) - assert list(map(get_source, tail)) == hist2 - assert hm1_last_sid() == sid1 - assert hm2_last_sid() == sid2 - assert ha_last_sid() == sid2 + hm1 = None + hm2 = None + try: + # hm1 creates a new session and adds history entries, + # ha catches up + hm1 = HistoryManager(shell=ip, hist_file=hist_file) + hm1_last_sid = hm1.get_last_session_id + ha = HistoryAccessor(hist_file=hist_file) + ha_last_sid = ha.get_last_session_id + + hist1 = ["a=1", "b=1", "c=1"] + for i, h in enumerate(hist1 + [""], start=1): + hm1.store_inputs(i, h) + assert list(map(get_source, hm1.get_tail())) == hist1 + assert list(map(get_source, ha.get_tail())) == hist1 + sid1 = hm1_last_sid() + assert sid1 is not None + assert ha_last_sid() == sid1 + + # hm2 creates a new session and adds entries, + # ha catches up + hm2 = HistoryManager(shell=ip, hist_file=hist_file) + hm2_last_sid = hm2.get_last_session_id + + hist2 = ["a=2", "b=2", "c=2"] + for i, h in enumerate(hist2 + [""], start=1): + hm2.store_inputs(i, h) + tail = hm2.get_tail(n=3) + assert list(map(get_source, tail)) == hist2 + tail = ha.get_tail(n=3) + assert list(map(get_source, tail)) == hist2 + sid2 = hm2_last_sid() + assert sid2 is not None + assert ha_last_sid() == sid2 + assert sid2 != sid1 + + # but hm1 still maintains its point of reference + # and adding more entries to it doesn't change others + # immediate perspective + assert hm1_last_sid() == sid1 + tail = hm1.get_tail(n=3) + assert list(map(get_source, tail)) == hist1 + + hist3 = ["a=3", "b=3", "c=3"] + for i, h in enumerate(hist3 + [""], start=5): + hm1.store_inputs(i, h) + tail = hm1.get_tail(n=7) + assert list(map(get_source, tail)) == hist1 + [""] + hist3 + tail = hm2.get_tail(n=3) + assert list(map(get_source, tail)) == hist2 + tail = ha.get_tail(n=3) + assert list(map(get_source, tail)) == hist2 + assert hm1_last_sid() == sid1 + assert hm2_last_sid() == sid2 + assert ha_last_sid() == sid2 + finally: + if hm1: + hm1.save_thread.stop() + if hm2: + hm2.save_thread.stop() + hm = hm1 or hm2 + if hm: + hm.db.close()