Skip to content

Commit 5bc6fa2

Browse files
codexByron
authored andcommitted
Close custom object stream in regression test
The Python package test (windows, 3.7) check failed during TemporaryDirectory cleanup because the GitDB regression left its loose-object mmap open, producing WinError 5 while deleting the object file. Close the object stream explicitly and use Repo's context manager so Windows releases both resources before temporary-directory cleanup. Validation: focused regression test; Ruff check and format; mypy; compileall; git diff --check.
1 parent 5b6ea0f commit 5bc6fa2

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

test/test_repo.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -247,9 +247,14 @@ def test_repo_discovery_preserves_object_directory(self):
247247
with cwd(tdir), mock.patch.dict(os.environ, {"GIT_DIR": "git", "GIT_OBJECT_DIRECTORY": "objects"}):
248248
repo = Repo(odbt=GitDB)
249249

250-
assert osp.samefile(repo.odb.root_path(), object_dir)
251-
assert repo.odb.stream(bytes.fromhex(blob_hexsha)).read() == payload
252-
assert repo.git.cat_file("blob", blob_hexsha) == payload.decode()
250+
with repo:
251+
assert osp.samefile(repo.odb.root_path(), object_dir)
252+
object_stream = repo.odb.stream(bytes.fromhex(blob_hexsha))
253+
try:
254+
assert object_stream.read() == payload
255+
finally:
256+
object_stream.stream.close()
257+
assert repo.git.cat_file("blob", blob_hexsha) == payload.decode()
253258

254259
@with_rw_repo("0.3.2.1")
255260
def test_repo_creation_from_different_paths(self, rw_repo):

0 commit comments

Comments
 (0)