Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# self._match_subdomains, as we want to return True here for e.g.
# file:// as well.
if self.host is None:
return True
# If the hosts are exactly equal, we have a match.
if host == self.host:
return True
# Otherwise, we can only match if our match pattern matches subdomains.
if not self._match_subdomains:
return False
# We don't do subdomain matching against IP addresses, so we can give
# up now if the test host is an IP address.
if not utils.raises(ValueError, ipaddress.ip_address, host):
return False
# Check if the test host is a subdomain of our host.
if len(host) <= (len(self.host) + 1):
return False
if not host.endswith(self.host):
return False
return host[len(host) - len(self.host) - 1] == '.'
def install(self, profile):
"""Install the handler for qute:// URLs on the given profile."""
if QWebEngineUrlScheme is not None:
assert QWebEngineUrlScheme.schemeByName(b'qute') is not None
profile.installUrlSchemeHandler(b'qute', self)
if (qtutils.version_check('5.11', compiled=False) and
not qtutils.version_check('5.12', compiled=False)):
# WORKAROUND for https://bugreports.qt.io/browse/QTBUG-63378
profile.installUrlSchemeHandler(b'chrome-error', self)
profile.installUrlSchemeHandler(b'chrome-extension', self)
def question():
return usertypes.Question()
def test_is_int():
"""Test the is_int argument."""
int_enum = usertypes.enum('Enum', ['item'], is_int=True)
no_int_enum = usertypes.enum('Enum', ['item'])
assert isinstance(int_enum.item, int)
assert not isinstance(no_int_enum.item, int)
def _record_message(self, level, text):
log_levels = {
usertypes.MessageLevel.error: logging.ERROR,
usertypes.MessageLevel.info: logging.INFO,
usertypes.MessageLevel.warning: logging.WARNING,
}
log_level = log_levels[level]
logging.getLogger('messagemock').log(log_level, text)
self.messages.append(Message(level, text))
This returns a line like qute without --json-logging would produce.
Args:
colorized: If True, ANSI color codes will be embedded.
"""
r = logging.LogRecord(self.category, self.loglevel, '', self.line,
self.message, (), None)
# Patch some attributes of the LogRecord
if self.line is None:
r.line = 0
r.created = self.timestamp.timestamp()
r.msecs = self.msecs
r.module = self.module
r.funcName = self.function
format_str = log.EXTENDED_FMT
format_str = format_str.replace('{asctime:8}',
'{asctime:8}.{msecs:03.0f}')
# Mark expected errors with (expected) so it's less confusing for tests
# which expect errors but fail due to other errors.
if self.expected and self.loglevel > logging.INFO:
new_color = '{' + log.LOG_COLORS['DEBUG'] + '}'
format_str = format_str.replace('{log_color}', new_color)
format_str = re.sub(r'{levelname:(\d*)}',
# Leave away the padding because (expected) is
# longer anyway.
r'{levelname} (expected)', format_str)
formatter = log.ColoredFormatter(format_str, log.DATEFMT, '{',
use_colors=colorized)
result = formatter.format(r)
# Manually append the stringified traceback if one is present
def test_configcache_except_pattern(config_stub):
with pytest.raises(AssertionError):
assert config.cache['content.javascript.enabled']
"""Partial comparison of dicts/lists."""
import re
import pprint
import os.path
import contextlib
import pytest
from qutebrowser.utils import qtutils
qt58 = pytest.mark.skipif(
qtutils.version_check('5.9'), reason="Needs Qt 5.8 or earlier")
qt59 = pytest.mark.skipif(
not qtutils.version_check('5.9'), reason="Needs Qt 5.9 or newer")
qt510 = pytest.mark.skipif(
not qtutils.version_check('5.10'), reason="Needs Qt 5.10 or newer")
skip_qt511 = pytest.mark.skipif(
qtutils.version_check('5.11'), reason="Needs Qt 5.10 or earlier")
class PartialCompareOutcome:
"""Storage for a partial_compare error.
Evaluates to False if an error was found.
Attributes:
error: A string describing an error or None.
def test_version_check(monkeypatch, qversion, compiled, pyqt, version, exact,
expected):
"""Test for version_check().
Args:
monkeypatch: The pytest monkeypatch fixture.
qversion: The version to set as fake qVersion().
compiled: The value for QT_VERSION_STR (set compiled=False)
pyqt: The value for PYQT_VERSION_STR (set compiled=False)
version: The version to compare with.
exact: Use exact comparing (==)
expected: The expected result.
"""
monkeypatch.setattr(qtutils, 'qVersion', lambda: qversion)
if compiled is not None:
monkeypatch.setattr(qtutils, 'QT_VERSION_STR', compiled)
monkeypatch.setattr(qtutils, 'PYQT_VERSION_STR', pyqt)
compiled_arg = True
else:
compiled_arg = False
actual = qtutils.version_check(version, exact, compiled=compiled_arg)
assert actual == expected
def test_invalid_start(self, colors):
"""Test an invalid start color."""
with pytest.raises(qtutils.QtValueError):
utils.interpolate_color(Color(), colors.white, 0)