def test_logger_title(capsys, caplog, logger_env_cleanup): logger = get_logger(TEST_LOGGER_NAME) log_title(logger, "Log title") assert "Log title" in caplog.text caplog.clear() log_subtitle(logger, "Log subtitle") assert "Log subtitle" in caplog.text
def test_get_logger(logger_env_cleanup, capsys, caplog): logger = get_logger(TEST_LOGGER_NAME) assert isinstance(logger, logging.Logger) stdouterr = capsys.readouterr() assert "Warning: cannot write debug logs" not in caplog.text assert "Exception encountered while setting up debug log file" not in caplog.text assert "Warning: cannot write debug logs" not in stdouterr.out assert "Exception encountered while setting up debug log file" not in stdouterr.err assert "Warning: cannot write debug logs" not in stdouterr.out assert "Exception encountered while setting up debug log file" not in stdouterr.err
def test_get_logger_exception(mock_RotatingFileHandler, capsys, caplog, logger_env_cleanup): mock_RotatingFileHandler.side_effect = Exception( 'all your log are belong to us') assert os.environ.get('EVALML_LOG_FILE') is None logger = get_logger(TEST_LOGGER_NAME) assert len(logger.handlers) == 1 assert len(mock_RotatingFileHandler.mock_calls) == 1 assert mock_RotatingFileHandler.call_count == 1 stdouterr = capsys.readouterr() assert "Warning: cannot write debug logs" not in caplog.text assert "Exception encountered while setting up debug log file" in caplog.text assert "Warning: cannot write debug logs" not in stdouterr.out assert "Exception encountered while setting up debug log file" in stdouterr.out assert "Warning: cannot write debug logs" not in stdouterr.err assert "Exception encountered while setting up debug log file" not in stdouterr.err
def test_get_logger_default(mock_RotatingFileHandler, capsys, caplog, logger_env_cleanup): assert os.environ.get('EVALML_LOG_FILE') is None logger = get_logger(TEST_LOGGER_NAME) assert len(logger.handlers) == 2 mock_RotatingFileHandler.assert_called_with( filename=Path("evalml_debug.log")) assert len(mock_RotatingFileHandler.mock_calls) == 4 assert mock_RotatingFileHandler.mock_calls[1] == call().setLevel( logging.DEBUG) stdouterr = capsys.readouterr() assert "Warning: cannot write debug logs" not in caplog.text assert "Exception encountered while setting up debug log file" not in caplog.text assert "Warning: cannot write debug logs" not in stdouterr.out assert "Exception encountered while setting up debug log file" not in stdouterr.out assert "Warning: cannot write debug logs" not in stdouterr.err assert "Exception encountered while setting up debug log file" not in stdouterr.err
def test_get_logger_path_empty(mock_RotatingFileHandler, monkeypatch, capsys, caplog, logger_env_cleanup): assert os.environ.get('EVALML_LOG_FILE') is None monkeypatch.setenv('EVALML_LOG_FILE', '') assert os.environ.get('EVALML_LOG_FILE') == '' logger = get_logger(TEST_LOGGER_NAME) assert len(logger.handlers) == 1 assert len(mock_RotatingFileHandler.mock_calls) == 0 assert mock_RotatingFileHandler.call_count == 0 stdouterr = capsys.readouterr() assert "Warning: cannot write debug logs" not in caplog.text assert "Exception encountered while setting up debug log file" not in caplog.text assert "Warning: cannot write debug logs" not in stdouterr.out assert "Exception encountered while setting up debug log file" not in stdouterr.out assert "Warning: cannot write debug logs" not in stdouterr.err assert "Exception encountered while setting up debug log file" not in stdouterr.err
def test_get_logger_path_valid_but_dir(mock_RotatingFileHandler, monkeypatch, capsys, caplog, logger_env_cleanup): assert os.environ.get('EVALML_LOG_FILE') is None with tempfile.TemporaryDirectory() as temp_dir: monkeypatch.setenv('EVALML_LOG_FILE', temp_dir) assert os.environ.get('EVALML_LOG_FILE') == temp_dir logger = get_logger(TEST_LOGGER_NAME) assert len(logger.handlers) == 1 assert len(mock_RotatingFileHandler.mock_calls) == 0 assert mock_RotatingFileHandler.call_count == 0 stdouterr = capsys.readouterr() assert "Warning: cannot write debug logs" not in caplog.text assert "Exception encountered while setting up debug log file" not in caplog.text assert "Warning: cannot write debug logs" in stdouterr.out assert "Exception encountered while setting up debug log file" not in stdouterr.out assert "Warning: cannot write debug logs" not in stdouterr.err assert "Exception encountered while setting up debug log file" not in stdouterr.err
def test_get_logger_path_invalid(mock_RotatingFileHandler, monkeypatch, capsys, caplog, logger_env_cleanup): assert os.environ.get('EVALML_LOG_FILE') is None with tempfile.TemporaryDirectory() as temp_dir: log_file_path = str( Path(temp_dir, 'INVALID', 'PATH', 'DOES_NOT_EXIST', 'evalml_debug_custom.log')) monkeypatch.setenv('EVALML_LOG_FILE', log_file_path) assert os.environ.get('EVALML_LOG_FILE') == log_file_path logger = get_logger(TEST_LOGGER_NAME) assert len(logger.handlers) == 1 assert len(mock_RotatingFileHandler.mock_calls) == 0 assert mock_RotatingFileHandler.call_count == 0 stdouterr = capsys.readouterr() assert "Warning: cannot write debug logs" not in caplog.text assert "Exception encountered while setting up debug log file" not in caplog.text assert "Warning: cannot write debug logs" in stdouterr.out assert "Exception encountered while setting up debug log file" not in stdouterr.out assert "Warning: cannot write debug logs" not in stdouterr.err assert "Exception encountered while setting up debug log file" not in stdouterr.err
def test_get_logger_path_valid(mock_RotatingFileHandler, monkeypatch, capsys, caplog, logger_env_cleanup): assert os.environ.get('EVALML_LOG_FILE') is None with tempfile.TemporaryDirectory() as temp_dir: log_file_path = str(Path(temp_dir, 'evalml_debug_custom.log')) monkeypatch.setenv('EVALML_LOG_FILE', log_file_path) assert os.environ.get('EVALML_LOG_FILE') == log_file_path logger = get_logger(TEST_LOGGER_NAME) assert len(logger.handlers) == 2 mock_RotatingFileHandler.assert_called_with( filename=Path(log_file_path)) assert len(mock_RotatingFileHandler.mock_calls) == 4 assert mock_RotatingFileHandler.mock_calls[1] == call().setLevel( logging.DEBUG) stdouterr = capsys.readouterr() assert "Warning: cannot write debug logs" not in caplog.text assert "Exception encountered while setting up debug log file" not in caplog.text assert "Warning: cannot write debug logs" not in stdouterr.out assert "Exception encountered while setting up debug log file" not in stdouterr.out assert "Warning: cannot write debug logs" not in stdouterr.err assert "Exception encountered while setting up debug log file" not in stdouterr.err
from abc import ABC, abstractmethod from collections import OrderedDict import numpy as np import pandas as pd from evalml.automl.utils import (check_all_pipeline_names_unique, tune_binary_threshold) from evalml.exceptions import PipelineScoreError from evalml.model_family import ModelFamily from evalml.preprocessing import split_data from evalml.problem_types import is_binary, is_classification, is_multiclass from evalml.utils.logger import get_logger from evalml.utils.woodwork_utils import _convert_woodwork_types_wrapper logger = get_logger(__file__) class EngineBase(ABC): """Base class for the engine API which handles the fitting and evaluation of pipelines during AutoML.""" def __init__(self, X_train=None, y_train=None, ensembling_indices=None, automl=None, should_continue_callback=None, pre_evaluation_callback=None, post_evaluation_callback=None): """Base class for the engine API which handles the fitting and evaluation of pipelines during AutoML. Arguments:
def test_logger_critical(caplog, logger_env_cleanup): logger = get_logger(TEST_LOGGER_NAME) logger.critical("Test critical") assert "Test critical" in caplog.text assert "CRITICAL" in caplog.text
def test_logger_error(caplog, logger_env_cleanup): logger = get_logger(TEST_LOGGER_NAME) logger.error("Test error") assert "Test error" in caplog.text assert "ERROR" in caplog.text
def test_logger_warn(caplog, logger_env_cleanup): logger = get_logger(TEST_LOGGER_NAME) logger.warn("Test warning") assert "Test warning" in caplog.text assert "WARN" in caplog.text
def test_logger_info(caplog, logger_env_cleanup): logger = get_logger(TEST_LOGGER_NAME) logger.info("Test info") assert "Test info" in caplog.text assert "INFO" in caplog.text