Get rid of standarddir.temp() again.
This commit is contained in:
parent
3bdfa3001c
commit
04ec9c2624
@ -109,21 +109,6 @@ def runtime():
|
|||||||
return path
|
return path
|
||||||
|
|
||||||
|
|
||||||
def temp():
|
|
||||||
"""Get a location for temporary files."""
|
|
||||||
typ = QStandardPaths.TempLocation
|
|
||||||
path = _writable_location(typ)
|
|
||||||
# "The returned value might be application-specific, shared among
|
|
||||||
# other applications for this user, or even system-wide."
|
|
||||||
#
|
|
||||||
# Unfortunately this path could get too long for IPC sockets, so we
|
|
||||||
# don't add the username here...
|
|
||||||
appname = QCoreApplication.instance().applicationName()
|
|
||||||
path = os.path.join(path, appname)
|
|
||||||
_maybe_create(path)
|
|
||||||
return path
|
|
||||||
|
|
||||||
|
|
||||||
def _writable_location(typ):
|
def _writable_location(typ):
|
||||||
"""Wrapper around QStandardPaths.writableLocation."""
|
"""Wrapper around QStandardPaths.writableLocation."""
|
||||||
with qtutils.unset_organization():
|
with qtutils.unset_organization():
|
||||||
@ -166,6 +151,7 @@ def _from_args(typ, args):
|
|||||||
|
|
||||||
if getattr(args, 'basedir', None) is not None:
|
if getattr(args, 'basedir', None) is not None:
|
||||||
basedir = args.basedir
|
basedir = args.basedir
|
||||||
|
|
||||||
try:
|
try:
|
||||||
suffix = basedir_suffix[typ]
|
suffix = basedir_suffix[typ]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
|
@ -121,11 +121,6 @@ class TestGetStandardDirLinux:
|
|||||||
monkeypatch.setenv('XDG_CACHE_HOME', str(tmpdir))
|
monkeypatch.setenv('XDG_CACHE_HOME', str(tmpdir))
|
||||||
assert standarddir.cache() == str(tmpdir / 'qute_test')
|
assert standarddir.cache() == str(tmpdir / 'qute_test')
|
||||||
|
|
||||||
def test_temp_explicit(self, monkeypatch, tmpdir):
|
|
||||||
"""Test temp dir with TMPDIR explicitly set."""
|
|
||||||
monkeypatch.setenv('TMPDIR', str(tmpdir))
|
|
||||||
assert standarddir.temp() == str(tmpdir / 'qute_test')
|
|
||||||
|
|
||||||
def test_data(self, monkeypatch, tmpdir):
|
def test_data(self, monkeypatch, tmpdir):
|
||||||
"""Test data dir with XDG_DATA_HOME not set."""
|
"""Test data dir with XDG_DATA_HOME not set."""
|
||||||
monkeypatch.setenv('HOME', str(tmpdir))
|
monkeypatch.setenv('HOME', str(tmpdir))
|
||||||
@ -147,11 +142,6 @@ class TestGetStandardDirLinux:
|
|||||||
expected = tmpdir / '.cache' / 'qute_test'
|
expected = tmpdir / '.cache' / 'qute_test'
|
||||||
assert standarddir.cache() == expected
|
assert standarddir.cache() == expected
|
||||||
|
|
||||||
def test_temp(self, monkeypatch, tmpdir):
|
|
||||||
"""Test temp dir with TMPDIR not set."""
|
|
||||||
monkeypatch.delenv('TMPDIR', raising=False)
|
|
||||||
assert standarddir.temp().split(os.sep)[-1] == 'qute_test'
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.windows
|
@pytest.mark.windows
|
||||||
@pytest.mark.usefixtures('no_cachedir_tag')
|
@pytest.mark.usefixtures('no_cachedir_tag')
|
||||||
@ -173,9 +163,6 @@ class TestGetStandardDirWindows:
|
|||||||
expected = ['qute_test', 'cache']
|
expected = ['qute_test', 'cache']
|
||||||
assert standarddir.cache().split(os.sep)[-2:] == expected
|
assert standarddir.cache().split(os.sep)[-2:] == expected
|
||||||
|
|
||||||
def test_temp(self):
|
|
||||||
assert standarddir.temp().split(os.sep)[-1] == 'qute_test'
|
|
||||||
|
|
||||||
|
|
||||||
DirArgTest = collections.namedtuple('DirArgTest', 'arg, expected')
|
DirArgTest = collections.namedtuple('DirArgTest', 'arg, expected')
|
||||||
|
|
||||||
@ -241,13 +228,6 @@ class TestArguments:
|
|||||||
func = getattr(standarddir, typ)
|
func = getattr(standarddir, typ)
|
||||||
assert func() == expected
|
assert func() == expected
|
||||||
|
|
||||||
def test_basedir_temp(self, tmpdir):
|
|
||||||
"""Make sure the temp file location is not influenced by basedir."""
|
|
||||||
args = types.SimpleNamespace(basedir=str(tmpdir))
|
|
||||||
standarddir.init(args)
|
|
||||||
qute_tempdir = standarddir.temp()
|
|
||||||
assert not qute_tempdir.startswith(str(tmpdir))
|
|
||||||
|
|
||||||
|
|
||||||
class TestInitCacheDirTag:
|
class TestInitCacheDirTag:
|
||||||
|
|
||||||
@ -302,7 +282,7 @@ class TestCreatingDir:
|
|||||||
|
|
||||||
"""Make sure inexistant directories are created properly."""
|
"""Make sure inexistant directories are created properly."""
|
||||||
|
|
||||||
DIR_TYPES = ['config', 'data', 'cache', 'download', 'runtime', 'temp']
|
DIR_TYPES = ['config', 'data', 'cache', 'download', 'runtime']
|
||||||
|
|
||||||
@pytest.mark.parametrize('typ', DIR_TYPES)
|
@pytest.mark.parametrize('typ', DIR_TYPES)
|
||||||
def test_basedir(self, tmpdir, typ):
|
def test_basedir(self, tmpdir, typ):
|
||||||
|
Loading…
Reference in New Issue
Block a user