Add failing tests for joining paths · gitpython-developers/GitPython@9fa28ae
@@ -8,10 +8,14 @@
88from pathlib import Path
99import subprocess
101011+import pytest
12+1113from git.objects import Blob, Tree
14+from git.repo import Repo
1215from git.util import cwd
13161417from test.lib import TestBase, with_rw_directory
18+from .lib.helper import PathLikeMock, with_rw_repo
151916201721class TestTree(TestBase):
@@ -161,3 +165,57 @@ def lib_folder(t, _d):
161165assert root[item.path] == item == root / item.path
162166# END for each item
163167assert found_slash
168+169+@with_rw_repo("0.3.2.1")
170+def test_repo_lookup_string_path(self, rw_repo):
171+repo = Repo(rw_repo.git_dir)
172+blob = repo.tree() / ".gitignore"
173+assert isinstance(blob, Blob)
174+assert blob.hexsha == "787b3d442a113b78e343deb585ab5531eb7187fa"
175+176+@with_rw_repo("0.3.2.1")
177+def test_repo_lookup_pathlike_path(self, rw_repo):
178+repo = Repo(rw_repo.git_dir)
179+blob = repo.tree() / PathLikeMock(".gitignore")
180+assert isinstance(blob, Blob)
181+assert blob.hexsha == "787b3d442a113b78e343deb585ab5531eb7187fa"
182+183+@with_rw_repo("0.3.2.1")
184+def test_repo_lookup_invalid_string_path(self, rw_repo):
185+repo = Repo(rw_repo.git_dir)
186+with pytest.raises(KeyError):
187+repo.tree() / "doesnotexist"
188+189+@with_rw_repo("0.3.2.1")
190+def test_repo_lookup_invalid_pathlike_path(self, rw_repo):
191+repo = Repo(rw_repo.git_dir)
192+with pytest.raises(KeyError):
193+repo.tree() / PathLikeMock("doesnotexist")
194+195+@with_rw_repo("0.3.2.1")
196+def test_repo_lookup_nested_string_path(self, rw_repo):
197+repo = Repo(rw_repo.git_dir)
198+blob = repo.tree() / "git/__init__.py"
199+assert isinstance(blob, Blob)
200+assert blob.hexsha == "d87dcbdbb65d2782e14eea27e7f833a209c052f3"
201+202+@with_rw_repo("0.3.2.1")
203+def test_repo_lookup_nested_pathlike_path(self, rw_repo):
204+repo = Repo(rw_repo.git_dir)
205+blob = repo.tree() / PathLikeMock("git/__init__.py")
206+assert isinstance(blob, Blob)
207+assert blob.hexsha == "d87dcbdbb65d2782e14eea27e7f833a209c052f3"
208+209+@with_rw_repo("0.3.2.1")
210+def test_repo_lookup_folder_string_path(self, rw_repo):
211+repo = Repo(rw_repo.git_dir)
212+blob = repo.tree() / "git"
213+assert isinstance(blob, Tree)
214+assert blob.hexsha == "ec8ae429156d65afde4bbb3455570193b56f0977"
215+216+@with_rw_repo("0.3.2.1")
217+def test_repo_lookup_folder_pathlike_path(self, rw_repo):
218+repo = Repo(rw_repo.git_dir)
219+blob = repo.tree() / PathLikeMock("git")
220+assert isinstance(blob, Tree)
221+assert blob.hexsha == "ec8ae429156d65afde4bbb3455570193b56f0977"