Skip to content

Commit 4184e4c

Browse files
codexByron
authored andcommitted
test: read historical trees without cloning a checkout
Eight lookup tests cloned and checked out `0.3.2.1` only to read paths from its tree. Resolve that historical tree through the existing class repository instead. Each assertion still uses a fresh tree wrapper and checks the same blob or tree IDs, pathlike operands, and missing-path errors. All 22 tree tests passed with GixPython first in 1.66 seconds wall time, then CLI in 3.86 seconds. Ruff lint and formatting checks passed.
1 parent 1b0810e commit 4184e4c

1 file changed

Lines changed: 25 additions & 34 deletions

File tree

‎test/test_tree.py‎

Lines changed: 25 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,10 @@
1616

1717
from git.objects import Blob, Tree
1818
from git.objects.tree import TreeModifier
19-
from git.repo import Repo
2019
from git.util import cwd
2120
from test.lib import TestBase, with_rw_directory
2221

23-
from .lib.helper import PathLikeMock, with_rw_repo
22+
from .lib.helper import PathLikeMock
2423

2524

2625
@ddt.ddt
@@ -303,56 +302,48 @@ def lib_folder(t, _d):
303302
# END for each item
304303
assert found_slash
305304

306-
@with_rw_repo("0.3.2.1")
307-
def test_repo_lookup_string_path(self, rw_repo):
308-
repo = Repo(rw_repo.git_dir)
309-
blob = repo.tree() / ".gitignore"
305+
def test_repo_lookup_string_path(self):
306+
tree = self.rorepo.tree("0.3.2.1")
307+
blob = tree / ".gitignore"
310308
assert isinstance(blob, Blob)
311309
assert blob.hexsha == "787b3d442a113b78e343deb585ab5531eb7187fa"
312310

313-
@with_rw_repo("0.3.2.1")
314-
def test_repo_lookup_pathlike_path(self, rw_repo):
315-
repo = Repo(rw_repo.git_dir)
316-
blob = repo.tree() / PathLikeMock(".gitignore")
311+
def test_repo_lookup_pathlike_path(self):
312+
tree = self.rorepo.tree("0.3.2.1")
313+
blob = tree / PathLikeMock(".gitignore")
317314
assert isinstance(blob, Blob)
318315
assert blob.hexsha == "787b3d442a113b78e343deb585ab5531eb7187fa"
319316

320-
@with_rw_repo("0.3.2.1")
321-
def test_repo_lookup_invalid_string_path(self, rw_repo):
322-
repo = Repo(rw_repo.git_dir)
317+
def test_repo_lookup_invalid_string_path(self):
318+
tree = self.rorepo.tree("0.3.2.1")
323319
with pytest.raises(KeyError):
324-
repo.tree() / "doesnotexist"
320+
tree / "doesnotexist"
325321

326-
@with_rw_repo("0.3.2.1")
327-
def test_repo_lookup_invalid_pathlike_path(self, rw_repo):
328-
repo = Repo(rw_repo.git_dir)
322+
def test_repo_lookup_invalid_pathlike_path(self):
323+
tree = self.rorepo.tree("0.3.2.1")
329324
with pytest.raises(KeyError):
330-
repo.tree() / PathLikeMock("doesnotexist")
325+
tree / PathLikeMock("doesnotexist")
331326

332-
@with_rw_repo("0.3.2.1")
333-
def test_repo_lookup_nested_string_path(self, rw_repo):
334-
repo = Repo(rw_repo.git_dir)
335-
blob = repo.tree() / "git/__init__.py"
327+
def test_repo_lookup_nested_string_path(self):
328+
tree = self.rorepo.tree("0.3.2.1")
329+
blob = tree / "git/__init__.py"
336330
assert isinstance(blob, Blob)
337331
assert blob.hexsha == "d87dcbdbb65d2782e14eea27e7f833a209c052f3"
338332

339-
@with_rw_repo("0.3.2.1")
340-
def test_repo_lookup_nested_pathlike_path(self, rw_repo):
341-
repo = Repo(rw_repo.git_dir)
342-
blob = repo.tree() / PathLikeMock("git/__init__.py")
333+
def test_repo_lookup_nested_pathlike_path(self):
334+
tree = self.rorepo.tree("0.3.2.1")
335+
blob = tree / PathLikeMock("git/__init__.py")
343336
assert isinstance(blob, Blob)
344337
assert blob.hexsha == "d87dcbdbb65d2782e14eea27e7f833a209c052f3"
345338

346-
@with_rw_repo("0.3.2.1")
347-
def test_repo_lookup_folder_string_path(self, rw_repo):
348-
repo = Repo(rw_repo.git_dir)
349-
tree = repo.tree() / "git"
339+
def test_repo_lookup_folder_string_path(self):
340+
tree = self.rorepo.tree("0.3.2.1")
341+
tree = tree / "git"
350342
assert isinstance(tree, Tree)
351343
assert tree.hexsha == "ec8ae429156d65afde4bbb3455570193b56f0977"
352344

353-
@with_rw_repo("0.3.2.1")
354-
def test_repo_lookup_folder_pathlike_path(self, rw_repo):
355-
repo = Repo(rw_repo.git_dir)
356-
tree = repo.tree() / PathLikeMock("git")
345+
def test_repo_lookup_folder_pathlike_path(self):
346+
tree = self.rorepo.tree("0.3.2.1")
347+
tree = tree / PathLikeMock("git")
357348
assert isinstance(tree, Tree)
358349
assert tree.hexsha == "ec8ae429156d65afde4bbb3455570193b56f0977"

0 commit comments

Comments
 (0)