コード例 #1
0
ファイル: test_history.py プロジェクト: optionalg/Slugathon
def test_undo_then_do_different():
    game_name = "game"
    playername = "player"
    parent_markerid = "Rd01"
    child_markerid = "Rd02"
    other_markerid = "Rd03"
    parent_creature_names = 4 * [None]
    child_creature_names = 4 * [None]

    history = History.History()
    action = Action.SplitLegion(game_name, playername, parent_markerid,
                                child_markerid, parent_creature_names,
                                child_creature_names)
    history.update(None, action, None)

    undo_action = Action.UndoSplit(game_name, playername, parent_markerid,
                                   child_markerid, parent_creature_names,
                                   child_creature_names)
    history.update(None, undo_action, None)

    action2 = Action.SplitLegion(game_name, playername, parent_markerid,
                                 other_markerid, parent_creature_names,
                                 child_creature_names)
    history.update(None, action2, None)
    assert history.actions == [action2]
    assert history.undone == []
    assert history.can_undo(playername)
    assert not history.can_redo(playername)
コード例 #2
0
ファイル: test_history.py プロジェクト: optionalg/Slugathon
def test_load2():
    history = History.History()
    assert history.actions == []
    assert history.undone == []
    fil = StringIO.StringIO(savefile_str)
    history.load(fil)
    assert len(history.actions) == 23
コード例 #3
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
コード例 #4
0
ファイル: test_history.py プロジェクト: optionalg/Slugathon
def test_load():
    history = History.History()
    assert history.actions == []
    assert history.undone == []
    with open(tmp_path) as fil:
        history.load(fil)
    assert len(history.actions) == 2
    for action in history.actions:
        assert isinstance(action, Action.MoveLegion)
    os.remove(tmp_path)
コード例 #5
0
ファイル: test_history.py プロジェクト: optionalg/Slugathon
def test_undo_nothing():
    game_name = "game"
    playername = "player"
    parent_markerid = "Rd01"
    child_markerid = "Rd02"
    parent_creature_names = 4 * [None]
    child_creature_names = 4 * [None]

    history = History.History()
    undo_action = Action.UndoSplit(game_name, playername, parent_markerid,
                                   child_markerid, parent_creature_names,
                                   child_creature_names)
    history.update(None, undo_action, None)
    assert history.actions == []
    assert history.undone == []
    assert not history.can_undo(playername)
    assert not history.can_redo(playername)
コード例 #6
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)
コード例 #7
0
ファイル: test_history.py プロジェクト: optionalg/Slugathon
def test_find_last_split():
    game_name = "game"
    playername = "player"
    parent_markerid = "Rd01"
    child_markerid = "Rd02"
    parent_creature_names = 4 * [None]
    child_creature_names = 4 * [None]

    history = History.History()
    action = Action.SplitLegion(game_name, playername, parent_markerid,
                                child_markerid, parent_creature_names,
                                child_creature_names)
    assert history.find_last_split(playername, parent_markerid,
                                   child_markerid) is None

    history.update(None, action, None)
    assert history.find_last_split(playername, parent_markerid,
                                   child_markerid) == action
    assert history.find_last_split(playername, "Rd03", "Rd04") is None