From 70697b8d9702356f9d2d006e241b1ca37b7df9e2 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Tue, 14 Jun 2022 13:25:11 +0200 Subject: tests: Make it possible to pass flags when saving session --- tests/end2end/features/conftest.py | 9 ++++++++- tests/end2end/fixtures/quteprocess.py | 10 +++++----- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/tests/end2end/features/conftest.py b/tests/end2end/features/conftest.py index 2bb3d5079..4504b4f20 100644 --- a/tests/end2end/features/conftest.py +++ b/tests/end2end/features/conftest.py @@ -533,7 +533,7 @@ def javascript_message_not_logged(quteproc, message): @bdd.then(bdd.parsers.parse("The session should look like:\n{expected}")) -def compare_session(request, quteproc, expected): +def compare_session(quteproc, expected): """Compare the current sessions against the given template. partial_compare is used, which means only the keys/values listed will be @@ -542,6 +542,13 @@ def compare_session(request, quteproc, expected): quteproc.compare_session(expected) +@bdd.then( + bdd.parsers.parse("The session saved with {flags} should look like:\n{expected}")) +def compare_session_flags(quteproc, flags, expected): + """Compare the current session saved with custom flags.""" + quteproc.compare_session(expected, flags=flags) + + @bdd.then("no crash should happen") def no_crash(): """Don't do anything. diff --git a/tests/end2end/fixtures/quteprocess.py b/tests/end2end/fixtures/quteprocess.py index ab8f28d26..6e47814fd 100644 --- a/tests/end2end/fixtures/quteprocess.py +++ b/tests/end2end/fixtures/quteprocess.py @@ -873,13 +873,13 @@ class QuteProc(testprocess.Process): self.wait_for_load_finished_url(url, timeout=timeout, load_status=load_status) - def get_session(self): + def get_session(self, flags="--with-private"): """Save the session and get the parsed session data.""" with tempfile.TemporaryDirectory() as tdir: session = pathlib.Path(tdir) / 'session.yml' - self.send_cmd(':session-save --with-private "{}"'.format(session)) + self.send_cmd(f':session-save {flags} "{session}"') self.wait_for(category='message', loglevel=logging.INFO, - message='Saved session {}.'.format(session)) + message=f'Saved session {session}.') data = session.read_text(encoding='utf-8') self._log('\nCurrent session data:\n' + data) @@ -966,14 +966,14 @@ class QuteProc(testprocess.Process): raise ValueError('Invalid response from qutebrowser: {}' .format(message)) - def compare_session(self, expected): + def compare_session(self, expected, *, flags="--with-private"): """Compare the current sessions against the given template. partial_compare is used, which means only the keys/values listed will be compared. """ __tracebackhide__ = lambda e: e.errisinstance(pytest.fail.Exception) - data = self.get_session() + data = self.get_session(flags=flags) expected = yaml.load(expected, Loader=YamlLoader) outcome = testutils.partial_compare(data, expected) if not outcome: -- cgit v1.2.3-54-g00ecf