add a rootdir param to py.path.local.mkdtemp

--HG--
branch : trunk
This commit is contained in:
Ronny Pfannschmidt 2010-06-03 11:14:32 +02:00
parent 2e82ca5fde
commit f8404be1b2
2 changed files with 8 additions and 2 deletions

View File

@ -628,12 +628,14 @@ class LocalPath(FSBase):
return py.path.local(py.std.tempfile.gettempdir())
get_temproot = classmethod(get_temproot)
def mkdtemp(cls):
def mkdtemp(cls, rootdir=None):
""" return a Path object pointing to a fresh new temporary directory
(which we created ourself).
"""
import tempfile
return cls(py.error.checked_call(tempfile.mkdtemp))
if rootdir is None:
rootdir = cls.get_temproot()
return cls(py.error.checked_call(tempfile.mkdtemp, dir=str(rootdir)))
mkdtemp = classmethod(mkdtemp)
def make_numbered_dir(cls, prefix='session-', rootdir=None, keep=3,

View File

@ -389,6 +389,10 @@ def test_samefile(tmpdir):
p = tmpdir.ensure("hello")
assert p.samefile(p)
def test_mkdtemp_rootdir(tmpdir):
dtmp = local.mkdtemp(rootdir=tmpdir)
assert tmpdir.listdir() == [dtmp]
class TestWINLocalPath:
pytestmark = win32only