newdwh2021/ecs/crm-datafetch/tests/util/test_logger_out_of_class.py

194 lines
7.1 KiB
Python

import logging
from src.util.logger import logger_instance as logger
class TestLogger:
def test_logging_debug(self, caplog):
"""
Cases:
Debugレベルを設定したloggerについて、それ以下のログが出力されないこと
Arranges:
- 各レベルでのログを出力する
- ログレベルの設定
Expects:
- 期待値通りのログが出力されること
"""
# Arranges
caplog.set_level(logging.DEBUG)
logger.debug('debugログ出力')
logger.info('infoログ出力')
logger.warning("warningログ出力")
logger.error("errorログ出力")
logger.critical("criticalログ出力")
# Expects
assert ("root", logging.DEBUG, "debugログ出力") in caplog.record_tuples
assert ("root", logging.INFO, "infoログ出力") in caplog.record_tuples
assert ("root", logging.WARNING, "warningログ出力") in caplog.record_tuples
assert ("root", logging.ERROR, "errorログ出力") in caplog.record_tuples
assert ("root", logging.CRITICAL, "criticalログ出力") in caplog.record_tuples
def test_logging_info(self, caplog):
"""
Cases:
Infoレベルを設定したloggerについて、それ以下のログが出力されないこと
Arranges:
- 各レベルでのログを出力する
- ログレベルの設定
Expects:
- 期待値通りのログが出力されること
"""
# Arranges
caplog.set_level(logging.INFO)
logger.debug('debugログ出力')
logger.info('infoログ出力')
logger.warning("warningログ出力")
logger.error("errorログ出力")
logger.critical("criticalログ出力")
# Expects
assert ("root", logging.DEBUG, "debugログ出力") not in caplog.record_tuples
assert ("root", logging.INFO, "infoログ出力") in caplog.record_tuples
assert ("root", logging.WARNING, "warningログ出力") in caplog.record_tuples
assert ("root", logging.ERROR, "errorログ出力") in caplog.record_tuples
assert ("root", logging.CRITICAL, "criticalログ出力") in caplog.record_tuples
def test_logging_warning(self, caplog):
"""
Cases:
Warningレベルを設定したloggerについて、それ以下のログが出力されないこと
Arranges:
- 各レベルでのログを出力する
- ログレベルの設定
Expects:
- 期待値通りのログが出力されること
"""
# Arranges
caplog.set_level(logging.WARNING)
logger.debug('debugログ出力')
logger.info('infoログ出力')
logger.warning("warningログ出力")
logger.error("errorログ出力")
logger.critical("criticalログ出力")
# Expects
assert ("root", logging.DEBUG, "debugログ出力") not in caplog.record_tuples
assert ("root", logging.INFO, "infoログ出力") not in caplog.record_tuples
assert ("root", logging.WARNING, "warningログ出力") in caplog.record_tuples
assert ("root", logging.ERROR, "errorログ出力") in caplog.record_tuples
assert ("root", logging.CRITICAL, "criticalログ出力") in caplog.record_tuples
def test_logging_error(self, caplog):
"""
Cases:
Errorレベルを設定したloggerについて、それ以下のログが出力されないこと
Arranges:
- 各レベルでのログを出力する
- ログレベルの設定
Expects:
- 期待値通りのログが出力されること
"""
# Arranges
caplog.set_level(logging.ERROR)
logger.debug('debugログ出力')
logger.info('infoログ出力')
logger.warning("warningログ出力")
logger.error("errorログ出力")
logger.critical("criticalログ出力")
# Expects
assert ("root", logging.DEBUG, "debugログ出力") not in caplog.record_tuples
assert ("root", logging.INFO, "infoログ出力") not in caplog.record_tuples
assert ("root", logging.WARNING, "warningログ出力") not in caplog.record_tuples
assert ("root", logging.ERROR, "errorログ出力") in caplog.record_tuples
assert ("root", logging.CRITICAL, "criticalログ出力") in caplog.record_tuples
def test_logging_critical(self, caplog):
"""
Cases:
Criticalレベルを設定したloggerについて、それ以下のログが出力されないこと
Arranges:
- 各レベルでのログを出力する
- ログレベルの設定
Expects:
- 期待値通りのログが出力されること
"""
# Arranges
caplog.set_level(logging.CRITICAL)
logger.debug('debugログ出力')
logger.info('infoログ出力')
logger.warning("warningログ出力")
logger.error("errorログ出力")
logger.critical("criticalログ出力")
# Expects
assert ("root", logging.DEBUG, "debugログ出力") not in caplog.record_tuples
assert ("root", logging.INFO, "infoログ出力") not in caplog.record_tuples
assert ("root", logging.WARNING, "warningログ出力") not in caplog.record_tuples
assert ("root", logging.ERROR, "errorログ出力") not in caplog.record_tuples
assert ("root", logging.CRITICAL, "criticalログ出力") in caplog.record_tuples
def test_logging_getlogger_boto3(self):
"""
Cases:
個別設定したboto3モジュールのログレベル確認
Arranges:
なし
Expects:
設定されているログレベルが期待値と一致すること
"""
# Expects
assert logging.getLogger("boto3").getEffectiveLevel() == logging.WARNING
def test_logging_getlogger_botocore(self):
"""
Cases:
個別設定したbotocoreモジュールのログレベル確認
Arranges:
なし
Expects:
設定されているログレベルが期待値と一致すること
"""
# Expects
assert logging.getLogger("botocore").getEffectiveLevel() == logging.WARNING
def test_logging_getlogger_s3transfer(self):
"""
Cases:
個別設定したs3transferモジュールのログレベル確認
Arranges:
なし
Expects:
設定されているログレベルが期待値と一致すること
"""
# Expects
assert logging.getLogger("s3transfer").getEffectiveLevel() == logging.WARNING
def test_logging_getlogger_urllib3(self):
"""
Cases:
個別設定したurllib3モジュールのログレベル確認
Arranges:
なし
Expects:
設定されているログレベルが期待値と一致すること
"""
# Expects
assert logging.getLogger("s3transfer").getEffectiveLevel() == logging.WARNING