`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)
| 516 | ], |
| 517 | ) |
| 518 | def 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 |
nothing calls this directly
no test coverage detected
searching dependent graphs…