summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Bruhin <me@the-compiler.org>2019-12-20 13:50:54 +0100
committerFlorian Bruhin <me@the-compiler.org>2019-12-20 16:54:08 +0100
commit20ee9e2d09b8a3d275080000b11fd5566afd525c (patch)
treef4b81d8ae09e07de0d2249ab6c87a21f6916bb1f
parentb20eba35e91735ca954af72f5d5ae7d407b7bbf2 (diff)
downloadqutebrowser-20ee9e2d09b8a3d275080000b11fd5566afd525c.tar.gz
qutebrowser-20ee9e2d09b8a3d275080000b11fd5566afd525c.zip
Replace configutils.UNSET by usertypes.UNSET
No need for two different UNSET types. Also, this avoids a circular import: configutils -> urlutils -> config -> configdata -> configtypes -> configutils
-rw-r--r--qutebrowser/config/config.py4
-rw-r--r--qutebrowser/config/configtypes.py108
-rw-r--r--qutebrowser/config/configutils.py25
-rw-r--r--qutebrowser/config/websettings.py12
-rw-r--r--qutebrowser/utils/usertypes.py11
-rw-r--r--tests/unit/config/test_config.py16
-rw-r--r--tests/unit/config/test_configcommands.py16
-rw-r--r--tests/unit/config/test_configtypes.py6
-rw-r--r--tests/unit/config/test_configutils.py25
-rw-r--r--tests/unit/utils/usertypes/test_misc.py9
10 files changed, 111 insertions, 121 deletions
diff --git a/qutebrowser/config/config.py b/qutebrowser/config/config.py
index 7e10a91f3..d8e0e110a 100644
--- a/qutebrowser/config/config.py
+++ b/qutebrowser/config/config.py
@@ -397,7 +397,7 @@ class Config(QObject):
"""Get the given setting as object (for YAML/config.py).
This gets the overridden value for a given pattern, or
- configutils.UNSET if no such override exists.
+ usertypes.UNSET if no such override exists.
"""
self.ensure_has_opt(name)
value = self._values[name].get_for_pattern(pattern, fallback=False)
@@ -434,7 +434,7 @@ class Config(QObject):
"""Get the given setting as string.
If a pattern is given, get the setting for the given pattern or
- configutils.UNSET.
+ usertypes.UNSET.
"""
opt = self.get_opt(name)
values = self._values[name]
diff --git a/qutebrowser/config/configtypes.py b/qutebrowser/config/configtypes.py
index be1f7edcf..475879de0 100644
--- a/qutebrowser/config/configtypes.py
+++ b/qutebrowser/config/configtypes.py
@@ -61,7 +61,7 @@ from PyQt5.QtWidgets import QTabWidget, QTabBar
from PyQt5.QtNetwork import QNetworkProxy
from qutebrowser.misc import objects, debugcachestats
-from qutebrowser.config import configexc, configutils
+from qutebrowser.config import configexc
from qutebrowser.utils import (standarddir, utils, qtutils, urlutils, urlmatch,
usertypes)
from qutebrowser.keyinput import keyutils
@@ -80,8 +80,8 @@ BOOLEAN_STATES = {'1': True, 'yes': True, 'true': True, 'on': True,
_Completions = typing.Optional[typing.Iterable[typing.Tuple[str, str]]]
-_StrUnset = typing.Union[str, configutils.Unset]
-_StrUnsetNone = typing.Union[None, str, configutils.Unset]
+_StrUnset = typing.Union[str, usertypes.Unset]
+_StrUnsetNone = typing.Union[None, str, usertypes.Unset]
class ValidValues:
@@ -168,7 +168,7 @@ class BaseType:
value: The value to check.
pytype: A Python type to check the value against.
"""
- if isinstance(value, configutils.Unset):
+ if isinstance(value, usertypes.Unset):
return
if (value is None or (pytype == list and value == []) or
@@ -342,7 +342,7 @@ class MappingType(BaseType):
def to_py(self, value: typing.Any) -> typing.Any:
self._basic_py_validation(value, str)
- if isinstance(value, configutils.Unset):
+ if isinstance(value, usertypes.Unset):
return value
elif not value:
return None
@@ -408,7 +408,7 @@ class String(BaseType):
def to_py(self, value: _StrUnset) -> _StrUnsetNone:
self._basic_py_validation(value, str)
- if isinstance(value, configutils.Unset):
+ if isinstance(value, usertypes.Unset):
return value
elif not value:
return None
@@ -450,7 +450,7 @@ class UniqueCharString(String):
def to_py(self, value: _StrUnset) -> _StrUnsetNone:
py_value = super().to_py(value)
- if isinstance(py_value, configutils.Unset):
+ if isinstance(py_value, usertypes.Unset):
return py_value
elif not py_value:
return None
@@ -510,10 +510,10 @@ class List(BaseType):
def to_py(
self,
- value: typing.Union[typing.List, configutils.Unset]
- ) -> typing.Union[typing.List, configutils.Unset]:
+ value: typing.Union[typing.List, usertypes.Unset]
+ ) -> typing.Union[typing.List, usertypes.Unset]:
self._basic_py_validation(value, list)
- if isinstance(value, configutils.Unset):
+ if isinstance(value, usertypes.Unset):
return value
elif not value:
return []
@@ -601,7 +601,7 @@ class ListOrValue(BaseType):
return value
def to_py(self, value: typing.Any) -> typing.Any:
- if isinstance(value, configutils.Unset):
+ if isinstance(value, usertypes.Unset):
return value
try:
@@ -652,10 +652,10 @@ class FlagList(List):
def to_py(
self,
- value: typing.Union[configutils.Unset, typing.List],
- ) -> typing.Union[configutils.Unset, typing.List]:
+ value: typing.Union[usertypes.Unset, typing.List],
+ ) -> typing.Union[usertypes.Unset, typing.List]:
vals = super().to_py(value)
- if not isinstance(vals, configutils.Unset):
+ if not isinstance(vals, usertypes.Unset):
self._check_duplicates(vals)
return vals
@@ -866,10 +866,10 @@ class Perc(_Numeric):
def to_py(
self,
- value: typing.Union[None, float, int, str, configutils.Unset]
- ) -> typing.Union[None, float, int, configutils.Unset]:
+ value: typing.Union[None, float, int, str, usertypes.Unset]
+ ) -> typing.Union[None, float, int, usertypes.Unset]:
self._basic_py_validation(value, (float, int, str))
- if isinstance(value, configutils.Unset):
+ if isinstance(value, usertypes.Unset):
return value
elif not value:
return None
@@ -1062,10 +1062,10 @@ class QtColor(BaseType):
except ValueError:
raise configexc.ValidationError(val, "must be a valid color value")
- def to_py(self, value: _StrUnset) -> typing.Union[configutils.Unset,
+ def to_py(self, value: _StrUnset) -> typing.Union[usertypes.Unset,
None, QColor]:
self._basic_py_validation(value, str)
- if isinstance(value, configutils.Unset):
+ if isinstance(value, usertypes.Unset):
return value
elif not value:
return None
@@ -1123,7 +1123,7 @@ class QssColor(BaseType):
def to_py(self, value: _StrUnset) -> _StrUnsetNone:
self._basic_py_validation(value, str)
- if isinstance(value, configutils.Unset):
+ if isinstance(value, usertypes.Unset):
return value
elif not value:
return None
@@ -1170,7 +1170,7 @@ class Font(BaseType):
def to_py(self, value: _StrUnset) -> _StrUnsetNone:
self._basic_py_validation(value, str)
- if isinstance(value, configutils.Unset):
+ if isinstance(value, usertypes.Unset):
return value
elif not value:
return None
@@ -1191,7 +1191,7 @@ class FontFamily(Font):
def to_py(self, value: _StrUnset) -> _StrUnsetNone:
self._basic_py_validation(value, str)
- if isinstance(value, configutils.Unset):
+ if isinstance(value, usertypes.Unset):
return value
elif not value:
return None
@@ -1215,10 +1215,10 @@ class QtFont(Font):
__doc__ = Font.__doc__ # for src2asciidoc.py
- def to_py(self, value: _StrUnset) -> typing.Union[configutils.Unset,
+ def to_py(self, value: _StrUnset) -> typing.Union[usertypes.Unset,
None, QFont]:
self._basic_py_validation(value, str)
- if isinstance(value, configutils.Unset):
+ if isinstance(value, usertypes.Unset):
return value
elif not value:
return None
@@ -1333,11 +1333,11 @@ class Regex(BaseType):
def to_py(
self,
- value: typing.Union[str, typing.Pattern[str], configutils.Unset]
- ) -> typing.Union[configutils.Unset, None, typing.Pattern[str]]:
+ value: typing.Union[str, typing.Pattern[str], usertypes.Unset]
+ ) -> typing.Union[usertypes.Unset, None, typing.Pattern[str]]:
"""Get a compiled regex from either a string or a regex object."""
self._basic_py_validation(value, (str, self._regex_type))
- if isinstance(value, configutils.Unset):
+ if isinstance(value, usertypes.Unset):
return value
elif not value:
return None
@@ -1425,10 +1425,10 @@ class Dict(BaseType):
def to_py(
self,
- value: typing.Union[typing.Dict, configutils.Unset, None]
- ) -> typing.Union[typing.Dict, configutils.Unset]:
+ value: typing.Union[typing.Dict, usertypes.Unset, None]
+ ) -> typing.Union[typing.Dict, usertypes.Unset]:
self._basic_py_validation(value, dict)
- if isinstance(value, configutils.Unset):
+ if isinstance(value, usertypes.Unset):
return value
elif not value:
return self._fill_fixed_keys({})
@@ -1477,7 +1477,7 @@ class File(BaseType):
def to_py(self, value: _StrUnset) -> _StrUnsetNone:
self._basic_py_validation(value, str)
- if isinstance(value, configutils.Unset):
+ if isinstance(value, usertypes.Unset):
return value
elif not value:
return None
@@ -1509,7 +1509,7 @@ class Directory(BaseType):
def to_py(self, value: _StrUnset) -> _StrUnsetNone:
self._basic_py_validation(value, str)
- if isinstance(value, configutils.Unset):
+ if isinstance(value, usertypes.Unset):
return value
elif not value:
return None
@@ -1546,7 +1546,7 @@ class FormatString(BaseType):
def to_py(self, value: _StrUnset) -> _StrUnsetNone:
self._basic_py_validation(value, str)
- if isinstance(value, configutils.Unset):
+ if isinstance(value, usertypes.Unset):
return value
elif not value:
return None
@@ -1590,10 +1590,10 @@ class ShellCommand(List):
def to_py(
self,
- value: typing.Union[typing.List, configutils.Unset],
- ) -> typing.Union[typing.List, configutils.Unset]:
+ value: typing.Union[typing.List, usertypes.Unset],
+ ) -> typing.Union[typing.List, usertypes.Unset]:
py_value = super().to_py(value)
- if isinstance(py_value, configutils.Unset):
+ if isinstance(py_value, usertypes.Unset):
return py_value
elif not py_value:
return []
@@ -1624,9 +1624,9 @@ class Proxy(BaseType):
def to_py(
self,
value: _StrUnset
- ) -> typing.Union[configutils.Unset, None, QNetworkProxy, _SystemProxy]:
+ ) -> typing.Union[usertypes.Unset, None, QNetworkProxy, _SystemProxy]:
self._basic_py_validation(value, str)
- if isinstance(value, configutils.Unset):
+ if isinstance(value, usertypes.Unset):
return value
elif not value:
return None
@@ -1666,7 +1666,7 @@ class SearchEngineUrl(BaseType):
def to_py(self, value: _StrUnset) -> _StrUnsetNone:
self._basic_py_validation(value, str)
- if isinstance(value, configutils.Unset):
+ if isinstance(value, usertypes.Unset):
return value
elif not value:
return None
@@ -1696,7 +1696,7 @@ class FuzzyUrl(BaseType):
def to_py(self, value: _StrUnset) -> _StrUnsetNone:
self._basic_py_validation(value, str)
- if isinstance(value, configutils.Unset):
+ if isinstance(value, usertypes.Unset):
return value
elif not value:
return None
@@ -1732,10 +1732,10 @@ class Padding(Dict):
def to_py( # type: ignore
self,
- value: typing.Union[configutils.Unset, typing.Dict, None],
- ) -> typing.Union[configutils.Unset, PaddingValues]:
+ value: typing.Union[usertypes.Unset, typing.Dict, None],
+ ) -> typing.Union[usertypes.Unset, PaddingValues]:
d = super().to_py(value)
- if isinstance(d, configutils.Unset):
+ if isinstance(d, usertypes.Unset):
return d
return PaddingValues(**d)
@@ -1747,7 +1747,7 @@ class Encoding(BaseType):
def to_py(self, value: _StrUnset) -> _StrUnsetNone:
self._basic_py_validation(value, str)
- if isinstance(value, configutils.Unset):
+ if isinstance(value, usertypes.Unset):
return value
elif not value:
return None
@@ -1807,9 +1807,9 @@ class Url(BaseType):
def to_py(
self,
value: _StrUnset
- ) -> typing.Union[configutils.Unset, None, QUrl]:
+ ) -> typing.Union[usertypes.Unset, None, QUrl]:
self._basic_py_validation(value, str)
- if isinstance(value, configutils.Unset):
+ if isinstance(value, usertypes.Unset):
return value
elif not value:
return None
@@ -1827,7 +1827,7 @@ class SessionName(BaseType):
def to_py(self, value: _StrUnset) -> _StrUnsetNone:
self._basic_py_validation(value, str)
- if isinstance(value, configutils.Unset):
+ if isinstance(value, usertypes.Unset):
return value
elif not value:
return None
@@ -1877,10 +1877,10 @@ class ConfirmQuit(FlagList):
def to_py(
self,
- value: typing.Union[configutils.Unset, typing.List],
- ) -> typing.Union[typing.List, configutils.Unset]:
+ value: typing.Union[usertypes.Unset, typing.List],
+ ) -> typing.Union[typing.List, usertypes.Unset]:
values = super().to_py(value)
- if isinstance(values, configutils.Unset):
+ if isinstance(values, usertypes.Unset):
return values
elif not values:
return []
@@ -1921,9 +1921,9 @@ class Key(BaseType):
def to_py(
self,
value: _StrUnset
- ) -> typing.Union[configutils.Unset, None, keyutils.KeySequence]:
+ ) -> typing.Union[usertypes.Unset, None, keyutils.KeySequence]:
self._basic_py_validation(value, str)
- if isinstance(value, configutils.Unset):
+ if isinstance(value, usertypes.Unset):
return value
elif not value:
return None
@@ -1945,9 +1945,9 @@ class UrlPattern(BaseType):
def to_py(
self,
value: _StrUnset
- ) -> typing.Union[configutils.Unset, None, urlmatch.UrlPattern]:
+ ) -> typing.Union[usertypes.Unset, None, urlmatch.UrlPattern]:
self._basic_py_validation(value, str)
- if isinstance(value, configutils.Unset):
+ if isinstance(value, usertypes.Unset):
return value
elif not value:
return None
diff --git a/qutebrowser/config/configutils.py b/qutebrowser/config/configutils.py
index 506c8eeda..57a0893d2 100644
--- a/qutebrowser/config/configutils.py
+++ b/qutebrowser/config/configutils.py
@@ -28,26 +28,13 @@ import operator
from PyQt5.QtCore import QUrl
-from qutebrowser.utils import utils, urlmatch, urlutils
+from qutebrowser.utils import utils, urlmatch, urlutils, usertypes
from qutebrowser.config import configexc
if typing.TYPE_CHECKING:
from qutebrowser.config import configdata
-class Unset:
-
- """Sentinel object."""
-
- __slots__ = ()
-
- def __repr__(self) -> str:
- return '<UNSET>'
-
-
-UNSET = Unset()
-
-
class ScopedValue:
"""A configuration value which is valid for a UrlPattern.
@@ -213,7 +200,7 @@ class Values:
if fallback:
return self.opt.default
else:
- return UNSET
+ return usertypes.UNSET
def get_for_url(self, url: QUrl = None, *,
fallback: bool = True) -> typing.Any:
@@ -222,7 +209,7 @@ class Values:
This first tries to find a value matching the URL (if given).
If there's no match:
With fallback=True, the global/default setting is returned.
- With fallback=False, UNSET is returned.
+ With fallback=False, usertypes.UNSET is returned.
"""
self._check_pattern_support(url)
if url is None:
@@ -243,7 +230,7 @@ class Values:
return scoped.value
if not fallback:
- return UNSET
+ return usertypes.UNSET
return self._get_fallback(fallback)
@@ -256,7 +243,7 @@ class Values:
If there's no match:
With fallback=True, the global/default setting is returned.
- With fallback=False, UNSET is returned.
+ With fallback=False, usertypes.UNSET is returned.
"""
self._check_pattern_support(pattern)
if pattern is not None:
@@ -264,6 +251,6 @@ class Values:
return self._vmap[pattern].value
if not fallback:
- return UNSET
+ return usertypes.UNSET
return self._get_fallback(fallback)
diff --git a/qutebrowser/config/websettings.py b/qutebrowser/config/websettings.py
index 7b839a009..2f78b561e 100644
--- a/qutebrowser/config/websettings.py
+++ b/qutebrowser/config/websettings.py
@@ -29,7 +29,7 @@ from PyQt5.QtCore import QUrl, pyqtSlot, qVersion
from PyQt5.QtGui import QFont
import qutebrowser
-from qutebrowser.config import config, configutils
+from qutebrowser.config import config
from qutebrowser.utils import log, usertypes, urlmatch, qtutils
from qutebrowser.misc import objects, debugcachestats
@@ -106,7 +106,7 @@ class AbstractSettings:
def set_attribute(self, name: str, value: typing.Any) -> bool:
"""Set the given QWebSettings/QWebEngineSettings attribute.
- If the value is configutils.UNSET, the value is reset instead.
+ If the value is usertypes.UNSET, the value is reset instead.
Return:
True if there was a change, False otherwise.
@@ -115,7 +115,7 @@ class AbstractSettings:
info = self._ATTRIBUTES[name]
for attribute in info.attributes:
- if value is configutils.UNSET:
+ if value is usertypes.UNSET:
self._settings.resetAttribute(attribute)
new_value = self.test_attribute(name)
else:
@@ -139,7 +139,7 @@ class AbstractSettings:
Return:
True if there was a change, False otherwise.
"""
- assert value is not configutils.UNSET # type: ignore
+ assert value is not usertypes.UNSET # type: ignore
family = self._FONT_SIZES[name]
old_value = self._settings.fontSize(family)
self._settings.setFontSize(family, value)
@@ -154,7 +154,7 @@ class AbstractSettings:
Return:
True if there was a change, False otherwise.
"""
- assert value is not configutils.UNSET # type: ignore
+ assert value is not usertypes.UNSET # type: ignore
family = self._FONT_FAMILIES[name]
if value is None:
font = QFont()
@@ -172,7 +172,7 @@ class AbstractSettings:
Return:
True if there was a change, False otherwise.
"""
- assert encoding is not configutils.UNSET # type: ignore
+ assert encoding is not usertypes.UNSET # type: ignore
old_value = self._settings.defaultTextEncoding()
self._settings.setDefaultTextEncoding(encoding)
return old_value != encoding
diff --git a/qutebrowser/utils/usertypes.py b/qutebrowser/utils/usertypes.py
index 58fe950b2..65ab2d491 100644
--- a/qutebrowser/utils/usertypes.py
+++ b/qutebrowser/utils/usertypes.py
@@ -33,14 +33,17 @@ from qutebrowser.utils import log, qtutils, utils
_T = typing.TypeVar('_T')
-class UnsetObject:
+class Unset:
"""Class for an unset object."""
__slots__ = ()
+ def __repr__(self) -> str:
+ return '<UNSET>'
+
-UNSET = UnsetObject()
+UNSET = Unset()
class NeighborList(typing.Sequence[_T]):
@@ -60,7 +63,7 @@ class NeighborList(typing.Sequence[_T]):
Modes = enum.Enum('Modes', ['edge', 'exception'])
def __init__(self, items: typing.Sequence[_T] = None,
- default: typing.Union[_T, UnsetObject] = UNSET,
+ default: typing.Union[_T, Unset] = UNSET,
mode: Modes = Modes.exception) -> None:
"""Constructor.
@@ -79,7 +82,7 @@ class NeighborList(typing.Sequence[_T]):
self._items = list(items)
self._default = default
- if not isinstance(default, UnsetObject):
+ if not isinstance(default, Unset):
idx = self._items.index(default)
self._idx = idx # type: typing.Optional[int]
else:
diff --git a/tests/unit/config/test_config.py b/tests/unit/config/test_config.py
index 9eefedf15..e8e814a79 100644
--- a/tests/unit/config/test_config.py
+++ b/tests/unit/config/test_config.py
@@ -26,7 +26,7 @@ import pytest
from PyQt5.QtCore import QObject, QUrl
from PyQt5.QtGui import QColor
-from qutebrowser.config import config, configdata, configexc, configutils
+from qutebrowser.config import config, configdata, configexc
from qutebrowser.utils import usertypes, urlmatch
from qutebrowser.misc import objects
from qutebrowser.keyinput import keyutils
@@ -410,7 +410,7 @@ class TestConfig:
assert conf.get(name) == 'always'
if save_yaml:
- assert yaml_value(name) is configutils.UNSET
+ assert yaml_value(name) is usertypes.UNSET
else:
assert yaml_value(name) == 'never'
@@ -439,8 +439,8 @@ class TestConfig:
assert options == {name1, name2}
if save_yaml:
- assert yaml_value(name1) is configutils.UNSET
- assert yaml_value(name2) is configutils.UNSET
+ assert yaml_value(name1) is usertypes.UNSET
+ assert yaml_value(name2) is usertypes.UNSET
else:
assert yaml_value(name1) == 'never'
assert yaml_value(name2) is True
@@ -482,7 +482,7 @@ class TestConfig:
@pytest.mark.parametrize('fallback, expected', [
(True, True),
- (False, configutils.UNSET)
+ (False, usertypes.UNSET)
])
def test_get_for_url_fallback(self, conf, fallback, expected):
"""Test conf.get() with a URL and fallback."""
@@ -617,7 +617,7 @@ class TestConfig:
pattern = urlmatch.UrlPattern('*://example.com')
name = 'content.javascript.enabled'
value = conf.get_obj_for_pattern(name, pattern=pattern)
- assert value is configutils.UNSET
+ assert value is usertypes.UNSET
def test_get_str(self, conf):
assert conf.get_str('content.plugins') == 'false'
@@ -637,7 +637,7 @@ class TestConfig:
if save_yaml:
assert yaml_value(option) is True
else:
- assert yaml_value(option) is configutils.UNSET
+ assert yaml_value(option) is usertypes.UNSET
@pytest.mark.parametrize('method', ['set_obj', 'set_str'])
def test_set_invalid(self, conf, qtbot, method):
@@ -669,7 +669,7 @@ class TestConfig:
meth(option, value, save_yaml=True)
assert not conf._values[option]
- assert yaml_value(option) is configutils.UNSET
+ assert yaml_value(option) is usertypes.UNSET
@pytest.mark.parametrize('method, value', [
('set_obj', {}),
diff --git a/tests/unit/config/test_configcommands.py b/tests/unit/config/test_configcommands.py
index 382d41ad8..97dcd7c42 100644
--- a/tests/unit/config/test_configcommands.py
+++ b/tests/unit/config/test_configcommands.py
@@ -25,7 +25,7 @@ import unittest.mock
import pytest
from PyQt5.QtCore import QUrl
-from qutebrowser.config import configcommands, configutils
+from qutebrowser.config import configcommands
from qutebrowser.api import cmdutils
from qutebrowser.utils import usertypes, urlmatch
from qutebrowser.keyinput import keyutils
@@ -92,7 +92,7 @@ class TestSet:
commands.set(0, option, inp, temp=temp)
assert config_stub.get(option) == new_value
- assert yaml_value(option) == (configutils.UNSET if temp else new_value)
+ assert yaml_value(option) == (usertypes.UNSET if temp else new_value)
def test_set_with_pattern(self, monkeypatch, commands, config_stub):
monkeypatch.setattr(objects, 'backend', usertypes.Backend.QtWebKit)
@@ -295,7 +295,7 @@ class TestAdd:
assert str(config_stub.get(name)[-1]) == value
if temp:
- assert yaml_value(name) == configutils.UNSET
+ assert yaml_value(name) == usertypes.UNSET
else:
assert yaml_value(name)[-1] == value
@@ -328,7 +328,7 @@ class TestAdd:
assert str(config_stub.get(name)[key]) == value
if temp:
- assert yaml_value(name) == configutils.UNSET
+ assert yaml_value(name) == usertypes.UNSET
else:
assert yaml_value(name)[key] == value
@@ -379,7 +379,7 @@ class TestRemove:
assert value not in config_stub.get(name)
if temp:
- assert yaml_value(name) == configutils.UNSET
+ assert yaml_value(name) == usertypes.UNSET
else:
assert value not in yaml_value(name)
@@ -410,7 +410,7 @@ class TestRemove:
assert key not in config_stub.get(name)
if temp:
- assert yaml_value(name) == configutils.UNSET
+ assert yaml_value(name) == usertypes.UNSET
else:
assert key not in yaml_value(name)
@@ -446,7 +446,7 @@ class TestUnsetAndClear:
commands.config_unset(name, temp=temp)
assert config_stub.get(name) == 'always'
- assert yaml_value(name) == ('never' if temp else configutils.UNSET)
+ assert yaml_value(name) == ('never' if temp else usertypes.UNSET)
def test_unset_unknown_option(self, commands):
with pytest.raises(cmdutils.CommandError, match="No option 'tabs'"):
@@ -460,7 +460,7 @@ class TestUnsetAndClear:
commands.config_clear(save=save)
assert config_stub.get(name) == 'always'
- assert yaml_value(name) == (configutils.UNSET if save else 'never')
+ assert yaml_value(name) == (usertypes.UNSET if save else 'never')
class TestSource:
diff --git a/tests/unit/config/test_configtypes.py b/tests/unit/config/test_configtypes.py
index 55d225a7e..e766fca8a 100644
--- a/tests/unit/config/test_configtypes.py
+++ b/tests/unit/config/test_configtypes.py
@@ -34,8 +34,8 @@ from PyQt5.QtGui import QColor, QFont
from PyQt5.QtNetwork import QNetworkProxy
from qutebrowser.misc import objects
-from qutebrowser.config import configtypes, configexc, configutils
-from qutebrowser.utils import debug, utils, qtutils, urlmatch
+from qutebrowser.config import configtypes, configexc
+from qutebrowser.utils import debug, utils, qtutils, urlmatch, usertypes
from qutebrowser.browser.network import pac
from qutebrowser.keyinput import keyutils
from helpers import utils as testutils
@@ -277,7 +277,7 @@ class TestAll:
@pytest.mark.parametrize('none_ok', [True, False])
def test_unset(self, klass, none_ok):
typ = klass(none_ok=none_ok)
- assert typ.to_py(configutils.UNSET) is configutils.UNSET
+ assert typ.to_py(usertypes.UNSET) is usertypes.UNSET
def test_to_str_none(self, klass):
assert klass().to_str(None) == ''
diff --git a/tests/unit/config/test_configutils.py b/tests/unit/config/test_configutils.py
index 90a7dbd88..518391d29 100644
--- a/tests/unit/config/test_configutils.py
+++ b/tests/unit/config/test_configutils.py
@@ -23,19 +23,10 @@ import pytest
from PyQt5.QtCore import QUrl
from qutebrowser.config import configutils, configdata, configtypes
-from qutebrowser.utils import urlmatch
+from qutebrowser.utils import urlmatch, usertypes
from tests.helpers import utils
-def test_unset_object_identity():
- assert configutils.Unset() is not configutils.Unset()
- assert configutils.UNSET is configutils.UNSET
-
-
-def test_unset_object_repr():
- assert repr(configutils.UNSET) == '<UNSET>'
-
-
@pytest.fixture
def opt():
return configdata.Option(name='example.option', typ=configtypes.String(),
@@ -142,7 +133,7 @@ def test_clear(values):
assert values
values.clear()
assert not values
- assert values.get_for_url(fallback=False) is configutils.UNSET
+ assert values.get_for_url(fallback=False) is usertypes.UNSET
def test_get_matching(values):
@@ -151,12 +142,12 @@ def test_get_matching(values):
def test_get_unset(empty_values):
- assert empty_values.get_for_url(fallback=False) is configutils.UNSET
+ assert empty_values.get_for_url(fallback=False) is usertypes.UNSET
def test_get_no_global(empty_values, other_pattern, pattern):
empty_values.add('example.org value', pattern)
- assert empty_values.get_for_url(fallback=False) is configutils.UNSET
+ assert empty_values.get_for_url(fallback=False) is usertypes.UNSET
def test_get_unset_fallback(empty_values):
@@ -165,7 +156,7 @@ def test_get_unset_fallback(empty_values):
def test_get_non_matching(values):
url = QUrl('https://www.example.ch/')
- assert values.get_for_url(url, fallback=False) is configutils.UNSET
+ assert values.get_for_url(url, fallback=False) is usertypes.UNSET
def test_get_non_matching_fallback(values):
@@ -201,13 +192,13 @@ def test_get_pattern_none(values, pattern):
def test_get_unset_pattern(empty_values, pattern):
value = empty_values.get_for_pattern(pattern, fallback=False)
- assert value is configutils.UNSET
+ assert value is usertypes.UNSET
def test_get_no_global_pattern(empty_values, pattern, other_pattern):
empty_values.add('example.org value', other_pattern)
value = empty_values.get_for_pattern(pattern, fallback=False)
- assert value is configutils.UNSET
+ assert value is usertypes.UNSET
def test_get_unset_fallback_pattern(empty_values, pattern):
@@ -216,7 +207,7 @@ def test_get_unset_fallback_pattern(empty_values, pattern):
def test_get_non_matching_pattern(values, other_pattern):
value = values.get_for_pattern(other_pattern, fallback=False)
- assert value is configutils.UNSET
+ assert value is usertypes.UNSET
def test_get_non_matching_fallback_pattern(values, other_pattern):
diff --git a/tests/unit/utils/usertypes/test_misc.py b/tests/unit/utils/usertypes/test_misc.py
index 1700b7f51..68eabc213 100644
--- a/tests/unit/utils/usertypes/test_misc.py
+++ b/tests/unit/utils/usertypes/test_misc.py
@@ -25,3 +25,12 @@ def test_abstract_certificate_error_wrapper():
err = object()
wrapper = usertypes.AbstractCertificateErrorWrapper(err)
assert wrapper._error is err
+
+
+def test_unset_object_identity():
+ assert usertypes.Unset() is not usertypes.Unset()
+ assert usertypes.UNSET is usertypes.UNSET
+
+
+def test_unset_object_repr():
+ assert repr(usertypes.UNSET) == '<UNSET>'