From 6b2b096f3cfa6cfe861fc01ae1183d1fe5190fec Mon Sep 17 00:00:00 2001 From: Jeremy Kaplan Date: Mon, 11 Jul 2016 20:08:24 -0400 Subject: [PATCH] Add test for :print --pdf --- qutebrowser/browser/commands.py | 1 + tests/end2end/features/conftest.py | 3 ++- tests/end2end/features/misc.feature | 7 +++++++ tests/end2end/features/test_misc_bdd.py | 11 +++++++++++ 4 files changed, 21 insertions(+), 1 deletion(-) diff --git a/qutebrowser/browser/commands.py b/qutebrowser/browser/commands.py index 45232282a..99ef1f088 100644 --- a/qutebrowser/browser/commands.py +++ b/qutebrowser/browser/commands.py @@ -332,6 +332,7 @@ class CommandDispatcher: printer = QPrinter() printer.setOutputFileName(pdf) tab.print(printer) + log.misc.debug("Print to file: {}".format(pdf)) else: diag = QPrintDialog() diag.setAttribute(Qt.WA_DeleteOnClose) diff --git a/tests/end2end/features/conftest.py b/tests/end2end/features/conftest.py index 9d1d5c074..8c9eea825 100644 --- a/tests/end2end/features/conftest.py +++ b/tests/end2end/features/conftest.py @@ -179,7 +179,7 @@ def set_setting(quteproc, httpbin, sect, opt, value): @bdd.when(bdd.parsers.parse("I run {command}")) -def run_command(quteproc, httpbin, command): +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. @@ -199,6 +199,7 @@ def run_command(quteproc, httpbin, command): command = command.replace('(port)', str(httpbin.port)) command = command.replace('(testdata)', utils.abs_datapath()) + command = command.replace('(tmpdir)', str(tmpdir)) quteproc.send_cmd(command, count=count, invalid=invalid) diff --git a/tests/end2end/features/misc.feature b/tests/end2end/features/misc.feature index ed415958d..5842a12a5 100644 --- a/tests/end2end/features/misc.feature +++ b/tests/end2end/features/misc.feature @@ -339,6 +339,13 @@ Feature: Various utility commands. And I run :debug-pyeval QApplication.instance().activeModalWidget().close() Then no crash should happen + Scenario: print pdf + Given a new tmpdir + When I open data/hello.txt + And I run :print --pdf (tmpdir)/hello.pdf + And I wait for "Print to file: *" in the log or skip the test + Then the file hello.pdf should exist in the tmpdir + # :pyeval Scenario: Running :pyeval diff --git a/tests/end2end/features/test_misc_bdd.py b/tests/end2end/features/test_misc_bdd.py index 443583166..7a28d059c 100644 --- a/tests/end2end/features/test_misc_bdd.py +++ b/tests/end2end/features/test_misc_bdd.py @@ -73,3 +73,14 @@ def check_cookie(quteproc, name, value): data = json.loads(content) print(data) assert data['cookies'][name] == value + + +@bdd.given(bdd.parsers.parse('a new tmpdir')) +def tmpdir(tmpdir_factory): + return tmpdir_factory.mktemp('tmpdir') + + +@bdd.then(bdd.parsers.parse('the file {filename} should exist in the tmpdir')) +def file_exists(quteproc, tmpdir, filename): + path = tmpdir / filename + assert os.path.exists(str(path))