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

Commitad570de

Browse files
committed
Avoid unsafe assumptions about tempdir content in tests
test_new_should_raise_on_invalid_repo_location had previously usedtempfile.gettempdir() directly to get a path assumed not to be avalid repository, assuming more than necessary about the directoryin which temporary files and directories are created. A newlycreated temporary directory is now used for that check, instead.test_new_should_raise_on_non_existent_path had assumed norepos/foobar existed relative to the current directory. Typicallythere would be no such directory, but is unnecessary for the testto rely on this. A newly created temporary directory known to beempty is now used in place of the "repos" component, for that test.
1 parentd7bf231 commitad570de

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

‎test/test_repo.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,15 +71,19 @@ def tearDown(self):
7171
forlfpinglob.glob(_tc_lock_fpaths):
7272
ifosp.isfile(lfp):
7373
raiseAssertionError("Previous TC left hanging git-lock file: {}".format(lfp))
74+
7475
importgc
7576

7677
gc.collect()
7778

7879
deftest_new_should_raise_on_invalid_repo_location(self):
79-
self.assertRaises(InvalidGitRepositoryError,Repo,tempfile.gettempdir())
80+
withtempfile.TemporaryDirectory()astdir:
81+
self.assertRaises(InvalidGitRepositoryError,Repo,tdir)
8082

8183
deftest_new_should_raise_on_non_existent_path(self):
82-
self.assertRaises(NoSuchPathError,Repo,"repos/foobar")
84+
withtempfile.TemporaryDirectory()astdir:
85+
nonexistent=osp.join(tdir,"foobar")
86+
self.assertRaises(NoSuchPathError,Repo,nonexistent)
8387

8488
@with_rw_repo("0.3.2.1")
8589
deftest_repo_creation_from_different_paths(self,rw_repo):

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp