Exemplo n.º 1
0
def test_use_mapping_in_selection():
    goals = Goals('a')
    for i, c in enumerate('bcdefghij'):
        goals.add(c)
        goals.select(i + 2)
    e = Enumeration(goals)
    e.select(0)
    assert e.all(keys='name,select') == {
        1: {'name': 'a', 'select': 'prev'},
        2: {'name': 'b', 'select': None},
        3: {'name': 'c', 'select': None},
        4: {'name': 'd', 'select': None},
        5: {'name': 'e', 'select': None},
        6: {'name': 'f', 'select': None},
        7: {'name': 'g', 'select': None},
        8: {'name': 'h', 'select': None},
        9: {'name': 'i', 'select': None},
        0: {'name': 'j', 'select': 'select'},
    }
    e.add('k')
    e.select(1)
    e.select(6)
    assert e.all(keys='name,select') == {
        11: {'name': 'a', 'select': 'prev'},
        12: {'name': 'b', 'select': None},
        13: {'name': 'c', 'select': None},
        14: {'name': 'd', 'select': None},
        15: {'name': 'e', 'select': None},
        16: {'name': 'f', 'select': 'select'},
        17: {'name': 'g', 'select': None},
        18: {'name': 'h', 'select': None},
        19: {'name': 'i', 'select': None},
        10: {'name': 'j', 'select': None},
        21: {'name': 'k', 'select': None},
    }
Exemplo n.º 2
0
def test_apply_mapping_for_the_10th_element():
    goals = Goals('a')
    for i, c in enumerate('bcdefghij'):
        goals.add(c)
        goals.select(i + 2)
    e = Enumeration(goals)
    assert e.all(keys='name,edge') == {
        1: {'name': 'a', 'edge': [2]},
        2: {'name': 'b', 'edge': [3]},
        3: {'name': 'c', 'edge': [4]},
        4: {'name': 'd', 'edge': [5]},
        5: {'name': 'e', 'edge': [6]},
        6: {'name': 'f', 'edge': [7]},
        7: {'name': 'g', 'edge': [8]},
        8: {'name': 'h', 'edge': [9]},
        9: {'name': 'i', 'edge': [0]},
        0: {'name': 'j', 'edge': []},
    }
    # simulate goal addition
    goals.select(1)
    goals.add('k')
    assert e.all(keys='name,edge') == {
        11: {'name': 'a', 'edge': [12, 21]},
        12: {'name': 'b', 'edge': [13]},
        13: {'name': 'c', 'edge': [14]},
        14: {'name': 'd', 'edge': [15]},
        15: {'name': 'e', 'edge': [16]},
        16: {'name': 'f', 'edge': [17]},
        17: {'name': 'g', 'edge': [18]},
        18: {'name': 'h', 'edge': [19]},
        19: {'name': 'i', 'edge': [10]},
        10: {'name': 'j', 'edge': []},
        21: {'name': 'k', 'edge': []},
    }
