def test_redo_filled(): """ Test redoing an action on a filled out planned schedule. """ # Set up case. Note that we have to manually set the base date of the session in # order to access the task, since it has a hard-coded date. session = Session("example", load=True) session.base_date = session.current_schedules( )[0].tasks[0].start_time.date() session.base_date -= timedelta(days=session.base_date.weekday()) # Store pre-edit values. old_history_pos = session.history_pos old_history_len = len(session.edit_history) old_planned, old_actual = session.current_schedules() # Undo then redo last action. session.undo() session.redo() # Test session values. new_planned, new_actual = session.current_schedules() assert session.history_pos == old_history_pos assert old_planned == new_planned assert old_actual == new_actual assert len(session.edit_history) == old_history_len
def test_undo_filled_planned(): """ Test undoing an edit task action on a filled out planned schedule. """ # Set up case. Note that we have to manually set the base date of the session in # order to access the task, since it has a hard-coded date. session = Session("example", load=True) session.base_date = session.current_schedules( )[0].tasks[0].start_time.date() session.base_date -= timedelta(days=session.base_date.weekday()) planned = True day = 4 task_index = 0 new_values = {"name": "new_name"} # Store pre-edit values. old_history_pos = session.history_pos old_planned, old_actual = session.current_schedules() # Edit task, then undo. session.edit_task( planned=planned, day=day, task_index=task_index, new_values=new_values, ) session.undo() # Test session values. new_planned, new_actual = session.current_schedules() assert session.history_pos == old_history_pos assert old_planned == new_planned assert old_actual == new_actual
def test_undo_empty_planned(): """ Test undoing the addition of a task to an empty session. """ # Construct session. session = Session("test") # Insert task and undo insertion. session.insert_task( day=4, planned=True, name="test", priority=1.0, start_time=time(hour=12), hours=1.5, ) session.undo() # Test session values. assert session.history_pos == 0 assert len(session.edit_history) == 2 assert len(session.edit_history[0][0].tasks) == 0 assert len(session.edit_history[0][1].tasks) == 0 assert len(session.edit_history[1][0].tasks) == 1 assert len(session.edit_history[1][1].tasks) == 0 task = session.edit_history[1][0].tasks[0] assert task.name == "test" assert task.priority == 1.0 assert task.start_time.date() == session.base_date + timedelta(days=4) assert task.start_time.time() == time(hour=12) assert task.end_time.date() == session.base_date + timedelta(days=4) assert task.end_time.time() == time(hour=13, minute=30)
def test_undo_edge(): """ Test undoing when there is nothing to undo. """ # Construct session. session = Session("test") # Undo. session.undo() # Test session values. assert session.history_pos == 0 assert len(session.edit_history) == 1 assert len(session.edit_history[0][0].tasks) == 0 assert len(session.edit_history[0][1].tasks) == 0
def test_redo_empty_planned(): """ Test redoing the addition of a task to an empty session. """ # Construct session. session = Session("test") # Insert task. session.insert_task( day=4, planned=True, name="test", priority=1.0, start_time=time(hour=12), hours=1.5, ) # Store session values. old_planned, old_actual = session.current_schedules() # Undo, then redo insertion. session.undo() session.redo() # Test session values. new_planned, new_actual = session.current_schedules() assert session.history_pos == 1 assert len(session.edit_history) == 2 assert new_planned == old_planned assert new_actual == old_actual assert len(session.edit_history[0][0].tasks) == 0 assert len(session.edit_history[0][1].tasks) == 0 assert len(session.edit_history[1][0].tasks) == 1 assert len(session.edit_history[1][1].tasks) == 0 task = session.edit_history[1][0].tasks[0] assert task.name == "test" assert task.priority == 1.0 assert task.start_time.date() == session.base_date + timedelta(days=4) assert task.start_time.time() == time(hour=12) assert task.end_time.date() == session.base_date + timedelta(days=4) assert task.end_time.time() == time(hour=13, minute=30)
def test_set_new_schedules_2(): """ Call `set_new_schedules()` in the second case of edit history (cases listed in docstring of `set_new_schedules()`). """ # Construct session. session = Session("test") # Construct planned and new schedules. planned_tasks = [ Task( "planned_task_1", priority=1.0, start_time=datetime(2020, 5, 1, hour=12), end_time=datetime(2020, 5, 1, hour=13, minute=30), ), Task( "planned_task_2", priority=1.0, start_time=datetime(2020, 5, 1, hour=12, minute=30), end_time=datetime(2020, 5, 1, hour=14), ), ] actual_tasks = [ Task( "actual_task_1", priority=1.0, start_time=datetime(2020, 5, 1, hour=13), end_time=datetime(2020, 5, 1, hour=14, minute=30), ), Task( "actual_task_2", priority=1.0, start_time=datetime(2020, 5, 1, hour=13, minute=30), end_time=datetime(2020, 5, 1, hour=15), ), ] planned = [ Schedule("planned_1", [planned_tasks[0]]), Schedule("planned_2", [planned_tasks[1]]), ] actual = [ Schedule("actual_1", [actual_tasks[0]]), Schedule("actual_2", [actual_tasks[1]]), ] # Set new schedules in session, undo, then redo with new versions. session.set_new_schedules(planned[0], actual[0]) session.undo() session.set_new_schedules(planned[1], actual[1]) # Test session values. assert session.history_pos == 1 assert len(session.edit_history) == 2 assert len(session.edit_history[0][0].tasks) == 0 assert len(session.edit_history[0][1].tasks) == 0 assert len(session.edit_history[1][0].tasks) == 1 assert len(session.edit_history[1][1].tasks) == 1 assert session.edit_history[1][0].tasks[0] == planned_tasks[1] assert session.edit_history[1][1].tasks[0] == actual_tasks[1]