<commit_before>import pytest
import logging

from charset_normalizer.utils import set_logging_handler
from charset_normalizer.api import from_bytes, explain_handler
from charset_normalizer.constant import TRACE


class TestLogBehaviorClass:
    def setup(self):
        self.logger = logging.getLogger("charset_normalizer")
        self.logger.handlers.clear()
        self.logger.addHandler(logging.NullHandler())
        self.logger.level = logging.WARNING

    def test_explain_true_behavior(self, caplog):
        test_sequence = b'This is a test sequence of bytes that should be sufficient'
        from_bytes(test_sequence, steps=1, chunk_size=50, explain=True)
        assert explain_handler not in self.logger.handlers
        for record in caplog.records:
            assert record.levelname in ["Level 5", "DEBUG"]

    def test_explain_false_handler_set_behavior(self, caplog):
        test_sequence = b'This is a test sequence of bytes that should be sufficient'
        set_logging_handler(level=TRACE, format_string="%(message)s")
        from_bytes(test_sequence, steps=1, chunk_size=50, explain=False)
        assert any(isinstance(hdl, logging.StreamHandler) for hdl in self.logger.handlers)
        for record in caplog.records:
            assert record.levelname in ["Level 5", "DEBUG"]
        assert "Encoding detection: ascii is most likely the one." in caplog.text<commit_msg>Update test_logging.py (#239)<commit_after>import pytest
import logging

from charset_normalizer.utils import set_logging_handler
from charset_normalizer.api import from_bytes, explain_handler
from charset_normalizer.constant import TRACE


class TestLogBehaviorClass:
    def setup_method(self):
        self.logger = logging.getLogger("charset_normalizer")
        self.logger.handlers.clear()
        self.logger.addHandler(logging.NullHandler())
        self.logger.level = logging.WARNING

    def test_explain_true_behavior(self, caplog):
        test_sequence = b'This is a test sequence of bytes that should be sufficient'
        from_bytes(test_sequence, steps=1, chunk_size=50, explain=True)
        assert explain_handler not in self.logger.handlers
        for record in caplog.records:
            assert record.levelname in ["Level 5", "DEBUG"]

    def test_explain_false_handler_set_behavior(self, caplog):
        test_sequence = b'This is a test sequence of bytes that should be sufficient'
        set_logging_handler(level=TRACE, format_string="%(message)s")
        from_bytes(test_sequence, steps=1, chunk_size=50, explain=False)
        assert any(isinstance(hdl, logging.StreamHandler) for hdl in self.logger.handlers)
        for record in caplog.records:
            assert record.levelname in ["Level 5", "DEBUG"]
        assert "Encoding detection: ascii is most likely the one." in caplog.text
{'fraction_non_alphanumeric': 0.07863974495217853, 'fraction_numerical': 0.006730428622033298, 'mean_word_length': 3.8191126279863483, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2720381', 'n_tokens_mistral': 806, 'n_tokens_neox': 783, 'n_words': 221}