Exemplo n.º 1
0
 def test_log_verbose_error_logs_expected_text_at_expected_level(
         self, mocker, caplog):
     with caplog.at_level(logging.ERROR):
         request = mocker.MagicMock(sepc=Request)
         request.body = {"foo": "bar"}
         CliLogger().log_verbose_error("code42 dothing --flag YES", request)
         assert "'code42 dothing --flag YES'" in caplog.text
         assert "Request parameters: {'foo': 'bar'}" in caplog.text
Exemplo n.º 2
0
    def convert(self, value, param, ctx):
        try:
            with open(value, "rb") as file:
                self.encoding = chardet.detect(file.read())["encoding"]
            if self.encoding is None:
                CliLogger().log_error(f"Failed to detect encoding of file: {value}")
        except Exception:
            pass  # we'll let click.File do it's own exception handling for the filepath

        return super().convert(value, param, ctx)
Exemplo n.º 3
0
class TestCliLogger:

    _logger = CliLogger()

    def test_init_creates_user_error_logger_with_expected_handlers(self):
        logger = CliLogger()
        handler_types = [type(h) for h in logger._logger.handlers]
        assert RotatingFileHandler in handler_types

    def test_log_error_logs_expected_text_at_expected_level(self, caplog):
        with caplog.at_level(logging.ERROR):
            ex = Exception("TEST")
            self._logger.log_error(ex)
            assert str(ex) in caplog.text

    def test_log_verbose_error_logs_expected_text_at_expected_level(
            self, mocker, caplog):
        with caplog.at_level(logging.ERROR):
            request = mocker.MagicMock(sepc=Request)
            request.body = {"foo": "bar"}
            self._logger.log_verbose_error("code42 dothing --flag YES",
                                           request)
            assert "'code42 dothing --flag YES'" in caplog.text
            assert "Request parameters: {'foo': 'bar'}" in caplog.text
Exemplo n.º 4
0
 def test_log_error_logs_expected_text_at_expected_level(self, caplog):
     with caplog.at_level(logging.ERROR):
         ex = Exception("TEST")
         CliLogger().log_error(ex)
         assert str(ex) in caplog.text
Exemplo n.º 5
0
 def test_init_creates_user_error_logger_with_expected_handlers(self):
     logger = CliLogger()
     handler_types = [type(h) for h in logger._logger.handlers]
     assert RotatingFileHandler in handler_types