Procházet zdrojové kódy

Add missing cleanups

Jelmer Vernooij před 1 měsícem
rodič
revize
6964056158

+ 7 - 0
tests/compat/server_utils.py

@@ -158,6 +158,7 @@ class ServerTests:
         new_repo_dir = os.path.join(new_repo_base_dir, "empty_new")
         run_git_or_fail(["clone", self.url(port), new_repo_dir], cwd=new_repo_base_dir)
         new_repo = Repo(new_repo_dir)
+        self.addCleanup(new_repo.close)
         self.assertReposEqual(self._old_repo, new_repo)
 
     def test_lsremote_from_dulwich(self) -> None:
@@ -184,7 +185,9 @@ class ServerTests:
                 self._stub_repo.path,
             ]
         )
+        self._stub_repo.close()
         clone = self._stub_repo = Repo(self._stub_repo.path)
+        self.addCleanup(clone.close)
         expected_shallow = [
             b"35e0b59e187dd72a0af294aedffc213eaa4d03ff",
             b"514dc6d3fbfe77361bcaef320c4d21b72bc10be9",
@@ -247,7 +250,9 @@ class ServerTests:
                 self._stub_repo.path,
             ]
         )
+        self._stub_repo.close()
         clone = self._stub_repo = Repo(self._stub_repo.path)
+        self.addCleanup(clone.close)
 
         # Fetching at the same depth is a no-op.
         run_git_or_fail(
@@ -279,7 +284,9 @@ class ServerTests:
                 self._stub_repo.path,
             ]
         )
+        self._stub_repo.close()
         clone = self._stub_repo = Repo(self._stub_repo.path)
+        self.addCleanup(clone.close)
 
         # Fetching at the same depth is a no-op.
         run_git_or_fail(

+ 9 - 0
tests/compat/test_commit_graph.py

@@ -137,6 +137,7 @@ class CommitGraphCompatTests(CompatTestCase):
 
         # Open the repository with dulwich
         repo = Repo(self.repo_path)
+        self.addCleanup(repo.close)
 
         # Verify that all commits in the graph are accessible
         for entry in commit_graph:
@@ -165,6 +166,7 @@ class CommitGraphCompatTests(CompatTestCase):
         commits, work_dir = self.create_test_repo_with_history()
 
         repo = Repo(self.repo_path)
+        self.addCleanup(repo.close)
 
         # Get some commit IDs for testing
         main_head = repo.refs[b"refs/heads/master"]
@@ -177,7 +179,9 @@ class CommitGraphCompatTests(CompatTestCase):
         run_git_or_fail(["commit-graph", "write", "--reachable"], cwd=work_dir)
 
         # Force reload of repository to pick up commit graph
+        repo.close()
         repo = Repo(self.repo_path)
+        self.addCleanup(repo.close)
 
         # Calculate merge base with commit graph
         merge_base_with_graph = find_merge_base(repo, [main_head, feature_head])
@@ -206,6 +210,7 @@ class CommitGraphCompatTests(CompatTestCase):
         commits, work_dir = self.create_test_repo_with_history()
 
         repo = Repo(self.repo_path)
+        self.addCleanup(repo.close)
 
         # Test with a simple fast-forward case (older commit to newer commit)
         commit1 = commits[1]  # Second commit
@@ -218,7 +223,9 @@ class CommitGraphCompatTests(CompatTestCase):
         run_git_or_fail(["commit-graph", "write", "--reachable"], cwd=work_dir)
 
         # Force reload
+        repo.close()
         repo = Repo(self.repo_path)
+        self.addCleanup(repo.close)
 
         # Check with commit graph
         can_ff_with_graph = can_fast_forward(repo, commit1, commit2)
@@ -259,6 +266,7 @@ class CommitGraphCompatTests(CompatTestCase):
         commit_graph = read_commit_graph(graph_file)
 
         repo = Repo(self.repo_path)
+        self.addCleanup(repo.close)
 
         # Build a map of commit to generation number
         generation_map = {}
@@ -415,6 +423,7 @@ class CommitGraphCompatTests(CompatTestCase):
         commit_graph = read_commit_graph(graph_file)
 
         repo = Repo(self.repo_path)
+        self.addCleanup(repo.close)
 
         # Verify tagged commits are in the graph
         tagged_commits = [commits[2], commits[4]]

+ 2 - 1
tests/compat/test_lfs.py

@@ -352,7 +352,8 @@ class LFSCloneCompatTest(LFSCompatTestCase):
 
         # Clone with dulwich
         target_dir = self.make_temp_dir()
-        porcelain.clone(source_dir, target_dir)
+        cloned_repo = porcelain.clone(source_dir, target_dir)
+        self.addCleanup(cloned_repo.close)
 
         # Verify LFS file exists as pointer
         cloned_file = os.path.join(target_dir, "test.bin")

+ 11 - 0
tests/compat/test_reftable.py

@@ -157,6 +157,7 @@ class ReftableCompatTestCase(CompatTestCase):
 
         # Open with Dulwich
         repo = Repo(self.test_dir)
+        self.addCleanup(repo.close)
 
         # Verify it's using reftable
         self.assertIsInstance(repo.refs, ReftableRefsContainer)
@@ -274,6 +275,7 @@ class ReftableCompatTestCase(CompatTestCase):
 
         # Read refs with Dulwich
         repo = Repo(self.test_dir)
+        self.addCleanup(repo.close)
         dulwich_refs = repo.get_refs()
 
         # Compare non-symbolic refs
@@ -300,6 +302,7 @@ class ReftableCompatTestCase(CompatTestCase):
 
         # Read with both git and Dulwich
         repo = Repo(self.test_dir)
+        self.addCleanup(repo.close)
         dulwich_refs = repo.get_refs()
 
         git_output = self._run_git(["show-ref"])
@@ -407,6 +410,7 @@ class ReftableCompatTestCase(CompatTestCase):
         ).strip()
 
         repo = Repo(self.test_dir)
