Exemple #1
0
def run_command(quteproc, httpbin, tmpdir, command):
    """Run a qutebrowser command.

    The suffix "with count ..." can be used to pass a count to the command.
    """
    if 'with count' in command:
        command, count = command.split(' with count ')
        count = int(count)
    else:
        count = None

    invalid_tag = ' (invalid command)'
    if command.endswith(invalid_tag):
        command = command[:-len(invalid_tag)]
        invalid = True
    else:
        invalid = False

    command = command.replace('(port)', str(httpbin.port))
    command = command.replace('(testdata)', utils.abs_datapath())
    command = command.replace('(tmpdir)', str(tmpdir))
    command = command.replace('(dirsep)', os.sep)
    command = command.replace('(echo-exe)', _get_echo_exe_path())

    quteproc.send_cmd(command, count=count, invalid=invalid)
Exemple #2
0
def run_command(quteproc, server, tmpdir, command):
    """Run a qutebrowser command.

    The suffix "with count ..." can be used to pass a count to the command.
    """
    if 'with count' in command:
        command, count = command.split(' with count ')
        count = int(count)
    else:
        count = None

    invalid_tag = ' (invalid command)'
    if command.endswith(invalid_tag):
        command = command[:-len(invalid_tag)]
        invalid = True
    else:
        invalid = False

    command = command.replace('(port)', str(server.port))
    command = command.replace('(testdata)', utils.abs_datapath())
    command = command.replace('(tmpdir)', str(tmpdir))
    command = command.replace('(dirsep)', os.sep)
    command = command.replace('(echo-exe)', _get_echo_exe_path())

    quteproc.send_cmd(command, count=count, invalid=invalid)
Exemple #3
0
def test_adblock_benchmark(data_tmpdir, benchmark, host_blocker_factory):
    blocked_hosts = os.path.join(utils.abs_datapath(), 'blocked-hosts')
    shutil.copy(blocked_hosts, str(data_tmpdir))

    url = QUrl('https://www.example.org/')
    blocker = host_blocker_factory()
    blocker.read_hosts()
    assert blocker._blocked_hosts

    benchmark(lambda: blocker._is_blocked(url))
def test_adblock_benchmark(data_tmpdir, benchmark, host_blocker_factory):
    blocked_hosts = os.path.join(utils.abs_datapath(), 'blocked-hosts')
    shutil.copy(blocked_hosts, str(data_tmpdir))

    url = QUrl('https://www.example.org/')
    blocker = host_blocker_factory()
    blocker.read_hosts()
    assert blocker._blocked_hosts

    benchmark(lambda: blocker._is_blocked(url))
Exemple #5
0
def _get_echo_exe_path():
    """Return the path to an echo-like command, depending on the system.

    Return:
        Path to the "echo"-utility.
    """
    if sys.platform == "win32":
        return os.path.join(utils.abs_datapath(), 'userscripts', 'echo.bat')
    else:
        return 'echo'
Exemple #6
0
def _get_echo_exe_path():
    """Return the path to an echo-like command, depending on the system.

    Return:
        Path to the "echo"-utility.
    """
    if sys.platform == "win32":
        return os.path.join(utils.abs_datapath(), 'userscripts', 'echo.bat')
    else:
        return 'echo'
Exemple #7
0
def check_contents(quteproc, filename):
    """Check the current page's content.

    The filename is interpreted relative to tests/integration/data.
    """
    content = quteproc.get_content(plain=False)
    path = os.path.join(utils.abs_datapath(),
                        os.path.join(*filename.split('/')))
    with open(path, 'r', encoding='utf-8') as f:
        file_content = f.read()
        assert content == file_content
Exemple #8
0
def check_contents(quteproc, filename):
    """Check the current page's content.

    The filename is interpreted relative to tests/end2end/data.
    """
    content = quteproc.get_content(plain=False)
    path = os.path.join(utils.abs_datapath(),
                        os.path.join(*filename.split('/')))
    with open(path, 'r', encoding='utf-8') as f:
        file_content = f.read()
        assert content == file_content
