Skip to content

Commit

Permalink
Avoid unsafe assumptions about tempdir content in tests
Browse files Browse the repository at this point in the history
test_new_should_raise_on_invalid_repo_location had previously used
tempfile.gettempdir() directly to get a path assumed not to be a
valid repository, assuming more than necessary about the directory
in which temporary files and directories are created. A newly
created temporary directory is now used for that check, instead.

test_new_should_raise_on_non_existent_path had assumed no
repos/foobar existed relative to the current directory. Typically
there would be no such directory, but is unnecessary for the test
to rely on this. A newly created temporary directory known to be
empty is now used in place of the "repos" component, for that test.
  • Loading branch information
EliahKagan committed Dec 8, 2023
1 parent d7bf231 commit ad570de
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions test/test_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,19 @@ def tearDown(self):
for lfp in glob.glob(_tc_lock_fpaths):
if osp.isfile(lfp):
raise AssertionError("Previous TC left hanging git-lock file: {}".format(lfp))

import gc

gc.collect()

def test_new_should_raise_on_invalid_repo_location(self):
self.assertRaises(InvalidGitRepositoryError, Repo, tempfile.gettempdir())
with tempfile.TemporaryDirectory() as tdir:
self.assertRaises(InvalidGitRepositoryError, Repo, tdir)

def test_new_should_raise_on_non_existent_path(self):
self.assertRaises(NoSuchPathError, Repo, "repos/foobar")
with tempfile.TemporaryDirectory() as tdir:
nonexistent = osp.join(tdir, "foobar")
self.assertRaises(NoSuchPathError, Repo, nonexistent)

@with_rw_repo("0.3.2.1")
def test_repo_creation_from_different_paths(self, rw_repo):
Expand Down

0 comments on commit ad570de

Please sign in to comment.