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

Function test_history_trim_cli

tests/test_history.py:518–543  ·  view source on GitHub ↗

`ipython history trim/clear` must replace the database file. All sqlite connections to the old database have to be closed before it is unlinked, otherwise this fails on Windows and leaves a stray ``history.sqlite.new`` file behind (gh-15241).

(tmp_path, subcommand, kept)

Source from the content-addressed store, hash-verified

516 ],
517)
518def test_history_trim_cli(tmp_path, subcommand, kept):
519 """`ipython history trim/clear` must replace the database file.
520
521 All sqlite connections to the old database have to be closed before it is
522 unlinked, otherwise this fails on Windows and leaves a stray
523 ``history.sqlite.new`` file behind (gh-15241).
524 """
525 profile_dir = tmp_path / "profile_default"
526 profile_dir.mkdir()
527 hist_file = profile_dir / "history.sqlite"
528 _make_history_db(hist_file, 5)
529
530 env = os.environ.copy()
531 env["IPYTHONDIR"] = str(tmp_path)
532 proc = subprocess.run(
533 [sys.executable, "-m", "IPython", "history"] + subcommand,
534 capture_output=True,
535 text=True,
536 env=env,
537 check=False,
538 )
539 assert proc.returncode == 0, proc.stderr
540 assert list(profile_dir.glob("history.sqlite.new*")) == []
541 with closing(sqlite3.connect(hist_file)) as con:
542 rows = list(con.execute("SELECT source FROM history"))
543 assert len(rows) == kept

Callers

nothing calls this directly

Calls 5

_make_history_dbFunction · 0.85
connectMethod · 0.80
executeMethod · 0.80
copyMethod · 0.45
runMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…