コード例 #1
0
ファイル: test_history.py プロジェクト: optionalg/Slugathon
def test_save():
    game_name = "game"
    playername = "player"
    parent_markerid = "Rd01"
    child_markerid = "Rd02"

    history = History.History()
    assert history.actions == []
    assert history.undone == []
    assert not history.can_undo(playername)
    assert not history.can_redo(playername)

    action1 = Action.MoveLegion(game_name, playername, parent_markerid,
                                1, 1, False, None, 2)
    history.update(None, action1, None)
    assert history.actions == [action1]
    assert history.undone == []
    assert history.can_undo(playername)
    assert not history.can_undo("")
    assert not history.can_redo(playername)

    action2 = Action.MoveLegion(game_name, playername, child_markerid,
                                2, 3, False, None, 3)
    history.update(None, action2, None)
    assert history.actions == [action1, action2]

    global tmp_path
    with tempfile.NamedTemporaryFile(prefix="test_history",
                                     delete=False) as fil:
        tmp_path = fil.name
        history.save(fil)

    with open(tmp_path) as fil:
        lines = fil.readlines()
    assert len(lines) == 2
コード例 #2
0
ファイル: test_history.py プロジェクト: optionalg/Slugathon
def test_history_2():
    game_name = "game"
    playername = "player"
    parent_markerid = "Rd01"
    child_markerid = "Rd02"

    history = History.History()
    assert history.actions == []
    assert history.undone == []
    assert not history.can_undo(playername)
    assert not history.can_redo(playername)

    action1 = Action.MoveLegion(game_name, playername, parent_markerid,
                                1, 1, False, None, 2)
    history.update(None, action1, None)
    assert history.actions == [action1]
    assert history.undone == []
    assert history.can_undo(playername)
    assert not history.can_undo("")
    assert not history.can_redo(playername)

    action2 = Action.MoveLegion(game_name, playername, child_markerid,
                                2, 3, False, None, 3)
    history.update(None, action2, None)
    assert history.actions == [action1, action2]
    assert history.undone == []
    assert history.can_undo(playername)
    assert not history.can_undo("")
    assert not history.can_redo(playername)

    undo_action2 = Action.UndoMoveLegion(game_name, playername,
                                         child_markerid, 2, 3, False, None, 3)
    history.update(None, undo_action2, None)
    assert history.actions == [action1]
    assert history.undone == [action2]
    assert history.can_undo(playername)
    assert history.can_redo(playername)

    undo_action1 = Action.UndoMoveLegion(game_name, playername,
                                         parent_markerid, 1, 1, False, None, 2)
    history.update(None, undo_action1, None)
    assert history.actions == []
    assert history.undone == [action2, action1]
    assert not history.can_undo(playername)
    assert history.can_redo(playername)