Exemplo n.º 3
0
def test_dot_export_open_view():
    g = Enumeration(Goals('Root'))
    g.add('Middle')
    g.add('Top', 2)
    g.add('Closed')
    g.select(4)
    g.toggle_close()
    assert dot_export(g) == '''digraph g {
Exemplo n.º 4
0
def test_all_keys_in_enumeration_must_be_of_the_same_length():
    g = Goals('Root')
    for i in range(2999):
        g.add(str(i))
    e = Enumeration(g)
    mapping = e.all()
    assert len(mapping) == len(g.all())
    assert set(len(str(k)) for k in mapping) == {4}
Exemplo n.º 5
0
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},
    }
Exemplo n.º 6
0
def test_mapping_for_top():
    goals = Goals('a')
    goals.add('b')
    for i, c in enumerate('cdefghijklmnopqrstuv'):
        goals.add(c)
        goals.delete(i + 3)         # 1: a, 2: b, 3 (i==0): c, 4 (i==1): d, ...
    goals.add('x')
    e = Enumeration(goals)
    assert e.all(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},
    }
Exemplo n.º 7
0
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": []},
    }
Exemplo n.º 8
0
def test_select_goal_by_full_id_with_non_empty_cache():
    goals = Goals('a')
    for c in 'bcdefghijk':
        goals.add(c)
    e = Enumeration(goals)
    assert e.all(keys='name,select') == {
        11: {'name': 'a', 'select': 'select'},
        12: {'name': 'b', 'select': None},
        13: {'name': 'c', 'select': None},
        14: {'name': 'd', 'select': None},
        15: {'name': 'e', 'select': None},
        16: {'name': 'f', 'select': None},
        17: {'name': 'g', 'select': None},
        18: {'name': 'h', 'select': None},
        19: {'name': 'i', 'select': None},
        10: {'name': 'j', 'select': None},
        21: {'name': 'k', 'select': None},
    }
    e.select(2)
    e.select(13)
    assert e.all(keys='name,select') == {
        11: {'name': 'a', 'select': 'prev'},
        12: {'name': 'b', 'select': None},
        13: {'name': 'c', 'select': 'select'},
        14: {'name': 'd', 'select': None},
        15: {'name': 'e', 'select': None},
        16: {'name': 'f', 'select': None},
        17: {'name': 'g', 'select': None},
        18: {'name': 'h', 'select': None},
        19: {'name': 'i', 'select': None},
        10: {'name': 'j', 'select': None},
        21: {'name': 'k', 'select': None},
    }
Exemplo n.º 9
0
def test_simple_enumeration_is_not_changed():
    goals = Goals('a')
    goals.add('b')
    goals.add('c')
    goals.select(2)
    goals.hold_select()
    goals.select(3)
    goals.toggle_link()
    e = Enumeration(goals)
    assert e.all(keys='name,edge') == {
        1: {'name': 'a', 'edge': [2, 3]},
        2: {'name': 'b', 'edge': [3]},
        3: {'name': 'c', 'edge': []},
    }
Exemplo n.º 10
0
def test_apply_mapping_for_the_10th_element(goal_chain_10):
    e = Enumeration(goal_chain_10)
    assert e.q(keys="name,edge") == {
        1: {"name": "a", "edge": [(2, EdgeType.PARENT)]},
        2: {"name": "b", "edge": [(3, EdgeType.PARENT)]},
        3: {"name": "c", "edge": [(4, EdgeType.PARENT)]},
        4: {"name": "d", "edge": [(5, EdgeType.PARENT)]},
        5: {"name": "e", "edge": [(6, EdgeType.PARENT)]},
        6: {"name": "f", "edge": [(7, EdgeType.PARENT)]},
        7: {"name": "g", "edge": [(8, EdgeType.PARENT)]},
        8: {"name": "h", "edge": [(9, EdgeType.PARENT)]},
        9: {"name": "i", "edge": [(0, EdgeType.PARENT)]},
        0: {"name": "j", "edge": []},
    }
Exemplo n.º 11
0
def test_render_in_switchable_view():
    goals = build_goaltree(
        open_(1, "Uno", [2, 3, 4, 5, 6]),
        open_(2, "Dos"),
        open_(3, "Tres"),
        open_(4, "Quatro"),
        open_(5, "Cinco"),
        open_(6, "Sext", select=selected),
    )
    view = Enumeration(SwitchableView(goals))
    view.accept(ToggleSwitchableView())
    result = Renderer(view).build().graph
    # Just verify that it renders fine
    assert len(result) == 5
Exemplo n.º 12
0
def test_use_mapping_in_selection(goal_chain_10):
    e = Enumeration(goal_chain_10)
    e.accept(Select(0))
    assert e.q(keys="name,select") == {
        1: {"name": "a", "select": "prev"},
        2: {"name": "b", "select": None},
        3: {"name": "c", "select": None},
        4: {"name": "d", "select": None},
        5: {"name": "e", "select": None},
        6: {"name": "f", "select": None},
        7: {"name": "g", "select": None},
        8: {"name": "h", "select": None},
        9: {"name": "i", "select": None},
        0: {"name": "j", "select": "select"},
    }
Exemplo n.º 13
0
def test_apply_mapping_for_the_11th_element(goal_chain_11):
    e = Enumeration(goal_chain_11)
    assert e.q(keys="name,edge") == {
        11: {"name": "a", "edge": [(12, EdgeType.PARENT)]},
        12: {"name": "b", "edge": [(13, EdgeType.PARENT)]},
        13: {"name": "c", "edge": [(14, EdgeType.PARENT)]},
        14: {"name": "d", "edge": [(15, EdgeType.PARENT)]},
        15: {"name": "e", "edge": [(16, EdgeType.PARENT)]},
        16: {"name": "f", "edge": [(17, EdgeType.PARENT)]},
        17: {"name": "g", "edge": [(18, EdgeType.PARENT)]},
        18: {"name": "h", "edge": [(19, EdgeType.PARENT)]},
        19: {"name": "i", "edge": [(10, EdgeType.PARENT)]},
        10: {"name": "j", "edge": [(21, EdgeType.PARENT)]},
        21: {"name": "k", "edge": []},
    }
Exemplo n.º 14
0
def test_simple_open_enumeration_workflow():
    e = Enumeration(Goals('Root'))
    e.add('1')
    e.add('2')
    e.select(2)
    assert e.all(keys='name,select,open,edge') == {
        1: {'name': 'Root', 'select': 'prev', 'open': True, 'edge': [2, 3]},
        2: {'name': '1', 'select': 'select', 'open': True, 'edge': []},
        3: {'name': '2', 'select': None, 'open': True, 'edge': []},
    }
    e.toggle_close()
    assert e.all(keys='name,select,open,edge') == {
        1: {'name': 'Root', 'select': 'select', 'open': True, 'edge': [2]},
        2: {'name': '2', 'select': None, 'open': True, 'edge': []}
    }
Exemplo n.º 15
0
def test_select_goal_by_id_parts(goal_chain_11):
    e = Enumeration(goal_chain_11)
    e.accept_all(Select(1), Select(6))
    assert e.q(keys="name,select") == {
        11: {"name": "a", "select": "prev"},
        12: {"name": "b", "select": None},
        13: {"name": "c", "select": None},
        14: {"name": "d", "select": None},
        15: {"name": "e", "select": None},
        16: {"name": "f", "select": "select"},
        17: {"name": "g", "select": None},
        18: {"name": "h", "select": None},
        19: {"name": "i", "select": None},
        10: {"name": "j", "select": None},
        21: {"name": "k", "select": None},
    }
Exemplo n.º 16
0
def test_any_goal_may_be_selected_through_enumeration(actions, ch, choice):
    g = build_from(actions, ch)
    e = Enumeration(g)
    e.next_view()
    e.next_view()
    rnd_goal = choice(list(e.all().keys()))
    for i in str(rnd_goal):
        e.select(int(i))
    assert e.all(keys='select')[rnd_goal]['select'] == 'select'
Exemplo n.º 17
0
def test_toggle_switch_view():
    e = Enumeration(Goals('Root'))
    assert e.view == 'open'
    e.next_view()
    assert e.view == 'top'
    e.next_view()
    assert e.view == 'full'
    e.next_view()
    assert e.view == 'open'
Exemplo n.º 18
0
def test_do_not_enumerate_goals_with_negative_id():
    g = PseudoZoomedGoals('Root')
    g.add('Zoomed')
    g.select(2)
    g.hold_select()
    g.add('Top')
    assert g.all('name,select,edge') == {
        -1: {'name': 'Root', 'select': None, 'edge': [2]},
        2: {'name': 'Zoomed', 'select': 'select', 'edge': [3]},
        3: {'name': 'Top', 'select': None, 'edge': []},
    }
    e = Enumeration(g)
    assert e.all('name,select,edge') == {
        -1: {'name': 'Root', 'select': None, 'edge': [1]},
        1: {'name': 'Zoomed', 'select': 'select', 'edge': [2]},
        2: {'name': 'Top', 'select': None, 'edge': []},
    }
Exemplo n.º 19
0
def test_do_not_select_goal_by_partial_id(goal_chain_11):
    e = Enumeration(goal_chain_11)
    # Select(1) is kept in cache, and selection is not changed yet
    e.accept_all(Select(1))
    assert e.q(keys="name,select") == {
        11: {"name": "a", "select": "select"},
        12: {"name": "b", "select": None},
        13: {"name": "c", "select": None},
        14: {"name": "d", "select": None},
        15: {"name": "e", "select": None},
        16: {"name": "f", "select": None},
        17: {"name": "g", "select": None},
        18: {"name": "h", "select": None},
        19: {"name": "i", "select": None},
        10: {"name": "j", "select": None},
        21: {"name": "k", "select": None},
    }
Exemplo n.º 20
0
def test_selection_cache_should_be_reset_after_view_switch():
    g = Goals('Root')
    # 1 -> 2 -> 3 -> .. -> 10 -> 11
    for i in range(10):
        g.add(str(i+2), i+1)
    g.add('Also top', 1)
    e = Enumeration(g)
    e.select(1)
    e.next_view()
    assert e.all('name,select') == {
        1: {'name': '11', 'select': 'select'},
        2: {'name': 'Also top', 'select': None},
    }
    e.select(2)
    assert e.all('name,select') == {
        1: {'name': '11', 'select': 'prev'},
        2: {'name': 'Also top', 'select': 'select'},
    }
Exemplo n.º 21
0
def test_do_not_enumerate_goals_with_negative_id():
    g = all_layers(
        build_goaltree(
            open_(1, "Root", [2]),
            open_(2, "Zoomed", [3], select=selected),
            open_(3, "Top"),
        )
    )
    g.accept(ToggleZoom())
    assert g.q("name,select,edge") == {
        -1: {"name": "Root", "select": None, "edge": [(2, EdgeType.BLOCKER)]},
        2: {"name": "Zoomed", "select": "select", "edge": [(3, EdgeType.PARENT)]},
        3: {"name": "Top", "select": None, "edge": []},
    }
    e = Enumeration(g)
    assert e.q("name,select,edge") == {
        -1: {"name": "Root", "select": None, "edge": [(1, EdgeType.BLOCKER)]},
        1: {"name": "Zoomed", "select": "select", "edge": [(2, EdgeType.PARENT)]},
        2: {"name": "Top", "select": None, "edge": []},
    }
Exemplo n.º 22
0
def test_select_goal_by_full_id_with_non_empty_cache(goal_chain_11):
    e = Enumeration(goal_chain_11)
    assert e.q(keys="name,select") == {
        11: {"name": "a", "select": "select"},
        12: {"name": "b", "select": None},
        13: {"name": "c", "select": None},
        14: {"name": "d", "select": None},
        15: {"name": "e", "select": None},
        16: {"name": "f", "select": None},
        17: {"name": "g", "select": None},
        18: {"name": "h", "select": None},
        19: {"name": "i", "select": None},
        10: {"name": "j", "select": None},
        21: {"name": "k", "select": None},
    }
    e.accept_all(Select(2), Select(13))
    assert e.q(keys="name,select") == {
        11: {"name": "a", "select": "prev"},
        12: {"name": "b", "select": None},
        13: {"name": "c", "select": "select"},
        14: {"name": "d", "select": None},
        15: {"name": "e", "select": None},
        16: {"name": "f", "select": None},
        17: {"name": "g", "select": None},
        18: {"name": "h", "select": None},
        19: {"name": "i", "select": None},
        10: {"name": "j", "select": None},
        21: {"name": "k", "select": None},
    }
Exemplo n.º 23
0
def load(filename=DEFAULT_DB):
    if path.isfile(filename):
        connection = sqlite3.connect(filename)
        run_migrations(connection)
        cur = connection.cursor()
        goals = [row for row in cur.execute('select * from goals')]
        edges = [row for row in cur.execute('select * from edges')]
        settings = [row for row in cur.execute('select * from settings')]
        cur.close()
        goals = Goals.build(goals, edges, settings)
    else:
        goals = Goals('Rename me')
    return Enumeration(Zoom(goals))
Exemplo n.º 24
0
def extract_source():
    # Legend: goals marked with 'NX' must not be extracted
    return Enumeration(
        all_layers(
            build_goaltree(
                open_(1, "Root NX", [2, 3], select=selected),
                open_(2, "Extract root", [4, 5], blockers=[3]),
                open_(3, "External blocker NX", [7]),
                open_(4, "Subgoal", blockers=[5]),
                open_(
                    5,
                    "Selected subgoal (selection will be lost)",
                    [6],
                    select=previous,
                ),
                clos_(6, "Closed subgoal", blockers=[7]),
                clos_(7, "Another external blocker NX"),
            )))
Exemplo n.º 25
0
def test_extract_misordered():
    source = Enumeration(
        all_layers(
            build_goaltree(
                open_(1, "Global root", [3], select=selected),
                open_(2, "Top"),
                open_(3, "Extraction root", [2]),
            )))
    result = extract_subtree(source, 3)
    assert result.q("name,edge") == {
        1: {
            "name": "Extraction root",
            "edge": [(2, EdgeType.PARENT)]
        },
        2: {
            "name": "Top",
            "edge": []
        },
    }
Exemplo n.º 26
0
def test_goaltree_selection_may_be_changed_in_top_view():
    goals = Goals('Root')
    goals.add('Top 1')
    goals.add('Top 2')
    e = Enumeration(goals)
    assert e.all(keys='name,switchable,select') == {
        1: {'name': 'Root', 'switchable': False, 'select': 'select'},
        2: {'name': 'Top 1', 'switchable': True, 'select': None},
        3: {'name': 'Top 2', 'switchable': True, 'select': None},
    }
    e.next_view()
    assert e.events[-2] == ('select', 2)
    assert e.events[-1] == ('hold_select', 2)
    assert e.all(keys='name,switchable,select') == {
        1: {'name': 'Top 1', 'switchable': True, 'select': 'select'},
        2: {'name': 'Top 2', 'switchable': True, 'select': None}
    }
Exemplo n.º 27
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.º 28
0
def test_dot_export_full_view():
    g = Enumeration(Goals('Root'))
    g.add('Middle')
    g.add('Top', 2)
    g.add('Closed')
    g.select(4)
    g.toggle_close()
    g.next_view()
    g.next_view()
    g.select(1)
    assert dot_export(g) == '''digraph g {
node [shape=box];
1 [label="1: Root", color=red, style=filled, fillcolor=gray];
2 [label="2: Middle", color=red];
3 [label="3: Top", color=red, style="bold,filled", fillcolor=lightgray];
4 [label="4: Closed", color=green];
2 -> 1 [color=black];
4 -> 1 [color=gray];
3 -> 2 [color=black];
}'''
    g.hold_select()
    g.select(3)
    assert dot_export(g) == '''digraph g {
Exemplo n.º 29
0
def test_dot_export_zoomed_goal_tree():
    g = Enumeration(Zoom(Goals('Root goal')))
    g.add('Hidden intermediate')
    g.add('Zoom root', 2)
    g.add('Hidden neighbour', 2)
    g.add('Visible top', 3)
    g.toggle_link(4, 5)
    g.select(3)
    for i in range(8):
        g.add('Additional %d' % (i + 3), 3)
    g.toggle_zoom()
    assert dot_export(g) == '''digraph g {
Exemplo n.º 30
0
def test_dot_export_top_view():
    g = Enumeration(Goals('Root'))
    g.add('Middle')
    g.add('Top', 2)
    g.add('Closed')
    g.add('More closed', 3)
    # close 'More closed'
    g.select(5)
    g.toggle_close()
    # close 'Closed'
    g.select(4)
    g.toggle_close()
    g.next_view()
    assert dot_export(g) == '''digraph g {