Replace some uses of the deprecated mktemp function by EliahKagan · Pull Request #1770 · gitpython-developers/GitPython · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
16 changes: 6 additions & 10 deletions git/index/util.py
3 changes: 1 addition & 2 deletions test/lib/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,7 @@ def with_rw_directory(func):

@wraps(func)
def wrapper(self):
path = tempfile.mktemp(prefix=func.__name__)
os.mkdir(path)
path = tempfile.mkdtemp(prefix=func.__name__)
keep = False
try:
return func(self, path)
Expand Down
3 changes: 1 addition & 2 deletions test/performance/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ class TestBigRepoRW(TestBigRepoR):
def setUp(self):
self.gitrwrepo = None
super().setUp()
dirname = tempfile.mktemp()
os.mkdir(dirname)
dirname = tempfile.mkdtemp()
self.gitrwrepo = self.gitrorepo.clone(dirname, shared=True, bare=True, odbt=GitCmdObjectDB)
self.puregitrwrepo = Repo(dirname, odbt=GitDB)

Expand Down
5 changes: 2 additions & 3 deletions test/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,11 @@ def test_base_object(self):
data = data_stream.read()
assert data

tmpfilename = tempfile.mktemp(suffix="test-stream")
with open(tmpfilename, "wb+") as tmpfile:
with tempfile.NamedTemporaryFile(suffix="test-stream", delete=False) as tmpfile:
self.assertEqual(item, item.stream_data(tmpfile))
tmpfile.seek(0)
self.assertEqual(tmpfile.read(), data)
os.remove(tmpfilename)
os.remove(tmpfile.name) # Do it this way so we can inspect the file on failure.
# END for each object type to create

# Each has a unique sha.
Expand Down
7 changes: 2 additions & 5 deletions test/test_reflog.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
# This module is part of GitPython and is released under the
# 3-Clause BSD License: https://opensource.org/license/bsd-3-clause/

import os
import os.path as osp
import tempfile

from git.objects import IndexObject
from git.refs import RefLogEntry, RefLog
from test.lib import TestBase, fixture_path
from git.util import Actor, rmtree, hex_to_bin

import os.path as osp


class TestRefLog(TestBase):
def test_reflogentry(self):
Expand All @@ -35,8 +33,7 @@ def test_reflogentry(self):
def test_base(self):
rlp_head = fixture_path("reflog_HEAD")
rlp_master = fixture_path("reflog_master")
tdir = tempfile.mktemp(suffix="test_reflogs")
os.mkdir(tdir)
tdir = tempfile.mkdtemp(suffix="test_reflogs")

rlp_master_ro = RefLog.path(self.rorepo.head)
assert osp.isfile(rlp_master_ro)
Expand Down
5 changes: 2 additions & 3 deletions test/test_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -667,11 +667,10 @@ def test_tag_to_full_tag_path(self):
self.assertEqual(value_errors, [])

def test_archive(self):
tmpfile = tempfile.mktemp(suffix="archive-test")
with open(tmpfile, "wb") as stream:
with tempfile.NamedTemporaryFile("wb", suffix="archive-test", delete=False) as stream:
self.rorepo.archive(stream, "0.1.6", path="doc")
assert stream.tell()
os.remove(tmpfile)
os.remove(stream.name) # Do it this way so we can inspect the file on failure.

@mock.patch.object(Git, "_call_process")
def test_should_display_blame_information(self, git):
Expand Down
64 changes: 34 additions & 30 deletions test/test_util.py