Example #1
0
def test_multiple_saves_works_fine():
    file_name = NamedTemporaryFile().name
    goals = all_layers(Goals("Root"))
    save(goals, file_name)
    goals.accept(Add("Next"))
    save(goals, file_name)
    new_goals = load(file_name)
    assert goals.q() == new_goals.q()
Example #2
0
def test_save_into_sqlite3_database():
    file_name = NamedTemporaryFile().name
    goals = all_layers(Goals("Sample"))
    save(goals, file_name)
    with sqlite3.connect(file_name) as conn:
        with closing(conn.cursor()) as cur:
            cur.execute("select version from migrations")
            assert cur.fetchone()[0] > 0
Example #3
0
def build_goals(conn):
    with closing(conn.cursor()) as cur:
        goals = list(cur.execute("select * from goals"))
        edges = list(cur.execute("select parent, child, reltype from edges"))
        db_settings = list(cur.execute("select * from settings"))
        zoom_data = list(cur.execute("select * from zoom"))
        autolink_data = list(cur.execute("select * from autolink"))
        note(
            f"Goals: {goals}, Edges: {edges}, Settings: {db_settings}, Zoom: {zoom_data}, Autolink: {autolink_data}"
        )
        goals = Goals.build(goals, edges, db_settings)
        return all_layers(goals, zoom_data, autolink_data)
Example #4
0
def test_migration_must_run_on_load_from_existing_db():
    file_name = NamedTemporaryFile().name
    goals = all_layers(Goals("Just a simple goal tree"))
    save(goals, file_name)
    MIGRATIONS.append([
        "create table dummy (answer integer)",
        "insert into dummy values (42)",
    ])
    try:
        load(file_name)
        with closing(sqlite3.connect(file_name)) as conn:
            with closing(conn.cursor()) as cur:
                cur.execute("select answer from dummy")
                value = cur.fetchone()[0]
                assert value == 42
    finally:
        MIGRATIONS.pop(-1)
Example #5
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"),
            )))
Example #6
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": []
        },
    }
Example #7
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": []},
    }
Example #8
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")
Example #9
0
 def __init__(self):
     super().__init__()
     self.goaltree = all_layers(Goals("Root"))
     self.database = sqlite3.connect(":memory:")