<commit_before>import pytest
from mailthon.enclosure import PlainText
from mailthon.envelope import Envelope, Stamp
from .mimetest import mimetest, blank


@pytest.fixture
def stamp():
    return Stamp(
        subject='subject',
        sender='Me <<EMAIL>>',
        receivers=['<EMAIL>', '<EMAIL>'],
        headers={
            'X-This-That': 'Something',
        }
    )


class TestStamp:
    def test_receiver_string(self, stamp):
        assert stamp.receiver_string == '<EMAIL>, <EMAIL>'

    def test_prepare(self, stamp):
        mime = blank()
        stamp.prepare(mime)

        assert mime['To'] == '<EMAIL>, <EMAIL>'
        assert mime['From'] == 'Me <<EMAIL>>'
        assert mime['Subject'] == 'subject'
        assert mime['X-This-That'] == 'Something'

    def test_headers_priority(self, stamp):
        stamp.headers = {
            'To': '<EMAIL>',
            'From': 'Her <<EMAIL>>'
        }

        mime = blank()
        stamp.prepare(mime)
        assert mime['To'] == '<EMAIL>'
        assert mime['From'] == 'Her <<EMAIL>>'


class TestEnvelope:
    @pytest.fixture
    def envelope(self, stamp):
        return Envelope(
            stamp=stamp,
            enclosure=[
                PlainText('hi!'),
                PlainText('bye!'),
            ],
        )

    def test_as_string(self, envelope):
        mime = mimetest(envelope.to_string())
        assert [g.payload for g in mime.parts] == [b'hi!', b'bye!']<commit_msg>test init stamp with header list<commit_after>import pytest
from mailthon.enclosure import PlainText
from mailthon.envelope import Envelope, Stamp
from mailthon import headers
from .mimetest import mimetest, blank


@pytest.fixture
def stamp():
    return Stamp(
        subject='subject',
        sender='Me <<EMAIL>>',
        receivers=['<EMAIL>', '<EMAIL>'],
        headers={
            'X-This-That': 'Something',
        }
    )


class TestStamp:
    def test_receiver_string(self, stamp):
        assert stamp.receiver_string == '<EMAIL>, <EMAIL>'

    def test_prepare(self, stamp):
        mime = blank()
        stamp.prepare(mime)

        assert mime['To'] == '<EMAIL>, <EMAIL>'
        assert mime['From'] == 'Me <<EMAIL>>'
        assert mime['Subject'] == 'subject'
        assert mime['X-This-That'] == 'Something'

    def test_headers_priority(self, stamp):
        stamp.headers = {
            'To': '<EMAIL>',
            'From': 'Her <<EMAIL>>'
        }

        mime = blank()
        stamp.prepare(mime)
        assert mime['To'] == '<EMAIL>'
        assert mime['From'] == 'Her <<EMAIL>>'

    def test_init_with_list(self):
        stamp = Stamp(
            subject='Subject',
            sender='Me <<EMAIL>>',
            receivers=['someone'],
            headers=[
                headers.date('this'),
                headers.content_id('filename'),
            ]
        )
        mime = blank()
        stamp.prepare(mime)
        assert mime['Date'] == 'this'
        assert mime['Content-ID'] == '<filename>'


class TestEnvelope:
    @pytest.fixture
    def envelope(self, stamp):
        return Envelope(
            stamp=stamp,
            enclosure=[
                PlainText('hi!'),
                PlainText('bye!'),
            ],
        )

    def test_as_string(self, envelope):
        mime = mimetest(envelope.to_string())
        assert [g.payload for g in mime.parts] == [b'hi!', b'bye!']
{'fraction_non_alphanumeric': 0.1501906717512467, 'fraction_numerical': 0.0, 'mean_word_length': 2.097184377838329, 'pattern_counts': {'":': 0, '<': 38, '<?xml version=': 0, '>': 38, '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': '3674179', 'n_tokens_mistral': 1062, 'n_tokens_neox': 1046, 'n_words': 232}