Merge branch 'master' of ssh://tonks/qutebrowser
This commit is contained in:
commit
ea2dba6b38
3
.flake8
3
.flake8
@ -7,5 +7,6 @@
|
|||||||
# F401: Unused import
|
# F401: Unused import
|
||||||
# E402: module level import not at top of file
|
# E402: module level import not at top of file
|
||||||
# E266: too many leading '#' for block comment
|
# E266: too many leading '#' for block comment
|
||||||
ignore=E265,E501,F841,F401,E402,E266
|
# W503: line break before binary operator
|
||||||
|
ignore=E265,E501,F841,F401,E402,E266,W503
|
||||||
max_complexity = 12
|
max_complexity = 12
|
||||||
|
@ -146,6 +146,7 @@ Contributors, sorted by the number of commits in descending order:
|
|||||||
* Larry Hynes
|
* Larry Hynes
|
||||||
* Thorsten Wißmann
|
* Thorsten Wißmann
|
||||||
* Thiago Barroso Perrotta
|
* Thiago Barroso Perrotta
|
||||||
|
* Samir Benmendil
|
||||||
* Matthias Lisin
|
* Matthias Lisin
|
||||||
* Helen Sherwood-Taylor
|
* Helen Sherwood-Taylor
|
||||||
* HalosGhost
|
* HalosGhost
|
||||||
|
@ -34,7 +34,7 @@
|
|||||||
|<<ui-display-statusbar-messages,display-statusbar-messages>>|Whether to display javascript statusbar messages.
|
|<<ui-display-statusbar-messages,display-statusbar-messages>>|Whether to display javascript statusbar messages.
|
||||||
|<<ui-zoom-text-only,zoom-text-only>>|Whether the zoom factor on a frame applies only to the text or to all content.
|
|<<ui-zoom-text-only,zoom-text-only>>|Whether the zoom factor on a frame applies only to the text or to all content.
|
||||||
|<<ui-frame-flattening,frame-flattening>>|Whether to expand each subframe to its contents.
|
|<<ui-frame-flattening,frame-flattening>>|Whether to expand each subframe to its contents.
|
||||||
|<<ui-user-stylesheet,user-stylesheet>>|User stylesheet to use (absolute filename or CSS string).
|
|<<ui-user-stylesheet,user-stylesheet>>|User stylesheet to use (absolute filename or CSS string). Will expand environment variables.
|
||||||
|<<ui-css-media-type,css-media-type>>|Set the CSS media type.
|
|<<ui-css-media-type,css-media-type>>|Set the CSS media type.
|
||||||
|<<ui-remove-finished-downloads,remove-finished-downloads>>|Whether to remove finished downloads automatically.
|
|<<ui-remove-finished-downloads,remove-finished-downloads>>|Whether to remove finished downloads automatically.
|
||||||
|<<ui-hide-statusbar,hide-statusbar>>|Whether to hide the statusbar unless a message is shown.
|
|<<ui-hide-statusbar,hide-statusbar>>|Whether to hide the statusbar unless a message is shown.
|
||||||
@ -105,7 +105,7 @@
|
|||||||
[options="header",width="75%",cols="25%,75%"]
|
[options="header",width="75%",cols="25%,75%"]
|
||||||
|==============
|
|==============
|
||||||
|Setting|Description
|
|Setting|Description
|
||||||
|<<storage-download-directory,download-directory>>|The directory to save downloads to. An empty value selects a sensible os-specific default.
|
|<<storage-download-directory,download-directory>>|The directory to save downloads to. An empty value selects a sensible os-specific default. Will expand environment variables.
|
||||||
|<<storage-maximum-pages-in-cache,maximum-pages-in-cache>>|The maximum number of pages to hold in the memory page cache.
|
|<<storage-maximum-pages-in-cache,maximum-pages-in-cache>>|The maximum number of pages to hold in the memory page cache.
|
||||||
|<<storage-object-cache-capacities,object-cache-capacities>>|The capacities for the memory cache for dead objects such as stylesheets or scripts. Syntax: cacheMinDeadCapacity, cacheMaxDead, totalCapacity.
|
|<<storage-object-cache-capacities,object-cache-capacities>>|The capacities for the memory cache for dead objects such as stylesheets or scripts. Syntax: cacheMinDeadCapacity, cacheMaxDead, totalCapacity.
|
||||||
|<<storage-offline-storage-default-quota,offline-storage-default-quota>>|Default quota for new offline storage databases.
|
|<<storage-offline-storage-default-quota,offline-storage-default-quota>>|Default quota for new offline storage databases.
|
||||||
@ -471,7 +471,7 @@ Default: +pass:[false]+
|
|||||||
|
|
||||||
[[ui-user-stylesheet]]
|
[[ui-user-stylesheet]]
|
||||||
=== user-stylesheet
|
=== user-stylesheet
|
||||||
User stylesheet to use (absolute filename or CSS string).
|
User stylesheet to use (absolute filename or CSS string). Will expand environment variables.
|
||||||
|
|
||||||
Default: +pass:[::-webkit-scrollbar { width: 0px; height: 0px; }]+
|
Default: +pass:[::-webkit-scrollbar { width: 0px; height: 0px; }]+
|
||||||
|
|
||||||
@ -907,7 +907,7 @@ Settings related to cache and storage.
|
|||||||
|
|
||||||
[[storage-download-directory]]
|
[[storage-download-directory]]
|
||||||
=== download-directory
|
=== download-directory
|
||||||
The directory to save downloads to. An empty value selects a sensible os-specific default.
|
The directory to save downloads to. An empty value selects a sensible os-specific default. Will expand environment variables.
|
||||||
|
|
||||||
Default: empty
|
Default: empty
|
||||||
|
|
||||||
|
@ -51,6 +51,10 @@ FIRST_COMMENT = r"""
|
|||||||
# Interpolation looks like ${value} or ${section:value} and will be
|
# Interpolation looks like ${value} or ${section:value} and will be
|
||||||
# replaced by the respective value.
|
# replaced by the respective value.
|
||||||
#
|
#
|
||||||
|
# Some settings will expand environment variables. Note that, since
|
||||||
|
# interpolation is run first, you will need to escape the $ char as
|
||||||
|
# described below.
|
||||||
|
#
|
||||||
# This is the default config, so if you want to remove anything from
|
# This is the default config, so if you want to remove anything from
|
||||||
# here (as opposed to change/add), for example a keybinding, set it to
|
# here (as opposed to change/add), for example a keybinding, set it to
|
||||||
# an empty value.
|
# an empty value.
|
||||||
@ -235,7 +239,8 @@ DATA = collections.OrderedDict([
|
|||||||
('user-stylesheet',
|
('user-stylesheet',
|
||||||
SettingValue(typ.UserStyleSheet(),
|
SettingValue(typ.UserStyleSheet(),
|
||||||
'::-webkit-scrollbar { width: 0px; height: 0px; }'),
|
'::-webkit-scrollbar { width: 0px; height: 0px; }'),
|
||||||
"User stylesheet to use (absolute filename or CSS string)."),
|
"User stylesheet to use (absolute filename or CSS string). Will "
|
||||||
|
"expand environment variables."),
|
||||||
|
|
||||||
('css-media-type',
|
('css-media-type',
|
||||||
SettingValue(typ.String(none_ok=True), ''),
|
SettingValue(typ.String(none_ok=True), ''),
|
||||||
@ -444,7 +449,7 @@ DATA = collections.OrderedDict([
|
|||||||
('download-directory',
|
('download-directory',
|
||||||
SettingValue(typ.Directory(none_ok=True), ''),
|
SettingValue(typ.Directory(none_ok=True), ''),
|
||||||
"The directory to save downloads to. An empty value selects a "
|
"The directory to save downloads to. An empty value selects a "
|
||||||
"sensible os-specific default."),
|
"sensible os-specific default. Will expand environment variables."),
|
||||||
|
|
||||||
('maximum-pages-in-cache',
|
('maximum-pages-in-cache',
|
||||||
SettingValue(
|
SettingValue(
|
||||||
|
@ -837,6 +837,7 @@ class Directory(BaseType):
|
|||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
raise configexc.ValidationError(value, "may not be empty!")
|
raise configexc.ValidationError(value, "may not be empty!")
|
||||||
|
value = os.path.expandvars(value)
|
||||||
value = os.path.expanduser(value)
|
value = os.path.expanduser(value)
|
||||||
if not os.path.isdir(value):
|
if not os.path.isdir(value):
|
||||||
raise configexc.ValidationError(value, "must be a valid "
|
raise configexc.ValidationError(value, "must be a valid "
|
||||||
@ -847,6 +848,7 @@ class Directory(BaseType):
|
|||||||
def transform(self, value):
|
def transform(self, value):
|
||||||
if not value:
|
if not value:
|
||||||
return None
|
return None
|
||||||
|
value = os.path.expandvars(value)
|
||||||
return os.path.expanduser(value)
|
return os.path.expanduser(value)
|
||||||
|
|
||||||
|
|
||||||
@ -1132,6 +1134,7 @@ class UserStyleSheet(File):
|
|||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
raise configexc.ValidationError(value, "may not be empty!")
|
raise configexc.ValidationError(value, "may not be empty!")
|
||||||
|
value = os.path.expandvars(value)
|
||||||
value = os.path.expanduser(value)
|
value = os.path.expanduser(value)
|
||||||
if not os.path.isabs(value):
|
if not os.path.isabs(value):
|
||||||
# probably a CSS, so we don't handle it as filename.
|
# probably a CSS, so we don't handle it as filename.
|
||||||
@ -1147,7 +1150,8 @@ class UserStyleSheet(File):
|
|||||||
raise configexc.ValidationError(value, "must be a valid file!")
|
raise configexc.ValidationError(value, "must be a valid file!")
|
||||||
|
|
||||||
def transform(self, value):
|
def transform(self, value):
|
||||||
path = os.path.expanduser(value)
|
path = os.path.expandvars(value)
|
||||||
|
path = os.path.expanduser(path)
|
||||||
if not value:
|
if not value:
|
||||||
return None
|
return None
|
||||||
elif os.path.isabs(path):
|
elif os.path.isabs(path):
|
||||||
|
@ -26,7 +26,7 @@ import base64
|
|||||||
from unittest import mock
|
from unittest import mock
|
||||||
|
|
||||||
from qutebrowser.config import configtypes, configexc
|
from qutebrowser.config import configtypes, configexc
|
||||||
from qutebrowser.test import stubs
|
from qutebrowser.test import stubs, helpers
|
||||||
from qutebrowser.utils import debug, utils
|
from qutebrowser.utils import debug, utils
|
||||||
|
|
||||||
from PyQt5.QtCore import QUrl
|
from PyQt5.QtCore import QUrl
|
||||||
@ -1377,14 +1377,27 @@ class DirectoryTests(unittest.TestCase):
|
|||||||
|
|
||||||
def test_validate_expanduser(self, os_path):
|
def test_validate_expanduser(self, os_path):
|
||||||
"""Test if validate expands the user correctly."""
|
"""Test if validate expands the user correctly."""
|
||||||
|
os_path.expandvars.side_effect = lambda x: x
|
||||||
os_path.expanduser.side_effect = lambda x: x.replace('~', '/home/foo')
|
os_path.expanduser.side_effect = lambda x: x.replace('~', '/home/foo')
|
||||||
os_path.isdir.side_effect = lambda path: path == '/home/foo/foobar'
|
os_path.isdir.side_effect = lambda path: path == '/home/foo/foobar'
|
||||||
os_path.isabs.return_value = True
|
os_path.isabs.return_value = True
|
||||||
self.t.validate('~/foobar')
|
self.t.validate('~/foobar')
|
||||||
os_path.expanduser.assert_called_once_with('~/foobar')
|
os_path.expanduser.assert_called_once_with('~/foobar')
|
||||||
|
|
||||||
|
def test_validate_expandvars(self, os_path):
|
||||||
|
"""Test if validate expands the user correctly."""
|
||||||
|
os_path.expandvars.side_effect = lambda x: x.replace('$BAR',
|
||||||
|
'/home/foo/bar')
|
||||||
|
os_path.expanduser.side_effect = lambda x: x
|
||||||
|
os_path.isdir.side_effect = lambda path: path == '/home/foo/bar/foobar'
|
||||||
|
os_path.isabs.return_value = True
|
||||||
|
with helpers.environ_set_temp('bar', '/home/foo/bar'):
|
||||||
|
self.t.validate('$BAR/foobar')
|
||||||
|
os_path.expandvars.assert_called_once_with('$BAR/foobar')
|
||||||
|
|
||||||
def test_transform(self, os_path):
|
def test_transform(self, os_path):
|
||||||
"""Test transform."""
|
"""Test transform."""
|
||||||
|
os_path.expandvars.side_effect = lambda x: x
|
||||||
os_path.expanduser.side_effect = lambda x: x.replace('~', '/home/foo')
|
os_path.expanduser.side_effect = lambda x: x.replace('~', '/home/foo')
|
||||||
self.assertEqual(self.t.transform('~/foobar'), '/home/foo/foobar')
|
self.assertEqual(self.t.transform('~/foobar'), '/home/foo/foobar')
|
||||||
os_path.expanduser.assert_called_once_with('~/foobar')
|
os_path.expanduser.assert_called_once_with('~/foobar')
|
||||||
@ -1780,6 +1793,12 @@ class UserStyleSheetTests(unittest.TestCase):
|
|||||||
path = os.path.join(os.path.sep, 'foo', 'bar')
|
path = os.path.join(os.path.sep, 'foo', 'bar')
|
||||||
self.assertEqual(self.t.transform(path), QUrl("file:///foo/bar"))
|
self.assertEqual(self.t.transform(path), QUrl("file:///foo/bar"))
|
||||||
|
|
||||||
|
def test_transform_file_expandvars(self):
|
||||||
|
"""Test transform with a filename (expandvars)."""
|
||||||
|
with helpers.environ_set_temp('FOO', 'foo'):
|
||||||
|
path = os.path.join(os.path.sep, '$FOO', 'bar')
|
||||||
|
self.assertEqual(self.t.transform(path), QUrl("file:///foo/bar"))
|
||||||
|
|
||||||
def test_transform_base64(self):
|
def test_transform_base64(self):
|
||||||
"""Test transform with a data string."""
|
"""Test transform with a data string."""
|
||||||
b64 = base64.b64encode(b"test").decode('ascii')
|
b64 = base64.b64encode(b"test").decode('ascii')
|
||||||
|
@ -33,11 +33,20 @@ def environ_set_temp(name, value):
|
|||||||
oldval = os.environ[name]
|
oldval = os.environ[name]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
oldval = None
|
oldval = None
|
||||||
|
|
||||||
|
if value is not None:
|
||||||
os.environ[name] = value
|
os.environ[name] = value
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
del os.environ[name]
|
||||||
|
except KeyError:
|
||||||
|
pass
|
||||||
|
|
||||||
yield
|
yield
|
||||||
|
|
||||||
if oldval is not None:
|
if oldval is not None:
|
||||||
os.environ[name] = oldval
|
os.environ[name] = oldval
|
||||||
else:
|
elif value is not None:
|
||||||
del os.environ[name]
|
del os.environ[name]
|
||||||
|
|
||||||
|
|
||||||
|
@ -43,6 +43,19 @@ class TestEnvironSetTemp(unittest.TestCase):
|
|||||||
self.assertEqual(os.environ['QUTEBROWSER_ENVIRON_TEST'], 'newval')
|
self.assertEqual(os.environ['QUTEBROWSER_ENVIRON_TEST'], 'newval')
|
||||||
self.assertNotIn('QUTEBROWSER_ENVIRON_TEST', os.environ)
|
self.assertNotIn('QUTEBROWSER_ENVIRON_TEST', os.environ)
|
||||||
|
|
||||||
|
def test_environ_none_set(self):
|
||||||
|
"""Test environ_set_temp with something which was set already."""
|
||||||
|
os.environ['QUTEBROWSER_ENVIRON_TEST'] = 'oldval'
|
||||||
|
with helpers.environ_set_temp('QUTEBROWSER_ENVIRON_TEST', None):
|
||||||
|
self.assertNotIn('QUTEBROWSER_ENVIRON_TEST', os.environ)
|
||||||
|
self.assertEqual(os.environ['QUTEBROWSER_ENVIRON_TEST'], 'oldval')
|
||||||
|
|
||||||
|
def test_environ_none_unset(self):
|
||||||
|
"""Test environ_set_temp with something which wasn't set yet."""
|
||||||
|
with helpers.environ_set_temp('QUTEBROWSER_ENVIRON_TEST', None):
|
||||||
|
self.assertNotIn('QUTEBROWSER_ENVIRON_TEST', os.environ)
|
||||||
|
self.assertNotIn('QUTEBROWSER_ENVIRON_TEST', os.environ)
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
if 'QUTEBROWSER_ENVIRON_TEST' in os.environ:
|
if 'QUTEBROWSER_ENVIRON_TEST' in os.environ:
|
||||||
# if some test failed
|
# if some test failed
|
||||||
|
@ -73,7 +73,8 @@ class GetStandardDirLinuxTests(unittest.TestCase):
|
|||||||
@unittest.skipUnless(sys.platform.startswith("linux"), "requires Linux")
|
@unittest.skipUnless(sys.platform.startswith("linux"), "requires Linux")
|
||||||
def test_data(self):
|
def test_data(self):
|
||||||
"""Test data dir with XDG_DATA_HOME not set."""
|
"""Test data dir with XDG_DATA_HOME not set."""
|
||||||
with helpers.environ_set_temp('HOME', self.temp_dir):
|
with helpers.environ_set_temp('HOME', self.temp_dir), \
|
||||||
|
helpers.environ_set_temp('XDG_DATA_HOME', None):
|
||||||
cur_dir = standarddir.get(QStandardPaths.DataLocation)
|
cur_dir = standarddir.get(QStandardPaths.DataLocation)
|
||||||
self.assertEqual(cur_dir, os.path.join(self.temp_dir, '.local',
|
self.assertEqual(cur_dir, os.path.join(self.temp_dir, '.local',
|
||||||
'share', 'qutebrowser'))
|
'share', 'qutebrowser'))
|
||||||
@ -81,7 +82,8 @@ class GetStandardDirLinuxTests(unittest.TestCase):
|
|||||||
@unittest.skipUnless(sys.platform.startswith("linux"), "requires Linux")
|
@unittest.skipUnless(sys.platform.startswith("linux"), "requires Linux")
|
||||||
def test_config(self):
|
def test_config(self):
|
||||||
"""Test config dir with XDG_CONFIG_HOME not set."""
|
"""Test config dir with XDG_CONFIG_HOME not set."""
|
||||||
with helpers.environ_set_temp('HOME', self.temp_dir):
|
with helpers.environ_set_temp('HOME', self.temp_dir), \
|
||||||
|
helpers.environ_set_temp('XDG_CONFIG_HOME', None):
|
||||||
cur_dir = standarddir.get(
|
cur_dir = standarddir.get(
|
||||||
QStandardPaths.ConfigLocation)
|
QStandardPaths.ConfigLocation)
|
||||||
self.assertEqual(cur_dir, os.path.join(self.temp_dir, '.config',
|
self.assertEqual(cur_dir, os.path.join(self.temp_dir, '.config',
|
||||||
@ -90,7 +92,8 @@ class GetStandardDirLinuxTests(unittest.TestCase):
|
|||||||
@unittest.skipUnless(sys.platform.startswith("linux"), "requires Linux")
|
@unittest.skipUnless(sys.platform.startswith("linux"), "requires Linux")
|
||||||
def test_cache(self):
|
def test_cache(self):
|
||||||
"""Test cache dir with XDG_CACHE_HOME not set."""
|
"""Test cache dir with XDG_CACHE_HOME not set."""
|
||||||
with helpers.environ_set_temp('HOME', self.temp_dir):
|
with helpers.environ_set_temp('HOME', self.temp_dir), \
|
||||||
|
helpers.environ_set_temp('XDG_CACHE_HOME', None):
|
||||||
cur_dir = standarddir.get(QStandardPaths.CacheLocation)
|
cur_dir = standarddir.get(QStandardPaths.CacheLocation)
|
||||||
self.assertEqual(cur_dir, os.path.join(self.temp_dir, '.cache',
|
self.assertEqual(cur_dir, os.path.join(self.temp_dir, '.cache',
|
||||||
'qutebrowser'))
|
'qutebrowser'))
|
||||||
|
Loading…
Reference in New Issue
Block a user