2014-10-08 06:19:45 +02:00
|
|
|
# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et:
|
|
|
|
|
2015-01-03 15:51:31 +01:00
|
|
|
# Copyright 2014-2015 Florian Bruhin (The Compiler) <mail@qutebrowser.org>
|
2014-10-08 06:19:45 +02:00
|
|
|
#
|
|
|
|
# This file is part of qutebrowser.
|
|
|
|
#
|
|
|
|
# qutebrowser is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# qutebrowser is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with qutebrowser. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
"""Tests for qutebrowser.utils.standarddir."""
|
|
|
|
|
|
|
|
import os
|
|
|
|
import os.path
|
|
|
|
import sys
|
|
|
|
|
2015-04-03 00:05:20 +02:00
|
|
|
from PyQt5.QtWidgets import QApplication
|
2015-04-03 00:45:52 +02:00
|
|
|
import pytest
|
2015-04-03 00:05:20 +02:00
|
|
|
|
2014-10-08 06:19:45 +02:00
|
|
|
from qutebrowser.utils import standarddir
|
|
|
|
|
|
|
|
|
2015-04-03 00:45:52 +02:00
|
|
|
@pytest.yield_fixture(autouse=True)
|
|
|
|
def change_qapp_name():
|
|
|
|
"""
|
|
|
|
Change the name of the QApplication instance for all tests in this module
|
|
|
|
to "qutebrowser_test".
|
2014-10-08 06:19:45 +02:00
|
|
|
"""
|
2015-04-03 00:45:52 +02:00
|
|
|
old_name = QApplication.instance().applicationName()
|
|
|
|
QApplication.instance().setApplicationName('qutebrowser_test')
|
|
|
|
yield
|
|
|
|
QApplication.instance().setApplicationName(old_name)
|
2014-10-08 06:19:45 +02:00
|
|
|
|
|
|
|
|
2015-04-03 00:45:52 +02:00
|
|
|
@pytest.mark.skipif(not sys.platform.startswith("linux"),
|
|
|
|
reason="requires Linux")
|
2015-04-04 17:05:44 +02:00
|
|
|
class TestGetStandardDirLinux:
|
2015-04-03 00:45:52 +02:00
|
|
|
"""Tests for standarddir under Linux.
|
|
|
|
"""
|
|
|
|
|
|
|
|
def test_data_explicit(self, monkeypatch, tmpdir):
|
2014-10-08 06:19:45 +02:00
|
|
|
"""Test data dir with XDG_DATA_HOME explicitely set."""
|
2015-04-03 00:45:52 +02:00
|
|
|
monkeypatch.setenv('XDG_DATA_HOME', str(tmpdir))
|
|
|
|
standarddir.init(None)
|
|
|
|
assert standarddir.data() == str(tmpdir / 'qutebrowser')
|
2014-10-08 06:19:45 +02:00
|
|
|
|
2015-04-03 00:45:52 +02:00
|
|
|
def test_config_explicit(self, monkeypatch, tmpdir):
|
2014-10-08 06:19:45 +02:00
|
|
|
"""Test config dir with XDG_CONFIG_HOME explicitely set."""
|
2015-04-03 00:45:52 +02:00
|
|
|
monkeypatch.setenv('XDG_CONFIG_HOME', str(tmpdir))
|
|
|
|
standarddir.init(None)
|
|
|
|
assert standarddir.config() == str(tmpdir / 'qutebrowser')
|
2014-10-08 06:19:45 +02:00
|
|
|
|
2015-04-03 00:45:52 +02:00
|
|
|
def test_cache_explicit(self, monkeypatch, tmpdir):
|
2014-10-08 06:19:45 +02:00
|
|
|
"""Test cache dir with XDG_CACHE_HOME explicitely set."""
|
2015-04-03 00:45:52 +02:00
|
|
|
monkeypatch.setenv('XDG_CACHE_HOME', str(tmpdir))
|
|
|
|
standarddir.init(None)
|
|
|
|
assert standarddir.cache() == str(tmpdir / 'qutebrowser')
|
2014-10-08 06:19:45 +02:00
|
|
|
|
2015-04-03 00:45:52 +02:00
|
|
|
def test_data(self, monkeypatch, tmpdir):
|
2014-10-08 06:19:45 +02:00
|
|
|
"""Test data dir with XDG_DATA_HOME not set."""
|
2015-04-03 00:45:52 +02:00
|
|
|
monkeypatch.setenv('HOME', str(tmpdir))
|
|
|
|
monkeypatch.setenv('XDG_DATA_HOME', None)
|
|
|
|
standarddir.init(None)
|
|
|
|
expected = tmpdir / '.local' / 'share' / 'qutebrowser'
|
|
|
|
assert standarddir.data() == str(expected)
|
|
|
|
|
|
|
|
def test_config(self, monkeypatch, tmpdir):
|
2014-10-08 06:19:45 +02:00
|
|
|
"""Test config dir with XDG_CONFIG_HOME not set."""
|
2015-04-03 00:45:52 +02:00
|
|
|
monkeypatch.setenv('HOME', str(tmpdir))
|
|
|
|
monkeypatch.setenv('XDG_CONFIG_HOME', None)
|
|
|
|
standarddir.init(None)
|
|
|
|
expected = tmpdir / '.config' / 'qutebrowser'
|
|
|
|
assert standarddir.config() == str(expected)
|
2014-10-08 06:19:45 +02:00
|
|
|
|
2015-04-03 00:45:52 +02:00
|
|
|
def test_cache(self, monkeypatch, tmpdir):
|
2014-10-08 06:19:45 +02:00
|
|
|
"""Test cache dir with XDG_CACHE_HOME not set."""
|
2015-04-03 00:45:52 +02:00
|
|
|
monkeypatch.setenv('HOME', str(tmpdir))
|
|
|
|
monkeypatch.setenv('XDG_CACHE_HOME', None)
|
|
|
|
standarddir.init(None)
|
|
|
|
expected = tmpdir / '.cache' / 'qutebrowser'
|
|
|
|
assert standarddir.cache() == expected
|
2014-10-08 06:19:45 +02:00
|
|
|
|
|
|
|
|
2015-04-03 00:45:52 +02:00
|
|
|
@pytest.mark.skipif(not sys.platform.startswith("win"),
|
|
|
|
reason="requires Windows")
|
2015-04-04 17:05:44 +02:00
|
|
|
class TestGetStandardDirWindows:
|
2015-02-26 07:01:22 +01:00
|
|
|
"""Tests for standarddir under Windows.
|
2014-10-08 06:19:45 +02:00
|
|
|
"""
|
|
|
|
|
2015-04-03 00:45:52 +02:00
|
|
|
@pytest.fixture(autouse=True)
|
|
|
|
def reset_standarddir(self):
|
2015-02-22 19:13:51 +01:00
|
|
|
standarddir.init(None)
|
2015-02-20 09:21:59 +01:00
|
|
|
|
2014-10-08 06:19:45 +02:00
|
|
|
def test_data(self):
|
|
|
|
"""Test data dir."""
|
2015-04-03 00:45:52 +02:00
|
|
|
expected = ['qutebrowser_test', 'data']
|
|
|
|
assert standarddir.data().split(os.sep)[-2:] == expected
|
2014-10-08 06:19:45 +02:00
|
|
|
|
|
|
|
def test_config(self):
|
|
|
|
"""Test config dir."""
|
2015-04-03 00:45:52 +02:00
|
|
|
assert standarddir.config().split(os.sep)[-1] == 'qutebrowser_test'
|
2014-10-08 06:19:45 +02:00
|
|
|
|
|
|
|
def test_cache(self):
|
|
|
|
"""Test cache dir."""
|
2015-04-03 00:45:52 +02:00
|
|
|
expected = ['qutebrowser_test', 'cache']
|
|
|
|
assert standarddir.cache().split(os.sep)[-2:] == expected
|