<commit_before># encoding: utf-8
"""Test the TurboMail Message class."""

import calendar
from datetime import datetime, timedelta
import email
import logging
import re
import time
import unittest

from email.header import Header
from email.mime.text import MIMEText
from email.utils import formatdate, parsedate_tz

from marrow.mailer import Message
from marrow.mailer.address import AddressList

from nose.tools import raises

# logging.disable(logging.WARNING)


class TestBasicMessage(unittest.TestCase):
    """Test the basic output of the Message class."""
    
    gif = '47494638396101000100910000000000000000fe010200000021f904041400ff002c00000000010001000002024401003b'
    
    def build_message(self, **kw):
        return Message(
                    author=('Author', '<EMAIL>'),
                    to=('Recipient', '<EMAIL>'),
                    subject='Test message subject.',
                    plain='This is a test message plain text body.',
                    **kw
                )
    
    def test_missing_values(self):
        message = Message()
        self.assertRaises(ValueError, str, message)
        
        message.author = "<EMAIL>"
        self.assertRaises(ValueError, str, message)
        
        message.subject = "Attn: <NAME>"
        self.assertRaises(ValueError, str, message)
        
        message.to = "<EMAIL>"
        self.assertRaises(ValueError, str, message)
        
        message.plain = "Testing!"
        
        try:
            str(message)
        except ValueError:
            self.fail("Message should be valid.")
    
    def test_message_id(self):
        msg = self.build_message()
        
        self.assertEquals(msg._id, None)
        
        id_ = msg.id
        self.assertEquals(msg._id, id_)
        
        self.assertEquals(msg.id, id_)
    
    def test_message_properties(self):<commit_msg>Unit tests to cover explicit exception if author and sender missing.<commit_after># encoding: utf-8
"""Test the TurboMail Message class."""

import calendar
from datetime import datetime, timedelta
import email
import logging
import re
import time
import unittest

from email.header import Header
from email.mime.text import MIMEText
from email.utils import formatdate, parsedate_tz

from marrow.mailer import Message
from marrow.mailer.address import AddressList

from nose.tools import raises

# logging.disable(logging.WARNING)


class TestBasicMessage(unittest.TestCase):
    """Test the basic output of the Message class."""
    
    gif = '47494638396101000100910000000000000000fe010200000021f904041400ff002c00000000010001000002024401003b'
    
    def build_message(self, **kw):
        return Message(
                    author=('Author', '<EMAIL>'),
                    to=('Recipient', '<EMAIL>'),
                    subject='Test message subject.',
                    plain='This is a test message plain text body.',
                    **kw
                )
    
    def test_missing_values(self):
        message = Message()
        self.assertRaises(ValueError, str, message)
        
        message.author = "<EMAIL>"
        self.assertRaises(ValueError, str, message)
        
        message.subject = "Attn: <NAME>"
        self.assertRaises(ValueError, str, message)
        
        message.to = "<EMAIL>"
        self.assertRaises(ValueError, str, message)
        
        message.plain = "Testing!"
        
        try:
            str(message)
        except ValueError:
            self.fail("Message should be valid.")
    
    def test_message_id(self):
        msg = self.build_message()
        
        self.assertEquals(msg._id, None)
        
        id_ = msg.id
        self.assertEquals(msg._id, id_)
        
        self.assertEquals(msg.id, id_)
    
    def test_missing_author(self):
        message = self.build_message()
        message.author = []
        
        self.assertRaises(ValueError, lambda: message.envelope)
    
    def test_message_properties(self):
{'fraction_non_alphanumeric': 0.09015777610818933, 'fraction_numerical': 0.04608064112196344, 'mean_word_length': 2.260408163265306, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 4, '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': '3999723', 'n_tokens_mistral': 1219, 'n_tokens_neox': 1070, 'n_words': 279}