def test_setup_logging_dict(self, smtp_config_yaml): logging_config_dict = {'version': 1, 'handlers': { 'error_file_handler': { 'class': 'logging.FileHandler', 'level': 'ERROR', 'filename': 'errors.log', 'encoding': 'utf8', 'mode': 'w' }, 'error_mail_handler': { 'class': 'logging.handlers.SMTPHandler', 'level': 'CRITICAL', 'mailhost': 'localhost', 'fromaddr': 'noreply@localhost', 'toaddrs': '*****@*****.**', 'subject': 'SCRAPER FAILED' } }, 'root': { 'level': 'INFO', 'handlers': ['error_file_handler', 'error_mail_handler'] }} setup_logging(logging_config_dict=logging_config_dict) actual_logging_tree = format.build_description() for handler in ['File', 'SMTP']: assert handler in actual_logging_tree assert '*****@*****.**' in actual_logging_tree
def test_setup_logging_smtp_dict(self): smtp_config_dict = {'handlers': {'error_mail_handler': {'toaddrs': '*****@*****.**', 'subject': 'lala'}}} setup_logging(smtp_config_dict=smtp_config_dict) actual_logging_tree = format.build_description() for handler in ['Stream', 'File', 'SMTP']: assert handler in actual_logging_tree assert '*****@*****.**' in actual_logging_tree
#!/usr/bin/python # -*- coding: utf-8 -*- """Facade that handles ScraperWiki and calls project main function""" import logging import sys from typing import Callable import scraperwiki from hdx.configuration import Configuration from hdx.facades import logging_kwargs from hdx.logging import setup_logging logger = logging.getLogger(__name__) setup_logging(**logging_kwargs) def facade(projectmainfn: Callable[[Configuration], None], **kwargs) -> bool: """Facade that handles ScraperWiki and calls project main function Args: projectmainfn ((configuration) -> None): main function of project **kwargs: configuration parameters to pass to HDX Configuration class Returns: bool: True = success, False = failure """ try: # # Setting up configuration
#!/usr/bin/python # -*- coding: utf-8 -*- """Facade to simplify project setup that calls project main function""" import logging from typing import Callable from hdx.configuration import Configuration from hdx.facades import logging_kwargs from hdx.logging import setup_logging logger = logging.getLogger(__name__) setup_logging(**logging_kwargs) def facade(projectmainfn: Callable[[Configuration], None], **kwargs) -> None: """Facade to simplify project setup that calls project main function Args: projectmainfn ((configuration) -> None): main function of project **kwargs: configuration parameters to pass to HDX Configuration class Returns: None """ # # Setting up configuration # configuration = Configuration(**kwargs)
def test_setup_logging_yaml(self, logging_config_yaml): setup_logging(logging_config_yaml=logging_config_yaml) actual_logging_tree = format.build_description() for handler in ['Stream', 'SMTP']: assert handler in actual_logging_tree assert '*****@*****.**' in actual_logging_tree
def test_setup_logging_json(self, logging_config_json): setup_logging(logging_config_json=logging_config_json) actual_logging_tree = format.build_description() for handler in ['Stream', 'File']: assert handler in actual_logging_tree
def test_setup_logging(self, logging_config_json, logging_config_yaml, smtp_config_json, smtp_config_yaml): with pytest.raises(FileNotFoundError): setup_logging(smtp_config_json='NOT_EXIST') with pytest.raises(FileNotFoundError): setup_logging(logging_config_json='NOT_EXIST', smtp_config_yaml=smtp_config_yaml) with pytest.raises(FileNotFoundError): setup_logging(logging_config_yaml='NOT_EXIST', smtp_config_yaml=smtp_config_yaml) with pytest.raises(LoggingError): setup_logging(logging_config_yaml=logging_config_yaml, smtp_config_yaml=smtp_config_yaml) with pytest.raises(LoggingError): setup_logging(logging_config_dict={'la': 'la'}, logging_config_json=logging_config_json, smtp_config_yaml=smtp_config_yaml) with pytest.raises(LoggingError): setup_logging(logging_config_dict={'la': 'la'}, logging_config_yaml=logging_config_yaml, smtp_config_yaml=smtp_config_yaml) with pytest.raises(LoggingError): setup_logging(logging_config_json=logging_config_json, logging_config_yaml=logging_config_yaml, smtp_config_yaml=smtp_config_yaml) with pytest.raises(LoggingError): setup_logging(smtp_config_dict={'la': 'la'}, smtp_config_json=smtp_config_json) with pytest.raises(LoggingError): setup_logging(smtp_config_dict={'la': 'la'}, smtp_config_yaml=smtp_config_yaml) with pytest.raises(LoggingError): setup_logging(smtp_config_json=smtp_config_json, smtp_config_yaml=smtp_config_yaml)
def test_setup_logging_smtp_json(self, smtp_config_json): setup_logging(smtp_config_json=smtp_config_json) actual_logging_tree = format.build_description() for handler in ['Stream', 'File', 'SMTP']: assert handler in actual_logging_tree assert '*****@*****.**' in actual_logging_tree