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 }, }
def test_change_link_type(self): self.goals = self.build(open_(1, "Root", [2], select=previous), open_(2, "Top", [], select=selected)) assert self.goals.q(keys="name,edge") == { 1: { "name": "Root", "edge": [(2, EdgeType.PARENT)] }, 2: { "name": "Top", "edge": [] }, } self.goals.accept(ToggleLink()) assert self.goals.q(keys="name,edge") == { 1: { "name": "Root", "edge": [(2, EdgeType.BLOCKER)] }, 2: { "name": "Top", "edge": [] }, } self.goals.accept(ToggleLink(edge_type=EdgeType.PARENT)) assert self.goals.q(keys="name,edge") == { 1: { "name": "Root", "edge": [(2, EdgeType.PARENT)] }, 2: { "name": "Top", "edge": [] }, }
def test_two_parents_for_one_goal_is_forbidden(): with pytest.raises(AssertionError): build_goaltree( open_(1, "First parent of 3", [2, 3]), open_(2, "Second parent of 3", [3]), open_(3, "Fellow child"), )
def tree_3i_goals(): return AutoLink( build_goaltree( open_(1, "Root", [2]), open_(2, "Autolink on me", [3], select=selected), open_(3, "Another subgoal"), ))
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" }, }
def goaltree(): return FilterView( build_goaltree( open_(1, "Alpha", [2], [], selected), open_(2, "Beta", [3]), open_(3, "Gamma", []), ))
def test_how_should_we_deal_with_zooming(): g = build_goaltree( open_(1, "Root", [2]), open_(2, "Zoomed", blockers=[3], select=selected), open_(3, "Ex-top"), ) v = SwitchableView(persistent_layers(g)) v.accept_all(ToggleZoom(), ToggleSwitchableView()) assert v.q("name,select") == { 2: { "name": "Zoomed", "select": "select" }, 3: { "name": "Ex-top", "select": None }, } v.accept(Add("Unexpectedly hidden")) assert v.q("name,select") == { 2: { "name": "Zoomed", "select": "select" }, 3: { "name": "Ex-top", "select": None }, 4: { "name": "Unexpectedly hidden", "select": None }, }
def test_do_not_hide_unswitchable_goals_when_they_have_selection(): v = SwitchableView( build_goaltree( open_(1, "Selected", [2], select=selected), open_(2, "Prev-selected", [3], select=previous), open_(3, "Switchable"), )) v.accept_all(ToggleSwitchableView()) assert v.q("name,switchable,select") == { 1: { "name": "Selected", "switchable": False, "select": "select" }, 2: { "name": "Prev-selected", "switchable": False, "select": "prev" }, 3: { "name": "Switchable", "switchable": True, "select": None }, }
def test_add_link_between_goals(self): self.goals = self.build( open_(1, "Root", [2, 3]), open_(2, "A", select=previous), open_(3, "B", select=selected), ) assert self.goals.q(keys="switchable,edge") == { 1: { "switchable": False, "edge": [(2, EdgeType.PARENT), (3, EdgeType.PARENT)], }, 2: { "switchable": True, "edge": [] }, 3: { "switchable": True, "edge": [] }, } self.goals.accept(ToggleLink()) assert self.goals.q(keys="switchable,edge") == { 1: { "switchable": False, "edge": [(2, EdgeType.PARENT), (3, EdgeType.PARENT)], }, 2: { "switchable": False, "edge": [(3, EdgeType.BLOCKER)] }, 3: { "switchable": True, "edge": [] }, }
def test_insert_goal_between_independent_goals(self): self.goals = self.build( open_(1, "Root", [2, 3]), open_(2, "A", select=previous), open_(3, "B", select=selected), ) self.goals.accept(Insert("Wow")) assert self.goals.q(keys="name,edge,switchable") == { 1: { "name": "Root", "edge": [(2, EdgeType.PARENT), (3, EdgeType.PARENT)], "switchable": False, }, 2: { "name": "A", "edge": [(4, EdgeType.BLOCKER)], "switchable": False }, 3: { "name": "B", "edge": [], "switchable": True }, 4: { "name": "Wow", "edge": [(3, EdgeType.BLOCKER)], "switchable": False }, }
def test_view_edges(self): self.goals = self.build( open_(1, "Root", [2, 3]), open_(2, "A", [4]), open_(3, "B", blockers=[4], select=previous), open_(4, "C", select=selected), ) assert self.goals.q(keys="edge,switchable") == { 1: { "edge": [(2, EdgeType.PARENT), (3, EdgeType.PARENT)], "switchable": False, }, 2: { "edge": [(4, EdgeType.PARENT)], "switchable": False }, 3: { "edge": [(4, EdgeType.BLOCKER)], "switchable": False }, 4: { "edge": [], "switchable": True }, }
def test_message_when_remove_last_link(self): self.goals = self.build( open_(1, "Root", [2]), open_(2, "Middle", [3], select=previous), open_(3, "Top", [], select=selected), ) self.goals.accept(ToggleLink(edge_type=EdgeType.PARENT)) assert len(self.messages) == 1
def test_no_message_when_remove_not_last_link(self): self.goals = self.build( open_(1, "Root", [2, 3], select=previous), open_(2, "Middle", blockers=[3]), open_(3, "Top", [], select=selected), ) self.goals.accept(ToggleLink()) assert self.messages == []
def test_message_on_link_to_self(self): self.goals = self.build( open_(1, "Root", [2]), open_(2, "Middle", [3]), open_(3, "Top", [], select=selected), ) self.goals.accept(ToggleLink()) assert len(self.messages) == 1
def extract_target(): return persistent_layers( build_goaltree( open_(1, "Extract root", [2, 3], select=selected), open_(2, "Subgoal", blockers=[3]), open_(3, "Selected subgoal (selection will be lost)", [4]), clos_(4, "Closed subgoal"), ))
def goaltree(): return ProgressView( build_goaltree( open_(1, "Root", [2, 3], select=selected), open_(2, "With blocker", [], [4]), open_(3, "With subgoal", [4]), open_(4, "Top goal"), ))
def test_no_message_on_allowed_link(self): self.goals = self.build( open_(1, "Root", [2], select=previous), open_(2, "Middle", [3]), open_(3, "Top", [], select=selected), ) self.goals.accept(ToggleLink()) assert self.messages == []
def test_message_when_closed_goal_is_blocked_by_open_one(self): self.goals = self.build( open_(1, "Root", [2, 3]), clos_(2, "Middle", [], select=previous), open_(3, "Top", [], select=selected), ) self.goals.accept(ToggleLink()) assert len(self.messages) == 1
def test_toggle_hide_non_switchable_goals(): g = build_goaltree( open_(1, "Root", [2, 3]), open_(2, "Switchable 1", select=selected), open_(3, "Switchable 2"), ) e = SwitchableView(g) assert e.q(keys="name,switchable,select") == { 1: { "name": "Root", "switchable": False, "select": None }, 2: { "name": "Switchable 1", "switchable": True, "select": "select" }, 3: { "name": "Switchable 2", "switchable": True, "select": None }, } e.accept(ToggleSwitchableView()) assert e.q(keys="name,switchable,select") == { 2: { "name": "Switchable 1", "switchable": True, "select": "select" }, 3: { "name": "Switchable 2", "switchable": True, "select": None }, } e.accept(ToggleSwitchableView()) assert e.q(keys="name,switchable,select") == { 1: { "name": "Root", "switchable": False, "select": None }, 2: { "name": "Switchable 1", "switchable": True, "select": "select" }, 3: { "name": "Switchable 2", "switchable": True, "select": None }, }
def test_delete_single_goal(self): self.goals = self.build(open_(1, "Root", [2]), open_(2, "A", select=selected)) self.goals.accept(Delete()) assert self.goals.q(keys="name,select,switchable") == { 1: { "name": "Root", "select": "select", "switchable": True }, }
def test_enumerated_goals_must_have_the_same_dimension(): e = Enumeration( build_goaltree( open_(1, "a", [2, 20], select=selected), open_(2, "b"), open_(20, "x") ) ) assert e.q(keys="name,switchable,select") == { 1: {"name": "a", "switchable": False, "select": "select"}, 2: {"name": "b", "switchable": True, "select": None}, 3: {"name": "x", "switchable": True, "select": None}, }
def test_change_link_type_events(self): self.goals = self.build( open_(1, "Root", [2, 3]), open_(2, "Lower", blockers=[3], select=previous), open_(3, "Upper", [], select=selected), ) self.goals.accept(ToggleLink(edge_type=EdgeType.PARENT)) assert self.goals.events()[-4] == ("link", 2, 3, EdgeType.PARENT) assert self.goals.events()[-3] == ("unlink", 2, 3, EdgeType.BLOCKER) assert self.goals.events()[-2] == ("link", 1, 3, EdgeType.BLOCKER) assert self.goals.events()[-1] == ("unlink", 1, 3, EdgeType.PARENT)
def test_simple_enumeration_is_not_changed(): e = Enumeration( build_goaltree( open_(1, "a", [2, 3]), open_(2, "b", blockers=[3], select=previous), open_(3, "c", select=selected), ) ) assert e.q(keys="name,edge") == { 1: {"name": "a", "edge": [(2, EdgeType.PARENT), (3, EdgeType.PARENT)]}, 2: {"name": "b", "edge": [(3, EdgeType.BLOCKER)]}, 3: {"name": "c", "edge": []}, }
def test_render_add_fake_vertex(): goals = build_goaltree( open_(1, "Root", [2, 3], select=selected), open_(2, "A", blockers=[3]), open_(3, "B"), ) result = Renderer(goals).build().graph assert get_in(result, "row") == { 3: 0, 2: 1, "1_1": 1, 1: 2, }
def test_use_different_long_edge_types(): goals = build_goaltree( open_(1, "Root", [2], [3], select=selected), open_(2, "A", [3]), open_(3, "B", []), ) result = Renderer(goals).build().graph assert get_in(result, "edge_render") == { 3: [], 2: [(3, EdgeType.PARENT)], "1_1": [(3, EdgeType.BLOCKER)], 1: [(2, EdgeType.PARENT), ("1_1", EdgeType.BLOCKER)], }
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 }, }
def goal_chain_10(): """a → b → c → ... → j""" return build_goaltree( open_(1, "a", [2], select=selected), open_(2, "b", [3]), open_(3, "c", [4]), open_(4, "d", [5]), open_(5, "e", [6]), open_(6, "f", [7]), open_(7, "g", [8]), open_(8, "h", [9]), open_(9, "i", [10]), open_(10, "j", []), )
def test_enumeration_should_not_be_changed_after_delete(self): self.goals = self.build(open_(1, "Root", [2, 3]), open_(2, "A", select=selected), open_(3, "B")) self.goals.accept(Delete()) assert self.goals.q(keys="name,switchable") == { 1: { "name": "Root", "switchable": False }, 3: { "name": "B", "switchable": True }, }
def test_render_4_subgoals_in_a_row(): goals = build_goaltree( open_(1, "Root", [2, 3, 4, 5], select=selected), open_(2, "A"), open_(3, "B"), open_(4, "C"), open_(5, "D"), ) result = Renderer(goals).build().graph assert get_in(result, "row") == { 2: 0, 3: 0, 4: 0, 5: 0, 1: 1, }
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 }, }