def test_args_kwargs(self, logger):
        targs = ['string1', 'string2']
        tkwargs = {'key': 'tkwargs'}

        @log_helpers.logwrap
        def func(*args, **kwargs):
            return tuple(args), kwargs

        result = func(*targs, **tkwargs)
        self.assertEqual(result, (tuple(targs), tkwargs))
        # raise ValueError(logger.mock_calls)
        logger.assert_has_calls((
            mock.call.log(
                level=logging.DEBUG,
                msg="Calling: \n'func'("
                    "\n    'args'={args},"
                    "\n    'kwargs'={kwargs},\n)".format(
                        args=log_helpers.pretty_repr(
                            tuple(targs),
                            indent=8, no_indent_start=True),
                        kwargs=log_helpers.pretty_repr(
                            tkwargs,
                            indent=8, no_indent_start=True)
                    )
            ),
            mock.call.log(
                level=logging.DEBUG,
                msg="Done: 'func' with result:\n{}".format(
                    log_helpers.pretty_repr(result))
            ),
        ))
    def test_args_complex(self, logger):
        string = 'string'
        dictionary = {'key': 'dictionary'}

        @log_helpers.logwrap
        def func(param_string, param_dictionary):
            return param_string, param_dictionary

        result = func(string, dictionary)
        self.assertEqual(result, (string, dictionary))
        # raise ValueError(logger.mock_calls)
        logger.assert_has_calls((
            mock.call.log(
                level=logging.DEBUG,
                msg="Calling: \n'func'("
                    "\n    'param_string'={string},"
                    "\n    'param_dictionary'={dictionary},\n)".format(
                        string=log_helpers.pretty_repr(
                            string,
                            indent=8, no_indent_start=True),
                        dictionary=log_helpers.pretty_repr(
                            dictionary,
                            indent=8, no_indent_start=True)
                    )
            ),
            mock.call.log(
                level=logging.DEBUG,
                msg="Done: 'func' with result:\n{}".format(
                    log_helpers.pretty_repr(result))
            ),
        ))
Beispiel #3
0
    def test_args_complex(self, logger):
        string = 'string'
        dictionary = {'key': 'dictionary'}

        @log_helpers.logwrap
        def func(param_string, param_dictionary):
            return param_string, param_dictionary

        result = func(string, dictionary)
        self.assertEqual(result, (string, dictionary))
        # raise ValueError(logger.mock_calls)
        logger.assert_has_calls((
            mock.call.log(
                level=logging.DEBUG,
                msg="Calling: \n'func'("
                "\n    'param_string'={string},"
                "\n    'param_dictionary'={dictionary},\n)".format(
                    string=log_helpers.pretty_repr(string,
                                                   indent=8,
                                                   no_indent_start=True),
                    dictionary=log_helpers.pretty_repr(dictionary,
                                                       indent=8,
                                                       no_indent_start=True))),
            mock.call.log(level=logging.DEBUG,
                          msg="Done: 'func' with result:\n{}".format(
                              log_helpers.pretty_repr(result))),
        ))
Beispiel #4
0
    def test_args_kwargs(self, logger):
        targs = ['string1', 'string2']
        tkwargs = {'key': 'tkwargs'}

        @log_helpers.logwrap
        def func(*args, **kwargs):
            return tuple(args), kwargs

        result = func(*targs, **tkwargs)
        self.assertEqual(result, (tuple(targs), tkwargs))
        # raise ValueError(logger.mock_calls)
        logger.assert_has_calls((
            mock.call.log(
                level=logging.DEBUG,
                msg="Calling: \n'func'("
                "\n    'args'={args},"
                "\n    'kwargs'={kwargs},\n)".format(
                    args=log_helpers.pretty_repr(tuple(targs),
                                                 indent=8,
                                                 no_indent_start=True),
                    kwargs=log_helpers.pretty_repr(tkwargs,
                                                   indent=8,
                                                   no_indent_start=True))),
            mock.call.log(level=logging.DEBUG,
                          msg="Done: 'func' with result:\n{}".format(
                              log_helpers.pretty_repr(result))),
        ))
Beispiel #5
0
    def test_args_defaults(self, logger):
        arg = 'test arg'

        @log_helpers.logwrap
        def func(tst=arg):
            return tst

        result = func()
        self.assertEqual(result, arg)
        logger.assert_has_calls((
            mock.call.log(level=logging.DEBUG,
                          msg="Calling: \n'func'(\n    'tst'={},\n)".format(
                              log_helpers.pretty_repr(arg,
                                                      indent=8,
                                                      no_indent_start=True))),
            mock.call.log(level=logging.DEBUG,
                          msg="Done: 'func' with result:\n{}".format(
                              log_helpers.pretty_repr(result))),
        ))
    def test_args_defaults(self, logger):
        arg = 'test arg'

        @log_helpers.logwrap
        def func(tst=arg):
            return tst

        result = func()
        self.assertEqual(result, arg)
        logger.assert_has_calls((
            mock.call.log(
                level=logging.DEBUG,
                msg="Calling: \n'func'(\n    'tst'={},\n)".format(
                    log_helpers.pretty_repr(
                        arg, indent=8, no_indent_start=True))
            ),
            mock.call.log(
                level=logging.DEBUG,
                msg="Done: 'func' with result:\n{}".format(
                    log_helpers.pretty_repr(result))
            ),
        ))
Beispiel #7
0
    def test_no_args(self, logger):
        @log_helpers.logwrap
        def func():
            return 'No args'

        result = func()
        self.assertEqual(result, 'No args')
        logger.assert_has_calls((
            mock.call.log(level=logging.DEBUG, msg="Calling: \n'func'()"),
            mock.call.log(level=logging.DEBUG,
                          msg="Done: 'func' with result:\n{}".format(
                              log_helpers.pretty_repr(result))),
        ))
    def test_no_args(self, logger):
        @log_helpers.logwrap
        def func():
            return 'No args'

        result = func()
        self.assertEqual(result, 'No args')
        logger.assert_has_calls((
            mock.call.log(
                level=logging.DEBUG,
                msg="Calling: \n'func'()"
            ),
            mock.call.log(
                level=logging.DEBUG,
                msg="Done: 'func' with result:\n{}".format(
                    log_helpers.pretty_repr(result))
            ),
        ))