def test_level_filter_not_matches(logger, caplog): enable(logger, level='DEBUG', echo=False) logger.addFilter(LevelFilter(logging.DEBUG)) # does *not* log message at level INFO > DEBUG with caplog.at_level(logging.INFO, logger=logger.name): logger.info('msg') assert not caplog.text
def test_level_filter_matches(logger, caplog): enable(logger, level='DEBUG', echo=False) logger.addFilter(LevelFilter(logging.CRITICAL)) # does log message at level CRITICAL with caplog.at_level(logging.CRITICAL, logger=logger.name): logger.critical('msg') assert caplog.text
#!/usr/bin/env python if __name__ == '__main__': from ballet.util.log import enable from ballet.validation.main import validate import ames enable(level='DEBUG', echo=False) validate(ames)
def test_logging_context(logger, caplog): enable(logger, level='DEBUG', echo=False) with caplog.at_level(logging.DEBUG, logger=logger.name): with LoggingContext(logger, level='INFO'): logger.debug('msg') assert not caplog.text
def test_enable(logger, caplog, level): with caplog.at_level(level, logger=logger.name): enable(logger, level, echo=True) assert 'enabled' in caplog.text
class RandomValue(BaseTransformer): def fit(self, X, y=None): return self def transform(self, X): return np.random.random(X.shape[0]) transformer = RandomValue() feature = Feature(input=input, transformer=transformer) if __name__ == "__main__": from ballet.util.log import enable from ballet.project import Project from ballet.validation.main import _load_class from ballet_predict_house_prices.features import build from ballet_predict_house_prices.load_data import load_data enable(level='INFO') X_df, y_df = load_data() out = build(X_df, y_df) X_df, y, features = out.X_df, out.y, out.features project = Project.from_path(".") Accepter = _load_class(project, 'validation.feature_accepter') accepter = Accepter(X_df, y, features, feature) assert accepter.judge()