Fix tests for basedir logging.

f5febc4 broke various tests which called standarddir.init() without a valid
basedir.
This commit is contained in:
Florian Bruhin 2015-11-29 00:23:39 +01:00
parent a67644589e
commit 6a46aea934
3 changed files with 12 additions and 7 deletions

View File

@ -190,6 +190,8 @@ def _maybe_create(path):
def init(args): def init(args):
"""Initialize all standard dirs.""" """Initialize all standard dirs."""
global _args global _args
if args is not None:
# args can be None during tests
log.init.debug("Base directory: {}".format(args.basedir)) log.init.debug("Base directory: {}".format(args.basedir))
_args = args _args = args
_init_cachedir_tag() _init_cachedir_tag()

View File

@ -315,7 +315,8 @@ class TestConfigInit:
def test_config_none(self, monkeypatch): def test_config_none(self, monkeypatch):
"""Test initializing with config path set to None.""" """Test initializing with config path set to None."""
args = types.SimpleNamespace(confdir='', datadir='', cachedir='') args = types.SimpleNamespace(confdir='', datadir='', cachedir='',
basedir='')
for k, v in self.env.items(): for k, v in self.env.items():
monkeypatch.setenv(k, v) monkeypatch.setenv(k, v)
standarddir.init(args) standarddir.init(args)

View File

@ -177,27 +177,28 @@ class TestArguments:
def test_confdir(self, testcase): def test_confdir(self, testcase):
"""Test --confdir.""" """Test --confdir."""
args = types.SimpleNamespace(confdir=testcase.arg, cachedir=None, args = types.SimpleNamespace(confdir=testcase.arg, cachedir=None,
datadir=None) datadir=None, basedir=None)
standarddir.init(args) standarddir.init(args)
assert standarddir.config() == testcase.expected assert standarddir.config() == testcase.expected
def test_cachedir(self, testcase): def test_cachedir(self, testcase):
"""Test --cachedir.""" """Test --cachedir."""
args = types.SimpleNamespace(confdir=None, cachedir=testcase.arg, args = types.SimpleNamespace(confdir=None, cachedir=testcase.arg,
datadir=None) datadir=None, basedir=None)
standarddir.init(args) standarddir.init(args)
assert standarddir.cache() == testcase.expected assert standarddir.cache() == testcase.expected
def test_datadir(self, testcase): def test_datadir(self, testcase):
"""Test --datadir.""" """Test --datadir."""
args = types.SimpleNamespace(confdir=None, cachedir=None, args = types.SimpleNamespace(confdir=None, cachedir=None,
datadir=testcase.arg) datadir=testcase.arg, basedir=None)
standarddir.init(args) standarddir.init(args)
assert standarddir.data() == testcase.expected assert standarddir.data() == testcase.expected
def test_confdir_none(self): def test_confdir_none(self):
"""Test --confdir with None given.""" """Test --confdir with None given."""
args = types.SimpleNamespace(confdir=None, cachedir=None, datadir=None) args = types.SimpleNamespace(confdir=None, cachedir=None, datadir=None,
basedir=None)
standarddir.init(args) standarddir.init(args)
assert standarddir.config().split(os.sep)[-1] == 'qute_test' assert standarddir.config().split(os.sep)[-1] == 'qute_test'
@ -206,7 +207,8 @@ class TestArguments:
monkeypatch.setattr( monkeypatch.setattr(
'qutebrowser.utils.standarddir.QStandardPaths.writableLocation', 'qutebrowser.utils.standarddir.QStandardPaths.writableLocation',
lambda _typ: str(tmpdir)) lambda _typ: str(tmpdir))
args = types.SimpleNamespace(confdir=None, cachedir=None, datadir=None) args = types.SimpleNamespace(confdir=None, cachedir=None, datadir=None,
basedir=None)
standarddir.init(args) standarddir.init(args)
assert standarddir.runtime() == str(tmpdir / 'qute_test') assert standarddir.runtime() == str(tmpdir / 'qute_test')