+        self.addCleanup(repo.close)
 
         # Test complex batched operations
         with repo.refs.batch_update():
@@ -478,6 +482,7 @@ class ReftableCompatTestCase(CompatTestCase):
         ).strip()
 
         repo = Repo(self.test_dir)
+        self.addCleanup(repo.close)
 
         # Create multiple refs
         with repo.refs.batch_update():
@@ -529,6 +534,7 @@ class ReftableCompatTestCase(CompatTestCase):
 
         # Create many refs efficiently
         repo = Repo(self.test_dir)
+        self.addCleanup(repo.close)
 
         with repo.refs.batch_update():
             # Create 50 branches
@@ -590,6 +596,7 @@ class ReftableCompatTestCase(CompatTestCase):
         ).strip()
 
         repo = Repo(self.test_dir)
+        self.addCleanup(repo.close)
 
         # Create chain of symbolic refs
         with repo.refs.batch_update():
@@ -633,6 +640,7 @@ class ReftableCompatTestCase(CompatTestCase):
         ).strip()
 
         repo = Repo(self.test_dir)
+        self.addCleanup(repo.close)
 
         # Test refs with special characters and structures
         special_refs = [
@@ -689,6 +697,7 @@ class ReftableCompatTestCase(CompatTestCase):
             commits.append(commit_sha)
 
         repo = Repo(self.test_dir)
+        self.addCleanup(repo.close)
 
         # Simulate concurrent operations with multiple batch updates
         # First batch: Create initial refs
@@ -759,6 +768,7 @@ class ReftableCompatTestCase(CompatTestCase):
         ).strip()
 
         repo = Repo(self.test_dir)
+        self.addCleanup(repo.close)
 
         with repo.refs.batch_update():
             repo.refs.set_if_equals(b"refs/heads/master", None, commit_sha)
@@ -775,6 +785,7 @@ class ReftableCompatTestCase(CompatTestCase):
 
         # Verify dulwich can still read after git modifications
         repo = Repo(self.test_dir)
+        self.addCleanup(repo.close)
         dulwich_refs = repo.get_refs()
 
         # Should be able to read git-modified refs

+ 2 - 0
tests/test_commit_graph.py

@@ -691,6 +691,7 @@ class CommitGraphGenerationTests(unittest.TestCase):
 
         # Verify commit graph is loaded by creating new repo instance
         repo2 = Repo(repo_path)
+        self.addCleanup(repo2.close)
         repo2.object_store = object_store
 
         # Verify commit graph is available
