Ejemplo n.º 1
0
    def test_log_warning(self, mock_logger_warning):
        path = inspect.getfile(MagicMock)
        name = 'faker.providers.color.Provider'
        docstring = ProviderMethodDocstring(
            app=MagicMock(),
            what='method',
            name=name,
            obj=MagicMock,
            options=MagicMock(),
            lines=MagicMock(),
        )
        docstring._log_warning('Test Warning 1')
        docstring._log_warning('Test Warning 2')

        assert docstring._log_prefix == '{path}:docstring of {name}: WARNING:'.format(
            path=path, name=name)

        calls = mock_logger_warning.call_args_list
        assert len(calls) == 2

        # 1st call to logger.warning
        args, kwargs = calls[0]
        assert len(args) == 1
        assert not kwargs
        assert args[
            0] == '{path}:docstring of {name}: WARNING: Test Warning 1'.format(
                path=path, name=name)

        # 2nd call to logger.warning
        args, kwargs = calls[1]
        assert len(args) == 1
        assert not kwargs
        assert args[
            0] == '{path}:docstring of {name}: WARNING: Test Warning 2'.format(
                path=path, name=name)
Ejemplo n.º 2
0
    def test_log_warning(self, mock_logger_warning):
        path = inspect.getfile(MagicMock)
        name = "faker.providers.color.Provider"
        docstring = ProviderMethodDocstring(
            app=MagicMock(),
            what="method",
            name=name,
            obj=MagicMock,
            options=MagicMock(),
            lines=MagicMock(),
        )
        docstring._log_warning("Test Warning 1")
        docstring._log_warning("Test Warning 2")

        assert docstring._log_prefix == f"{path}:docstring of {name}: WARNING:"

        calls = mock_logger_warning.call_args_list
        assert len(calls) == 2

        # 1st call to logger.warning
        args, kwargs = calls[0]
        assert len(args) == 1
        assert not kwargs
        assert args[
            0] == f"{path}:docstring of {name}: WARNING: Test Warning 1"

        # 2nd call to logger.warning
        args, kwargs = calls[1]
        assert len(args) == 1
        assert not kwargs
        assert args[
            0] == f"{path}:docstring of {name}: WARNING: Test Warning 2"