diff options
author | toofar <toofar@spalge.com> | 2024-01-30 08:19:57 +1300 |
---|---|---|
committer | pylbrecht <pylbrecht@mailbox.org> | 2024-02-07 20:22:21 +0100 |
commit | db61de8e8412fc7948a7e1a01f8dfde2c9dd6b73 (patch) | |
tree | 5de82fecdc1ce81e461aa356d48a3fa883f9fe38 | |
parent | 40823c6cb33f13608b739ecebace295026311215 (diff) | |
download | qutebrowser-db61de8e8412fc7948a7e1a01f8dfde2c9dd6b73.tar.gz qutebrowser-db61de8e8412fc7948a7e1a01f8dfde2c9dd6b73.zip |
Create simplified string representation from tree tab session
Recurse through the tree structure and build up a simplified string
representation of a window in a tree tab session so we can compare it to a
test fixture. It should look something like this:
- about:blank?one
- about:blank?child (collapsed)
- about:blank?grandchild
- about:blank?childtwo (active)
- about:blank?two
TODO:
* align with `check_open_tabs()` - I think we should be able to adapt that
one to be the same format as this. Eg construct a string from the session
and then compare the two strings line by line. Then the comparison
shouldn't need to care if it's a tree or not. `tree_to_str()` could maybe
be made more generic too, or at least pull the "flat tab to str" bit out of
it and then slap the tree bit on afterwards if needed
* now we've got three individual suffixes handling them one by one is a bit of
a pain, can we put them in a dict and iterate over that instead?
* add some sanity checks instead of blindly doing array indexing etc, I think
it's hard to get stack traces from generators?
-rw-r--r-- | tests/end2end/features/conftest.py | 44 |
1 files changed, 37 insertions, 7 deletions
diff --git a/tests/end2end/features/conftest.py b/tests/end2end/features/conftest.py index c883e4f58..f3220282b 100644 --- a/tests/end2end/features/conftest.py +++ b/tests/end2end/features/conftest.py @@ -617,6 +617,7 @@ def check_open_tree_tabs(quteproc, request, tabs): # TODO: support ' (collapsed)', also maybe make suffixes generic? active_suffix = ' (active)' pinned_suffix = ' (pinned)' + collapsed_suffix = ' (collapsed)' tabs = tabs.splitlines() assert len(session['windows']) == 1 assert len(session['windows'][0]['tabs']) == len(tabs) @@ -626,16 +627,45 @@ def check_open_tree_tabs(quteproc, request, tabs): has_pinned = any(pinned_suffix in line for line in tabs) - from qutebrowser.misc import sessions - tree_data = sessions.SessionManager._reconstruct_tree_data(None, session['windows'][0]) - # TODO: iterate/recurse through tree_data and build a string of the same # format we are putting in the test fixtures - root = [v for v in tree_data.values() if "treetab_node_data" not in v][0] - expected = "" - for uid in root["children"]: - ... + def tree_to_str(node, indentation=-1): + tree_node = node.get("treetab_node_data") + if tree_node: # root node doesn't have a tree data structure + current = [ + entry + for entry in node["history"] + if entry.get("active") + ][0] + text = f"{' ' * indentation}- {current['url']}" + for suffix, state in { + active_suffix: node.get("active"), + pinned_suffix: current["pinned"], + collapsed_suffix: tree_node["collapsed"], + }.items(): + if state: + text += suffix + + yield text + else: + tree_node = node + + for uid in tree_node["children"]: + yield from tree_to_str(tree_data[uid], indentation + 1) + + is_tree_tab_window = "treetab_root" in session["windows"][0] + if is_tree_tab_window: + from qutebrowser.misc import sessions + tree_data = sessions.SessionManager._reconstruct_tree_data(None, session['windows'][0]) + + root = [v for v in tree_data.values() if "treetab_node_data" not in v][0] + expected = "\n".join(tree_to_str(root)) + else: + pass # TODO: support "flat" tab windows too + + import pdbr + pdbr.set_trace() # Then copy the remaining parts from check_open_tabs() and probably change # it to support more leading spaces |