@@ -780,6 +781,7 @@ class CommitGraphGenerationTests(unittest.TestCase):
 
         # Create new repo instance to pick up commit graph
         repo2 = Repo(repo_path)
+        self.addCleanup(repo2.close)
         repo2.object_store = object_store
 
         # Verify commit graph is loaded

+ 2 - 0
tests/test_grafts.py

@@ -168,6 +168,7 @@ class GraftsInRepoTests(GraftsInRepositoryBase, TestCase):
         r._put_named_file(os.path.join("info", "grafts"), b"")
 
         r = Repo(self._repo_dir)
+        self.addCleanup(r.close)
         self.assertEqual({}, r._graftpoints)
 
     def test_init_with_info_grafts(self) -> None:
@@ -178,6 +179,7 @@ class GraftsInRepoTests(GraftsInRepositoryBase, TestCase):
         )
 
         r = Repo(self._repo_dir)
+        self.addCleanup(r.close)
         self.assertEqual({self._shas[-1]: [self._shas[0]]}, r._graftpoints)
 
 

+ 3 - 0
tests/test_porcelain.py

@@ -918,6 +918,7 @@ class CloneTests(PorcelainTestCase):
         self.addCleanup(r.close)
         self.assertEqual(r.path, target_path)
         target_repo = Repo(target_path)
+        self.addCleanup(target_repo.close)
         self.assertEqual(0, len(target_repo.open_index()))
         self.assertEqual(c3.id, target_repo.refs[b"refs/tags/foo"])
         self.assertNotIn(b"f1", os.listdir(target_path))
@@ -1055,6 +1056,7 @@ class CloneTests(PorcelainTestCase):
         self.addCleanup(r.close)
         self.assertEqual(r.path, target_path)
         target_repo = Repo(target_path)
+        self.addCleanup(target_repo.close)
         self.assertEqual(0, len(target_repo.open_index()))
         self.assertEqual(c1.id, target_repo.refs[b"refs/heads/else"])
         self.assertEqual(c1.id, target_repo.refs[b"HEAD"])
@@ -4187,6 +4189,7 @@ class CheckoutTests(PorcelainTestCase):
         target_path = tempfile.mkdtemp()
         self.addCleanup(shutil.rmtree, target_path)
         target_repo = porcelain.clone(remote_path, target_path)
+        self.addCleanup(target_repo.close)
 
         # Create a remote tracking branch reference
         remote_branch_ref = b"refs/remotes/origin/feature"

+ 4 - 0
tests/test_porcelain_merge.py

@@ -283,6 +283,7 @@ class PorcelainMergeTreeTests(TestCase):
             # Initialize repo
             porcelain.init(tmpdir)
             repo = Repo(tmpdir)
+            self.addCleanup(repo.close)
 
             # Create base tree
             with open(os.path.join(tmpdir, "file1.txt"), "w") as f:
@@ -329,6 +330,7 @@ class PorcelainMergeTreeTests(TestCase):
             # Initialize repo
             porcelain.init(tmpdir)
             repo = Repo(tmpdir)
+            self.addCleanup(repo.close)
 
             # Create base tree
             with open(os.path.join(tmpdir, "file1.txt"), "w") as f:
@@ -381,6 +383,7 @@ class PorcelainMergeTreeTests(TestCase):
             # Initialize repo
             porcelain.init(tmpdir)
             repo = Repo(tmpdir)
+            self.addCleanup(repo.close)
 
             # Create our tree
             with open(os.path.join(tmpdir, "file1.txt"), "w") as f:
@@ -414,6 +417,7 @@ class PorcelainMergeTreeTests(TestCase):
             # Initialize repo
             porcelain.init(tmpdir)
             repo = Repo(tmpdir)
+            self.addCleanup(repo.close)
 
             # Create base tree
             with open(os.path.join(tmpdir, "file1.txt"), "w") as f:

+ 1 - 0
tests/test_repository.py

@@ -1302,6 +1302,7 @@ class BuildRepoRootTests(TestCase):
         c.set(("core",), "looseCompression", "4")
         c.write_to_path()
         r = Repo(self._repo_dir)
+        self.addCleanup(r.close)
         self.assertEqual(r.object_store.loose_compression_level, 4)
 
     def test_repositoryformatversion_unsupported(self) -> None: