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

Commit9277ff5

Browse files
committed
Avoid another tempdir content assumption in test
test_init was using tempfile.gettempdir() directly to get thelocation where the hard-coded path repos/foo/bar.git would be usedto test repository creation with relative and absolute paths. Thatreused the same location each time, and also assumed the directorywould be usable, which could fail due to previous runs or due tothe path being used separately from GitPython's tests. This commitfixes that by using that path inside a temporary directory, knownat the start of the test to be empty.Reorganizing the acquision and cleanup logic also has had theeffect of causing the test no longer to be skipped due to the logicin git.util.rmtree due to the final cleanup attempt (after allassertions). The directory is now successfully removed on Windows,and the test passes on all platforms.
1 parentad570de commit9277ff5

File tree

1 file changed

+7
-16
lines changed

1 file changed

+7
-16
lines changed

‎test/test_repo.py

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
UnsafeProtocolError,
4242
)
4343
fromgit.repo.funimporttouch
44-
fromgit.utilimportbin_to_hex,cygpath,join_path_native,rmfile,rmtree
44+
fromgit.utilimportbin_to_hex,cwd,cygpath,join_path_native,rmfile,rmtree
4545
fromtest.libimportTestBase,fixture,with_rw_directory,with_rw_repo
4646

4747

@@ -511,13 +511,11 @@ def write(self, b):
511511
repo.git.log(n=100,output_stream=TestOutputStream(io.DEFAULT_BUFFER_SIZE))
512512

513513
deftest_init(self):
514-
prev_cwd=os.getcwd()
515-
os.chdir(tempfile.gettempdir())
516-
git_dir_rela="repos/foo/bar.git"
517-
del_dir_abs=osp.abspath("repos")
518-
git_dir_abs=osp.abspath(git_dir_rela)
519-
try:
520-
# with specific path
514+
withtempfile.TemporaryDirectory()astdir,cwd(tdir):
515+
git_dir_rela="repos/foo/bar.git"
516+
git_dir_abs=osp.abspath(git_dir_rela)
517+
518+
# With specific path
521519
forpathin (git_dir_rela,git_dir_abs):
522520
r=Repo.init(path=path,bare=True)
523521
self.assertIsInstance(r,Repo)
@@ -527,7 +525,7 @@ def test_init(self):
527525

528526
self._assert_empty_repo(r)
529527

530-
#test clone
528+
#Test clone
531529
clone_path=path+"_clone"
532530
rc=r.clone(clone_path)
533531
self._assert_empty_repo(rc)
@@ -562,13 +560,6 @@ def test_init(self):
562560
assertnotr.has_separate_working_tree()
563561

564562
self._assert_empty_repo(r)
565-
finally:
566-
try:
567-
rmtree(del_dir_abs)
568-
exceptOSError:
569-
pass
570-
os.chdir(prev_cwd)
571-
# END restore previous state
572563

573564
deftest_bare_property(self):
574565
self.rorepo.bare

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp