Ejemplo n.º 1
0
def test_do_not_load_from_broken_data():
    file_name = NamedTemporaryFile().name
    with sqlite3.connect(file_name) as conn:
        run_migrations(conn)
        setup_sample_db(conn)
        with closing(conn.cursor()) as cur:
            cur.execute("delete from goals where goal_id = 2")
    with pytest.raises(AssertionError):
        load(file_name)
Ejemplo n.º 2
0
 def __init__(self, db):
     super().__init__()
     self.refresh.connect(self.reload_image)
     self.quit_app.connect(QApplication.instance().quit)
     self.db = db
     self.goals = load(db)
     self.use_dot = True
     self.force_refresh = True
Ejemplo n.º 3
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)
Ejemplo n.º 4
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()
Ejemplo n.º 5
0
 def __init__(self, db, *args, **kwargs):
     super().__init__(*args, **kwargs)
     self.refresh.connect(self.save_and_render)
     self.quit_app.connect(QApplication.instance().quit)
     self.db = db
     self.goals = load(db, self.show_user_message)
     self.force_refresh = True
     self.columns = Renderer.DEFAULT_WIDTH
Ejemplo n.º 6
0
 def show_open_dialog(self):
     name = QFileDialog.getOpenFileName(self,
                                        caption="Open file",
                                        filter="*.db")[0]
     if name:
         self.db = name
         self.goals = load(name, self.show_user_message)
         self._update_title()
         self.force_refresh = True
         self.refresh.emit()
Ejemplo n.º 7
0
def main():
    io = ConsoleIO(prompt="> ")
    parser = ArgumentParser()
    parser.add_argument(
        "db",
        nargs="?",
        default="sieben.db",
        help="Path to the database file",
    )
    args = parser.parse_args()
    goals = load(args.db, update_message)
    loop(io, goals, args.db)
Ejemplo n.º 8
0
 def show_new_dialog(self):
     name = QFileDialog.getSaveFileName(self,
                                        caption="Save as...",
                                        filter="*.db")[0]
     if name:
         if not name.endswith(".db"):
             name = name + ".db"
         self.db = name
         self.goals = load(name, self.show_user_message)
         self._update_title()
         self.force_refresh = True
         self.refresh.emit()
Ejemplo n.º 9
0
def test_simple_scenario():
    log = []
    commands = [
        "r Approval testing",
        "a Measure coverage",
        "2",
        "a Build simple test",
        "3",
        "c",
    ]
    io = DummyIO(commands, log)
    db_name = ":memory:"
    goals = load(db_name, update_message)
    loop(io, goals, db_name)
    verify("\n".join(log),
           reporter=GenericDiffReporterFactory().get_first_working())
Ejemplo n.º 10
0
def test_complex_scenario():
    log = []
    commands = [
        "r Cover all current features",
        "a Filter view",
        "a Toggle show open/closed goals",
        "a Toggle show goal progress",
        "a Toggle show switchable goals",
        "a Toggle zoom and unzoom",
        "2",
        "h",
        "6",
        "l",
        "2",
        "z",
        "2",
        "c",
        "z",
        "f Toggle",
        "n",
        "2",
        "c",
        "f",
        "p",
        "t",
        "n",
        "t",
        "4",
        "c",
        "2",
        "c",
        "p",
        "c",
        # exit
        "q",
    ]
    io = DummyIO(commands, log)
    db_name = ":memory:"
    goals = load(db_name, update_message)
    loop(io, goals, db_name)
    verify("\n".join(log),
           reporter=GenericDiffReporterFactory().get_first_working())
Ejemplo n.º 11
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")
Ejemplo n.º 12
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()
Ejemplo n.º 13
0
def test_load_from_missing_file():
    file_name = NamedTemporaryFile().name
    expected_goals = Goals("Rename me")
    new_goals = load(file_name)
    assert new_goals.q(keys="open,name,edge,select") == expected_goals.q(
        keys="open,name,edge,select")