def test_delete_command_execute(): canvas = Mock(spec=Canvas) command = DeleteCommand(lambda: canvas) x1, y1 = 42, 69 target_point = Point(x1, y1) command.execute(x1, y1) canvas.delete.assert_called_once_with(target_point)
def get_routes(): """ This function contains the dictionary of possible commands. :return: `dict` of possible commands, with the format: `name -> class` """ # Dynamic load: # def class_filter(klass): # return inspect.isclass(klass) \ # and klass.__module__ == BaseCommand.__module__ \ # and issubclass(klass, BaseCommand) \ # and klass is not BaseCommand # # routes = inspect.getmembers( # sys.modules[BaseCommand.__module__], # class_filter # ) # return dict((route.label(), route) for _, route in routes) return { ListCommand.label(): ListCommand, NewCommand.label(): NewCommand, DoneCommand.label(): DoneCommand, UndoneCommand.label(): UndoneCommand, DeleteCommand.label(): DeleteCommand, ExitCommand.label(): ExitCommand, }
def _create_commands_dictionary(): def assign_canvas_fn(new_canvas): #pylint: disable=missing-docstring global canvas canvas = new_canvas return { 'C': CreateCanvasCommand(assign_canvas_fn), 'L': DrawLineCommand(lambda: canvas), 'R': DrawRectangleCommand(lambda: canvas), 'B': BucketFillCommand(lambda: canvas), 'D': DeleteCommand(lambda: canvas), 'U': UndoCommand(lambda: canvas), 'Q': ExitCommand() }
def parse_user_input(): """ Gets the user input. :return: `str` with the user input. """ input_function = input message = 'Input your command: (%s): ' % '|'.join( { ListCommand.label(): ListCommand, NewCommand.label(): NewCommand, DoneCommand.label(): DoneCommand, UndoneCommand.label(): UndoneCommand, DeleteCommand.label(): DeleteCommand, ExitCommand.label(): ExitCommand, }.keys()) return input_function(message)
def test_delete_command_execute_with_incorrect_nb_args(): canvas = Mock(spec=Canvas) command = DeleteCommand(lambda: canvas) with pytest.raises(ValueError) as ex: command.execute([1]) assert str(ex.value) == "2 arguments expected (x, y)"