Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Avoid brittle assumptions about preexisting temporary files in tests#1759

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Byron merged 3 commits intogitpython-developers:mainfromEliahKagan:subdir
Dec 8, 2023
Merged
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 25 additions & 19 deletionstest/test_repo.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -41,7 +41,7 @@
UnsafeProtocolError,
)
fromgit.repo.funimporttouch
fromgit.utilimportbin_to_hex,cygpath,join_path_native,rmfile,rmtree
fromgit.utilimportbin_to_hex,cwd,cygpath,join_path_native,rmfile,rmtree
fromtest.libimportTestBase,fixture,with_rw_directory,with_rw_repo


Expand DownExpand Up@@ -71,15 +71,30 @@ def tearDown(self):
forlfpinglob.glob(_tc_lock_fpaths):
ifosp.isfile(lfp):
raiseAssertionError("Previous TC left hanging git-lock file: {}".format(lfp))

importgc

gc.collect()

deftest_new_should_raise_on_invalid_repo_location(self):
self.assertRaises(InvalidGitRepositoryError,Repo,tempfile.gettempdir())
# Ideally this tests a directory that is outside of any repository. In the rare
# case tempfile.gettempdir() is inside a repo, this still passes, but tests the
# same scenario as test_new_should_raise_on_invalid_repo_location_within_repo.
withtempfile.TemporaryDirectory()astdir:
self.assertRaises(InvalidGitRepositoryError,Repo,tdir)

@with_rw_directory
deftest_new_should_raise_on_invalid_repo_location_within_repo(self,rw_dir):
repo_dir=osp.join(rw_dir,"repo")
Repo.init(repo_dir)
subdir=osp.join(repo_dir,"subdir")
os.mkdir(subdir)
self.assertRaises(InvalidGitRepositoryError,Repo,subdir)

deftest_new_should_raise_on_non_existent_path(self):
self.assertRaises(NoSuchPathError,Repo,"repos/foobar")
withtempfile.TemporaryDirectory()astdir:
nonexistent=osp.join(tdir,"foobar")
self.assertRaises(NoSuchPathError,Repo,nonexistent)

@with_rw_repo("0.3.2.1")
deftest_repo_creation_from_different_paths(self,rw_repo):
Expand DownExpand Up@@ -118,7 +133,7 @@ def test_tree_from_revision(self):
self.assertEqual(tree.type,"tree")
self.assertEqual(self.rorepo.tree(tree),tree)

#try from invalid revision that does not exist
#Try fromaninvalid revision that does not exist.
self.assertRaises(BadName,self.rorepo.tree,"hello world")

deftest_pickleable(self):
Expand DownExpand Up@@ -507,13 +522,11 @@ def write(self, b):
repo.git.log(n=100,output_stream=TestOutputStream(io.DEFAULT_BUFFER_SIZE))

deftest_init(self):
prev_cwd=os.getcwd()
os.chdir(tempfile.gettempdir())
git_dir_rela="repos/foo/bar.git"
del_dir_abs=osp.abspath("repos")
git_dir_abs=osp.abspath(git_dir_rela)
try:
# with specific path
withtempfile.TemporaryDirectory()astdir,cwd(tdir):
git_dir_rela="repos/foo/bar.git"
git_dir_abs=osp.abspath(git_dir_rela)

# With specific path
forpathin (git_dir_rela,git_dir_abs):
r=Repo.init(path=path,bare=True)
self.assertIsInstance(r,Repo)
Expand All@@ -523,7 +536,7 @@ def test_init(self):

self._assert_empty_repo(r)

#test clone
#Test clone
clone_path=path+"_clone"
rc=r.clone(clone_path)
self._assert_empty_repo(rc)
Expand DownExpand Up@@ -558,13 +571,6 @@ def test_init(self):
assertnotr.has_separate_working_tree()

self._assert_empty_repo(r)
finally:
try:
rmtree(del_dir_abs)
exceptOSError:
pass
os.chdir(prev_cwd)
# END restore previous state

deftest_bare_property(self):
self.rorepo.bare
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp