Exemplo n.º 1
0
def test_change_progress_on_close(goaltree):
    goaltree.accept_all(ToggleProgress(), Select(4), ToggleClose())
    assert goaltree.q("name") == {
        1: {
            "name": "[1/4] Root"
        },
        2: {
            "name": "[0/1] With blocker"
        },
        3: {
            "name": "[1/2] With subgoal"
        },
        4: {
            "name": "[1/1] Top goal"
        },
    }
    goaltree.accept_all(Select(2), ToggleClose())
    assert goaltree.q("name") == {
        1: {
            "name": "[2/4] Root"
        },
        2: {
            "name": "[1/1] With blocker"
        },
        3: {
            "name": "[1/2] With subgoal"
        },
        4: {
            "name": "[1/1] Top goal"
        },
    }
Exemplo n.º 2
0
 def test_toggle_close_events(self):
     self.goals.accept(ToggleClose())
     assert self.goals.events()[-3] == ("toggle_close", False, 1)
     assert self.goals.events()[-2] == ("select", 1)
     assert self.goals.events()[-1] == ("hold_select", 1)
     self.goals.accept(ToggleClose())
     assert self.goals.events()[-1] == ("toggle_close", True, 1)
Exemplo n.º 3
0
 def test_close_goal_again(self):
     self.goals = self.build(
         open_(1, "Root", [2], select=selected),
         open_(2, "A", [3]),
         clos_(3, "Ab"),
     )
     self.goals.accept_all(Select(2), ToggleClose())
     assert self.goals.q(keys="open,switchable") == {
         1: {
             "open": True,
             "switchable": True
         },
         2: {
             "open": False,
             "switchable": True
         },
         3: {
             "open": False,
             "switchable": False
         },
     }
     self.goals.accept_all(Select(2), ToggleClose())
     assert self.goals.q(keys="open,switchable") == {
         1: {
             "open": True,
             "switchable": False
         },
         2: {
             "open": True,
             "switchable": True
         },
         3: {
             "open": False,
             "switchable": True
         },
     }
     self.goals.accept_all(Select(2), ToggleClose())
     assert self.goals.q(keys="open,switchable") == {
         1: {
             "open": True,
             "switchable": True
         },
         2: {
             "open": False,
             "switchable": True
         },
         3: {
             "open": False,
             "switchable": False
         },
     }
Exemplo n.º 4
0
 def test_move_selection_to_another_open_goal_with_given_root_after_closing(
         self):
     self.goals = self.build(
         open_(1, "Root", [2, 3]),
         open_(2, "Should not be selected"),
         open_(3, "Subroot", [4, 5]),
         open_(4, "Must be selected"),
         open_(5, "Closing", select=selected),
     )
     self.goals.accept(ToggleClose(3))
     assert self.goals.q(keys="open,select") == {
         1: {
             "open": True,
             "select": None
         },
         2: {
             "open": True,
             "select": None
         },
         3: {
             "open": True,
             "select": None
         },
         4: {
             "open": True,
             "select": "select"
         },
         5: {
             "open": False,
             "select": None
         },
     }
Exemplo n.º 5
0
 def test_closed_leaf_goal_could_not_be_reopened(self):
     self.goals = self.build(open_(1, "Root", [2], select=selected),
                             clos_(2, "A", [3]), clos_(3, "B"))
     assert self.goals.q(keys="open,switchable") == {
         1: {
             "open": True,
             "switchable": True
         },
         2: {
             "open": False,
             "switchable": True
         },
         3: {
             "open": False,
             "switchable": False
         },
     }
     self.goals.accept_all(Select(3), ToggleClose())
     # nothing should change
     assert self.goals.q(keys="open,switchable") == {
         1: {
             "open": True,
             "switchable": True
         },
         2: {
             "open": False,
             "switchable": True
         },
         3: {
             "open": False,
             "switchable": False
         },
     }
Exemplo n.º 6
0
def test_remove_autolink_on_close(tree_2_goals):
    goals = tree_2_goals
    goals.accept(ToggleAutoLink("test"))
    assert goals.q("edge,open") == {
        1: {
            "edge": [(-12, EdgeType.PARENT)],
            "open": True
        },
        -12: {
            "edge": [(2, EdgeType.PARENT)],
            "open": True
        },
        2: {
            "edge": [],
            "open": True
        },
    }
    goals.accept(ToggleClose())
    assert goals.q("edge,open") == {
        1: {
            "edge": [(2, EdgeType.PARENT)],
            "open": True
        },
        2: {
            "edge": [],
            "open": False
        },
    }
    assert _autolink_events(goals) == [
        ("add_autolink", 2, "test"),
        ("remove_autolink", 2),
    ]
Exemplo n.º 7
0
def build_actions(command):
    simple_commands = {
        "c": ToggleClose(),
        "d": Delete(),
        "h": HoldSelect(),
        "k": ToggleLink(edge_type=EdgeType.PARENT),
        "l": ToggleLink(),
        "n": ToggleOpenView(),
        "p": ToggleProgress(),
        "t": ToggleSwitchableView(),
        "z": ToggleZoom(),
    }
    if command and all(c in "1234567890" for c in command):
        return [Select(int(c)) for c in command]
    if command.startswith("a "):
        return [Add(command[2:])]
    if command.startswith("i "):
        return [Insert(command[2:])]
    if command.startswith("r "):
        return [Rename(command[2:])]
    if command.startswith("f"):
        return [FilterBy(command[1:].lstrip())]
    if command.startswith("` "):
        return [ToggleAutoLink(command[2:])]
    if command in simple_commands:
        return [simple_commands[command]]
    return []
Exemplo n.º 8
0
 def test_move_selection_to_previously_selected_goal_after_closing(self):
     self.goals = self.build(
         open_(1, "Root", [2, 3, 4]),
         open_(2, "A", select=selected),
         open_(3, "B"),
         open_(4, "C", select=previous),
     )
     self.goals.accept(ToggleClose())
     assert self.goals.q(keys="open,select") == {
         1: {
             "open": True,
             "select": None
         },
         2: {
             "open": False,
             "select": None
         },
         3: {
             "open": True,
             "select": None
         },
         4: {
             "open": True,
             "select": "select"
         },
     }
Exemplo n.º 9
0
 def test_close_single_goal(self):
     assert self.goals.q(keys="name,open") == {
         1: {
             "name": "Root",
             "open": True
         }
     }
     self.goals.accept(ToggleClose())
     assert self.goals.q(keys="name,open,switchable") == {
         1: {
             "name": "Root",
             "open": False,
             "switchable": True
         }
     }
Exemplo n.º 10
0
def test_simple_open_enumeration_workflow():
    e = OpenView(
        build_goaltree(
            open_(1, "Root", [2, 3], select=previous),
            open_(2, "1", select=selected),
            open_(3, "2"),
        ))
    assert e.q(keys="name,select,open,edge") == {
        1: {
            "name": "Root",
            "select": "prev",
            "open": True,
            "edge": [(2, EdgeType.PARENT), (3, EdgeType.PARENT)],
        },
        2: {
            "name": "1",
            "select": "select",
            "open": True,
            "edge": []
        },
        3: {
            "name": "2",
            "select": None,
            "open": True,
            "edge": []
        },
    }
    e.accept(ToggleClose())
    assert e.q(keys="name,select,open,edge") == {
        1: {
            "name": "Root",
            "select": "select",
            "open": True,
            "edge": [(3, EdgeType.PARENT)],
        },
        3: {
            "name": "2",
            "select": None,
            "open": True,
            "edge": []
        },
    }
Exemplo n.º 11
0
 def test_goal_in_the_middle_could_not_be_closed(self):
     self.goals = self.build(
         open_(1, "Root", [2, 3]),
         open_(2, "A", blockers=[4]),
         open_(3, "B", [4], select=selected),
         open_(4, "C"),
     )
     self.goals.accept(ToggleClose())
     assert self.goals.q(keys="open") == {
         1: {
             "open": True
         },
         2: {
             "open": True
         },
         3: {
             "open": True
         },
         4: {
             "open": True
         },
     }
Exemplo n.º 12
0
 def test_reopen_goal(self):
     self.goals = self.build(open_(1, "Root", [2]),
                             clos_(2, "A", select=selected))
     assert self.goals.q(keys="open") == {
         1: {
             "open": True
         },
         2: {
             "open": False
         }
     }
     self.goals.accept(ToggleClose())
     assert self.goals.q(keys="open,switchable") == {
         1: {
             "open": True,
             "switchable": False
         },
         2: {
             "open": True,
             "switchable": True
         },
     }
Exemplo n.º 13
0
def test_save_and_load():
    file_name = NamedTemporaryFile().name
    goals = Enumeration(all_layers(Goals("Root")))
    goals.accept_all(
        Add("Top"),
        Add("Middle"),
        Select(3),
        HoldSelect(),
        Select(2),
        ToggleLink(),
        Add("Closed"),
        Select(4),
        ToggleClose(),
        Select(2),
        ToggleZoom(),
    )
    save(goals, file_name)
    new_goals = load(file_name)
    goals.accept_all(ToggleOpenView())
    new_goals.accept_all(ToggleOpenView())
    assert goals.q(keys="open,name,edge,select,switchable") == new_goals.q(
        keys="open,name,edge,select,switchable")
Exemplo n.º 14
0
 def test_do_not_select_unswitchable_goal_after_closing(self):
     self.goals = self.build(
         open_(1, "Root", [2, 3]),
         open_(2, "Should not be selected"),
         open_(3, "Subroot", [4, 5]),
         open_(4, "intermediate", [6]),
         open_(5, "Closing", select=selected),
         open_(6, "Must be selected"),
     )
     self.goals.accept(ToggleClose(3))
     assert self.goals.q(keys="open,select") == {
         1: {
             "open": True,
             "select": None
         },
         2: {
             "open": True,
             "select": None
         },
         3: {
             "open": True,
             "select": None
         },
         4: {
             "open": True,
             "select": None
         },
         5: {
             "open": False,
             "select": None
         },
         6: {
             "open": True,
             "select": "select"
         },
     }