Exemple #9
0
def run_userscript(quteproc, userscript):
    """Run a userscript located in tests/integration/data/userscripts.

    Wrapper around :spawn --userscript {userscript} that uses an absolute
    path.
    """
    abs_userscript_path = os.path.join(utils.abs_datapath(),
                                       'userscripts', userscript)

    cmd = ':spawn --userscript {abs_userscript_path}'
    quteproc.send_cmd(cmd.format(abs_userscript_path=abs_userscript_path))
Exemple #10
0
def _get_echo_exe_path():
    """Return the path to an echo-like command, depending on the system.

    Return:
        Path to the "echo"-utility.
    """
    if utils.is_windows:
        return os.path.join(testutils.abs_datapath(), 'userscripts',
                            'echo.bat')
    else:
        return 'echo'
Exemple #11
0
def _get_echo_exe_path():
    """Return the path to an echo-like command, depending on the system.

    Return:
        Path to the "echo"-utility.
    """
    if utils.is_windows:
        return os.path.join(testutils.abs_datapath(), 'userscripts',
                            'echo.bat')
    else:
        return 'echo'
Exemple #12
0
def run_userscript(quteproc, userscript):
    """Run a userscript located in tests/integration/data/userscripts.

    Wrapper around :spawn --userscript {userscript} that uses an absolute
    path.
    """
    abs_userscript_path = os.path.join(utils.abs_datapath(), 'userscripts',
                                       userscript)

    cmd = ':spawn --userscript {abs_userscript_path}'
    quteproc.send_cmd(cmd.format(abs_userscript_path=abs_userscript_path))
Exemple #13
0
def run_command(quteproc, httpbin, command):
    """Run a qutebrowser command.

    The suffix "with count ..." can be used to pass a count to the command.
    """
    if 'with count' in command:
        command, count = command.split(' with count ')
        count = int(count)
    else:
        count = None
    command = command.replace('(port)', str(httpbin.port))
    command = command.replace('(testdata)', utils.abs_datapath())

    quteproc.send_cmd(command, count=count)
Exemple #14
0
def run_command(quteproc, httpbin, command):
    """Run a qutebrowser command.

    The suffix "with count ..." can be used to pass a count to the command.
    """
    if 'with count' in command:
        command, count = command.split(' with count ')
        count = int(count)
    else:
        count = None
    command = command.replace('(port)', str(httpbin.port))
    command = command.replace('(testdata)', utils.abs_datapath())

    quteproc.send_cmd(command, count=count)
Exemple #15
0
def run_command(quteproc, httpbin, command):
    """Run a qutebrowser command.

    The suffix "with count ..." can be used to pass a count to the command.
    """
    if 'with count' in command:
        command, count = command.split(' with count ')
        count = int(count)
    else:
        count = None

    invalid_tag = ' (invalid command)'
    if command.endswith(invalid_tag):
        command = command[:-len(invalid_tag)]
        invalid = True
    else:
        invalid = False

    command = command.replace('(port)', str(httpbin.port))
    command = command.replace('(testdata)', utils.abs_datapath())

    quteproc.send_cmd(command, count=count, invalid=invalid)
Exemple #16
0
def hint_and_follow(quteproc, args, letter):
    args = args.replace('(testdata)', testutils.abs_datapath())
    args = args.replace('(python-executable)', sys.executable)
    quteproc.send_cmd(':hint {}'.format(args))
    quteproc.wait_for(message='hints: *')
    quteproc.send_cmd(':hint-follow {}'.format(letter))
Exemple #17
0
def hint_and_follow(quteproc, args, letter):
    args = args.replace('(testdata)', utils.abs_datapath())
    quteproc.send_cmd(':hint {}'.format(args))
    quteproc.wait_for(message='hints: *')
    quteproc.send_cmd(':follow-hint {}'.format(letter))
Exemple #18
0
def hint_and_follow(quteproc, args, letter):
    args = args.replace('(testdata)', utils.abs_datapath())
    quteproc.send_cmd(':hint {}'.format(args))
    quteproc.wait_for(message='hints: *')
    quteproc.send_cmd(':follow-hint {}'.format(letter))