<commit_before># coding=utf8
import pytest
from mailthon.helpers import (guess, format_addresses,
                              encode_address, UnicodeDict)
from .utils import unicode as uni


def test_guess_recognised():
    mimetype, _ = guess('file.html')
    assert mimetype == 'text/html'


def test_guess_fallback():
    mimetype, _ = guess('ha', fallback='text/plain')
    assert mimetype == 'text/plain'


def test_format_addresses():
    chunks = format_addresses([
        ('Sender', '<EMAIL>'),
        'Fender <<EMAIL>>',
    ])
    assert chunks == 'Sender <<EMAIL>>, Fender <<EMAIL>>'


def test_encode_address():
    assert encode_address(uni('<EMAIL>')) == b'<EMAIL>'
    assert encode_address(uni('<EMAIL>')) == b'<EMAIL>'
    assert encode_address(uni('<EMAIL>')) == b'<EMAIL>'


class TestUnicodeDict:
    @pytest.fixture
    def mapping(self):
        return UnicodeDict({'Item': uni('måil')})

    @pytest.mark.parametrize('param', [
        uni('måil'),
        uni('måil').encode('utf8'),
    ])
    def test_setitem(self, param):
        u = UnicodeDict()
        u['Item'] = param
        assert u['Item'] == uni('måil')

    def test_update(self, mapping):
        mapping.update({
            'Item-1': uni('unicode-itém'),
            'Item-2': uni('bytes-item').encode('utf8'),
        })
        assert mapping['Item-1'] == uni('unicode-itém')
        assert mapping['Item-2'] == uni('bytes-item')<commit_msg>test more edge cases for encode_address<commit_after># coding=utf8
import pytest
from mailthon.helpers import (guess, format_addresses,
                              encode_address, UnicodeDict)
from .utils import unicode as uni


def test_guess_recognised():
    mimetype, _ = guess('file.html')
    assert mimetype == 'text/html'


def test_guess_fallback():
    mimetype, _ = guess('ha', fallback='text/plain')
    assert mimetype == 'text/plain'


def test_format_addresses():
    chunks = format_addresses([
        ('Sender', '<EMAIL>'),
        'Fender <<EMAIL>>',
    ])
    assert chunks == 'Sender <<EMAIL>>, Fender <<EMAIL>>'


def test_encode_address():
    assert encode_address(b'<EMAIL>') == b'<EMAIL>'
    assert encode_address(uni('<EMAIL>')) == b'<EMAIL>'
    assert encode_address(uni('<EMAIL>')) == b'<EMAIL>'
    assert encode_address(uni('<EMAIL>')) == b'm\xc3\xa<EMAIL>'
    assert encode_address(uni('måil')) == b'm\xc3\xa5il'


class TestUnicodeDict:
    @pytest.fixture
    def mapping(self):
        return UnicodeDict({'Item': uni('måil')})

    @pytest.mark.parametrize('param', [
        uni('måil'),
        uni('måil').encode('utf8'),
    ])
    def test_setitem(self, param):
        u = UnicodeDict()
        u['Item'] = param
        assert u['Item'] == uni('måil')

    def test_update(self, mapping):
        mapping.update({
            'Item-1': uni('unicode-itém'),
            'Item-2': uni('bytes-item').encode('utf8'),
        })
        assert mapping['Item-1'] == uni('unicode-itém')
        assert mapping['Item-2'] == uni('bytes-item')
{'fraction_non_alphanumeric': 0.17477656405163852, 'fraction_numerical': 0.005627275736511089, 'mean_word_length': 3.0837837837837836, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 31, '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': '5793313', 'n_tokens_mistral': 1032, 'n_tokens_neox': 993, 'n_words': 194}