Skip to content

test(signatures): save through a temp directory, not an open temporary file - #10971

Open
Luckyou-d wants to merge 1 commit into
stanfordnlp:mainfrom
Luckyou-d:test/save-load-without-an-open-handle
Open

Luckyou-d wants to merge 1 commit into
stanfordnlp:mainfrom
Luckyou-d:test/save-load-without-an-open-handle

Conversation

@Luckyou-d

Copy link
Copy Markdown

Six save/load cases in the signature adapter suites hold a temporary file open and then ask DSPy to write that same path:

with tempfile.NamedTemporaryFile(mode="w+", delete=True, suffix=".json") as temp_file:
    compiled_predictor.save(temp_file.name)     # PermissionError on Windows
    loaded_predictor.load(temp_file.name)

POSIX lets a second handle write over a file that is already open; Windows refuses it with PermissionError: [Errno 13] Permission denied: 'C:\...\tmp_zpw3l9u.json'. So the suites are green on CI and red for anyone on Windows, for a reason that has nothing to do with saving:

tests/signatures/test_adapter_file.py::test_save_load_file_signature
tests/signatures/test_adapter_image.py::test_predictor_save_load
tests/signatures/test_adapter_image.py::test_save_load_complex_default_types
tests/signatures/test_adapter_image.py::test_save_load_complex_types[test_case0]
tests/signatures/test_adapter_image.py::test_save_load_complex_types[test_case1]
tests/signatures/test_adapter_image.py::test_save_load_pydantic_model

Change

Use TemporaryDirectory and save to a path inside it. Nothing else moves: the same signature, the same save()/load() calls, the same assertions after the block.

Verification

  • pytest tests/signatures/test_adapter_file.py tests/signatures/test_adapter_image.py -> 72 passed, 2 xfailed; on main the same two files are 66 passed, 6 failed, the six listed above.
  • pytest tests/signatures -> 127 passed, 2 xfailed.
  • ruff check and ruff format clean on both files (ruff check tests/signatures/ still reports the 11 pre-existing findings in test_custom_types.py, which this does not touch).

Found while looking at save/load round trips; test-side only, no behaviour change.

…y file

Six save/load cases held a `NamedTemporaryFile` open and then asked
`compiled_predictor.save()` to write that same path. POSIX allows it; Windows
refuses the second handle with `PermissionError: [Errno 13]`, which is why the
file and image adapter suites were red there and green on CI.

`TemporaryDirectory` gives a path with no handle attached, so the cases exercise
the save/load code instead of the platform's file locking.
@greptile-apps

greptile-apps Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5 · The PR appears safe to merge; the test changes preserve the existing save/load checks.RetriggerView in GreptileConfidence Score: 5/5

[Low impact] The PR appears safe to merge; the test changes preserve the existing save/load checks.

Summary

Updates six save/load test cases to avoid writing over an open temporary file on Windows.

  • Signature adapter tests save through a path inside a temporary directory.
  • The image prefix check spans multiple lines but expects the same text.

No actionable issues found. Tests were not run during this review.

Reviews (2) · Last reviewed commit: "test(signatures): save through a temp di..." · Reviewed by Greptile

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant