Merge pull request #1770 from EliahKagan/less-mktemp · gitpython-developers/GitPython@f55d194 · GitHub
Skip to content

Commit f55d194

Browse files
authored
Merge pull request #1770 from EliahKagan/less-mktemp
Replace some uses of the deprecated mktemp function
2 parents 98580e4 + 9e86053 commit f55d194

7 files changed

Lines changed: 48 additions & 55 deletions

File tree

git/index/util.py

Lines changed: 6 additions & 10 deletions

test/lib/helper.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,7 @@ def with_rw_directory(func):
8989

9090
@wraps(func)
9191
def wrapper(self):
92-
path = tempfile.mktemp(prefix=func.__name__)
93-
os.mkdir(path)
92+
path = tempfile.mkdtemp(prefix=func.__name__)
9493
keep = False
9594
try:
9695
return func(self, path)

test/performance/lib.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,7 @@ class TestBigRepoRW(TestBigRepoR):
6565
def setUp(self):
6666
self.gitrwrepo = None
6767
super().setUp()
68-
dirname = tempfile.mktemp()
69-
os.mkdir(dirname)
68+
dirname = tempfile.mkdtemp()
7069
self.gitrwrepo = self.gitrorepo.clone(dirname, shared=True, bare=True, odbt=GitCmdObjectDB)
7170
self.puregitrwrepo = Repo(dirname, odbt=GitDB)
7271

test/test_base.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,11 @@ def test_base_object(self):
6868
data = data_stream.read()
6969
assert data
7070

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

7978
# Each has a unique sha.

test/test_reflog.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
# This module is part of GitPython and is released under the
22
# 3-Clause BSD License: https://opensource.org/license/bsd-3-clause/
33

4-
import os
4+
import os.path as osp
55
import tempfile
66

77
from git.objects import IndexObject
88
from git.refs import RefLogEntry, RefLog
99
from test.lib import TestBase, fixture_path
1010
from git.util import Actor, rmtree, hex_to_bin
1111

12-
import os.path as osp
13-
1412

1513
class TestRefLog(TestBase):
1614
def test_reflogentry(self):
@@ -35,8 +33,7 @@ def test_reflogentry(self):
3533
def test_base(self):
3634
rlp_head = fixture_path("reflog_HEAD")
3735
rlp_master = fixture_path("reflog_master")
38-
tdir = tempfile.mktemp(suffix="test_reflogs")
39-
os.mkdir(tdir)
36+
tdir = tempfile.mkdtemp(suffix="test_reflogs")
4037

4138
rlp_master_ro = RefLog.path(self.rorepo.head)
4239
assert osp.isfile(rlp_master_ro)

test/test_repo.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -667,11 +667,10 @@ def test_tag_to_full_tag_path(self):
667667
self.assertEqual(value_errors, [])
668668

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

676675
@mock.patch.object(Git, "_call_process")
677676
def test_should_display_blame_information(self, git):

test/test_util.py

Lines changed: 34 additions & 30 deletions

0 commit comments

Comments
 (0)