Exemplo n.º 15
0
def test_restore_goals_from_db():
    file_name = NamedTemporaryFile().name
    with sqlite3.connect(file_name) as conn:
        run_migrations(conn)
        setup_sample_db(conn)
    actual_goals = load(file_name)
    actual_goals.accept(ToggleOpenView())
    expected_goals = Goals("Root")
    expected_goals.accept_all(
        Add("A"),
        Add("B"),
        Select(2),
        HoldSelect(),
        Select(3),
        ToggleLink(),
        Select(3),
        ToggleClose(),
        Select(1),
        HoldSelect(),
        Select(2),
    )
    keys = "name,edge,open,select"
    assert expected_goals.q(keys=keys) == actual_goals.q(keys=keys)
    assert not actual_goals.events()
Exemplo n.º 16
0
 def keyPressEvent(self, event):
     key_handlers = {
         Qt.Key_1:
         self.select_number(1),
         Qt.Key_2:
         self.select_number(2),
         Qt.Key_3:
         self.select_number(3),
         Qt.Key_4:
         self.select_number(4),
         Qt.Key_5:
         self.select_number(5),
         Qt.Key_6:
         self.select_number(6),
         Qt.Key_7:
         self.select_number(7),
         Qt.Key_8:
         self.select_number(8),
         Qt.Key_9:
         self.select_number(9),
         Qt.Key_0:
         self.select_number(0),
         Qt.Key_A:
         self.start_edit("Add new goal", self.emit_add),
         Qt.Key_C:
         self.with_refresh(self.goals.accept, ToggleClose()),
         Qt.Key_D:
         self.with_refresh(self.goals.accept, Delete()),
         Qt.Key_F:
         self.start_edit(
             "Filter by substring (leave empty to reset filtration)",
             self.emit_filter,
         ),
         Qt.Key_I:
         self.start_edit("Insert new goal", self.emit_insert),
         Qt.Key_K:
         self.with_refresh(self.goals.accept,
                           ToggleLink(edge_type=EdgeType.PARENT)),
         Qt.Key_L:
         self.with_refresh(self.goals.accept, ToggleLink()),
         Qt.Key_N:
         self.with_refresh(self.toggle_open_view, True),
         Qt.Key_O:
         self.show_open_dialog,
         Qt.Key_P:
         self.with_refresh(self.toggle_progress_view, True),
         Qt.Key_Q:
         self.quit_app.emit,
         Qt.Key_R:
         self.start_edit("Rename goal", self.emit_rename,
                         self._current_goal_label),
         Qt.Key_T:
         self.with_refresh(self.toggle_switchable_view, True),
         Qt.Key_Z:
         self.toggle_zoom,
         Qt.Key_QuoteLeft:
         self.start_edit(
             "Auto link by keyword (leave empty to reset auto link)",
             self.emit_autolink,
         ),
         Qt.Key_Escape:
         self.cancel_edit,
         Qt.Key_Minus:
         self.with_refresh(self.change_columns, -1),
         Qt.Key_Plus:
         self.with_refresh(self.change_columns, 1),
         Qt.Key_Slash:
         self.show_keys_help,
         Qt.Key_Space:
         self.with_refresh(self.goals.accept, HoldSelect()),
     }
     if event.key() in key_handlers:
         key_handlers[event.key()]()
     else:
         super().keyPressEvent(event)
Exemplo n.º 17
0
 def test_message_on_reopening_blocked_goal(self):
     self.goals = self.build(clos_(1, "Root", [2]),
                             clos_(2, "Top", [], select=selected))
     self.goals.accept(ToggleClose())
     assert len(self.messages) == 1
Exemplo n.º 18
0
 def accept_ToggleClose(self, command: ToggleClose):
     if self.settings("selection") == self.zoom_root[-1]:
         self.accept_ToggleZoom(ToggleZoom())
     # Note: zoom_root may be changed inside accept_ToggleZoom
     self.goaltree.accept(ToggleClose(self.zoom_root[-1]))
Exemplo n.º 19
0
 def inner():
     self.goals.accept_all(Select(goal_id), ToggleClose())
     self.refresh.emit()
Exemplo n.º 20
0
 def test_no_message_on_valid_closing(self):
     self.goals = self.build(open_(1, "Root", [2]),
                             open_(2, "Top", [], select=selected))
     self.goals.accept(ToggleClose())
     assert self.messages == []
Exemplo n.º 21
0
 def test_no_message_on_valid_reopening(self):
     self.goals = self.build(clos_(1, "Root", [2], select=selected),
                             clos_(2, "Top"))
     self.goals.accept(ToggleClose())
     assert self.messages == []
Exemplo n.º 22
0
 def test_message_on_closing_blocked_goal(self):
     self.goals = self.build(open_(1, "Root", [2], select=selected),
                             open_(2, "Top"))
     self.goals.accept(ToggleClose())
     assert len(self.messages) == 1
Exemplo n.º 23
0
 def close_or_open(self):
     event("close/open")
     self._accept(ToggleClose())