コード例 #1
0
def test_invoker_execute_should_execute_in_given_order():
    commands_to_execute = [Command2(), Command1()]
    invoker = Invoker()
    invoker.execute(commands_to_execute)

    assert isinstance(invoker._executed_commands[0], Command2)
    assert isinstance(invoker._executed_commands[1], Command1)
コード例 #2
0
def test_invoker_execute_should_execute_commands_in_giver_order():
    commands_to_execute = [Command1(), Command2()]
    invoker = Invoker()
    invoker.execute(commands_to_execute)

    assert invoker._executed_commands[0].command == "touch content.txt"
    assert (invoker._executed_commands[1].command ==
            "mv content.txt content-replaced.txt")
コード例 #3
0
def set_up_invoker(things_dict):
    invoker = Invoker()
    appliances, doors, security_systems = things_dict
    appliance_commands = get_appliance_commands(appliances)
    door_commands = get_door_commands(doors)
    security_commands = get_security_commands(security_systems)
    types_of_commands = [appliance_commands, door_commands, security_commands]
    for type_of_command in types_of_commands:
        for object, command in type_of_command.items():
            invoker.set_object_commands(object, command)
    return invoker
コード例 #4
0
def test_invoker_execute_shouldnt_be_undo():
    commands_to_execute = [Command1(), Command2(), InvalidCommand()]
    invoker = Invoker()

    invoker.execute(commands_to_execute, run_undo=False)

    assert invoker._executed_commands[0].command == "touch content.txt"
    assert (invoker._executed_commands[1].command ==
            "mv content.txt content-replaced.txt")

    assert invoker._undo_commands_executed == []

    assert len(invoker._commands) == 3
    assert len(invoker._executed_commands) == 2
    assert len(invoker._undo_commands_executed) == 0
コード例 #5
0
def test_invoker_execute_should_be_undo_automatically():
    commands_to_execute = [Command1(), Command2(), InvalidCommand()]
    invoker = Invoker()

    invoker.execute(commands_to_execute, run_undo=True)

    assert invoker._executed_commands[0].command == "touch content.txt"
    assert (invoker._executed_commands[1].command ==
            "mv content.txt content-replaced.txt")

    assert (invoker._undo_commands_executed[0].undo_command ==
            "mv content-replaced.txt content.txt")
    assert invoker._undo_commands_executed[1].undo_command == "rm content.txt"

    assert len(invoker._commands) == 3
    assert len(invoker._executed_commands) == 2
    assert len(invoker._undo_commands_executed) == 2
コード例 #6
0
def test_invoker_undo_should_run_two_commands_in_reversed_order():
    commands_to_execute = [Command1(), Command2()]
    invoker = Invoker()
    invoker.execute(commands_to_execute)

    assert invoker._executed_commands[0].command == "touch content.txt"
    assert (invoker._executed_commands[1].command ==
            "mv content.txt content-replaced.txt")

    invoker.undo()

    assert (invoker._undo_commands_executed[0].undo_command ==
            "mv content-replaced.txt content.txt")
    assert invoker._undo_commands_executed[1].undo_command == "rm content.txt"
コード例 #7
0
def test_invoker_execute_should_execute_two_commands():
    commands_to_execute = [Command1(), Command2()]
    invoker = Invoker()
    invoker.execute(commands_to_execute)

    assert len(invoker._executed_commands) == 2
コード例 #8
0
def test_invoker_has_been_success_should_be_false():
    commands_to_execute = [Command1(), Command2(), InvalidCommand()]
    invoker = Invoker()
    invoker.execute(commands_to_execute)

    assert invoker.has_been_success is False
コード例 #9
0
def test_invoker_has_been_success_should_be_true():
    commands_to_execute = [Command1(), Command2()]
    invoker = Invoker()
    invoker.execute(commands_to_execute)

    assert invoker.has_been_success is True