fix(library): close sqlite and PDF temp handles so tests pass on Windows - #145
Open
hudsonwa wants to merge 1 commit into
Open
fix(library): close sqlite and PDF temp handles so tests pass on Windows#145hudsonwa wants to merge 1 commit into
hudsonwa wants to merge 1 commit into
Conversation
tests/library/* and the PDF golden test assumed POSIX semantics where an open file handle does not block another process from opening that path. On Windows: - sqlite test helpers used \with sqlite3.connect(path) as db:\, which commits on exit but does not close the connection, so temporary_directory.cleanup() in tearDown failed with PermissionError [WinError 32]. - _write_artifacts kept a NamedTemporaryFile handle open while handing source.name to the native liteparse parser, which then could not open it (PDF error: file not found). Fix: close the sqlite connection after each helper block, and for the PDF artifact use delete=False + close the handle before parsing, then unlink. Prevents a fresh Windows checkout from failing scripts/verify.sh pytest step. Closes LLMQuant#143.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
A fresh Windows checkout fails
scripts/verify.shat the pytest step (18 failures) because several tests and one production helper assumed POSIX semantics where an open file handle does not block another process from opening that path. On Windows, an open handle prevents deletion/opening, so:with sqlite3.connect(path) as db:, which commits on exit but does not close the connection.tempfile.TemporaryDirectory.cleanup()intearDowntherefore failed withPermissionError [WinError 32](17 of the 18 failures, intests/library/)._write_artifactsinquantmind/preprocess/format/pdf.pykept aNamedTemporaryFilehandle open while handingsource.nameto the nativeliteparseparser, which then could not open the path (PDF error: file not found) — the 18th failure.This PR fixes both root causes:
with sqlite3.connect(...) as db:helper block in the four library test files (db.close()immediately after the block). This preserves the block's commit-on-exit semantics while releasing the file handle so the temp dir can be cleaned up.delete=False, close the temp file handle before passing the path to the native parser, and unlink the file afterward in afinally.These are test-infra / Windows-portability fixes only; no production behavior changes.
Related Issue
Closes #143
Verification
Performed on a Windows 11 host (Python 3.12.10) with the
.[dev]environment, on a fresh shallow clone:test_pdf.py::test_golden_preserves_pages_blocks_coordinates_and_artifactsfails withPDF error: file not found;tests/library/test_local.py,test_structure.py,test_paper.pyfail withPermissionError [WinError 32](17 failures).pytest tests/library/test_local.py tests/library/test_structure.py tests/library/test_paper.py tests/library/test_example_bundle.py tests/preprocess/format/test_pdf.py->40 passed425 passed, 1 failedwhere the single failure is the pre-existing, unrelatedDiscoverPRNewswireTests::test_cache_bust_retries_listing_404timing flake (microsecond cache-bust timestamp collision inquantmind/preprocess/pr_newswire.py); it fails identically on an unmodifiedmastercheckout and is not touched by this change.ruff checkon the changed files -> "All checks passed!";ruff format --check-> all changed files formatted.scripts/verify.shcould not be run end-to-end on the Windows box because its shell script is checked out with CRLF line endings (fails under Git Bash on Windows with$'\r': command not found); its individual steps were run and verified as green as noted above.Checklist
type(scope): summary.bash scripts/verify.shpasses.