<commit_before>from maldini import digest, models, emails

MAIL_PATH_MAPBOX = "eml-1-promotional/Introducing Mapbox Android Services - " \
              "Mapbox Team <<EMAIL>> - 2016-04-20 1603.eml"
MAIL_PATH_CODINGAME = "eml-1-promotional/New on CodinGame: Check it out! - " \
                 "CodinGame <<EMAIL>> - 2016-04-21 1034.eml"
MAIL_PATH_CAMPUS = "eml-2-attachment/FW: Invitation Fontys Open Day 2nd " \
                    "of February 2014 - <NAME> " \
                    "<<EMAIL>> - 2013-12-16 1700.eml"

def get_email_for_path(path):
    doc = models.Document(path=path)
    with digest.open_document(doc) as f:
        email = emails.EmailParser(f)
    return email

def test_subject():
    doc = models.Document(path=MAIL_PATH_MAPBOX)

    with digest.open_document(doc) as f:
        email = emails.EmailParser(f)
    data = email.get_data()

    assert data['subject'] == "Introducing Mapbox Android Services"

def test_text():
    email_codin = get_email_for_path(MAIL_PATH_CODINGAME)
    assert email_codin.get_text().startswith("New on CodinGame: Check it out!")

    email_mapbox = get_email_for_path(MAIL_PATH_MAPBOX)
    assert "Android Services includes RxJava" in email_mapbox.get_text()

def test_people():
    email = get_email_for_path(MAIL_PATH_MAPBOX)
    data = email.get_data()

    assert type(data['to']) is list
    assert len(data['to']) == 1
    assert "<EMAIL>" in data['to']

    assert type(data['from']) is list
    assert len(data['from']) == 1
    assert "<EMAIL>" in data[0]

<commit_msg>test email path, title, attachments<commit_after>from maldini import digest, models, emails

MAIL_PATH_MAPBOX = "eml-1-promotional/Introducing Mapbox Android Services - " \
              "Mapbox Team <<EMAIL>> - 2016-04-20 1603.eml"
MAIL_PATH_CODINGAME = "eml-1-promotional/New on CodinGame: Check it out! - " \
                 "CodinGame <<EMAIL>> - 2016-04-21 1034.eml"
MAIL_PATH_CAMPUS = "eml-2-attachment/FW: Invitation Fontys Open Day 2nd " \
                    "of February 2014 - <NAME> " \
                    "<<EMAIL>> - 2013-12-16 1700.eml"
MAIL_PATH_AMERICAN = "eml-3-uppercaseheaders/Fwd: The American College " \
                     "of Thessaloniki - Greece - <NAME> " \
                     "<<EMAIL>> - 2013-11-11 1622.eml"
MAIL_PATH_LONG_FILENAMES = "eml-5-long-names/Attachments have " \
                           "long file names..eml"

def get_email_for_path(path):
    doc = models.Document(path=path)
    with digest.open_document(doc) as f:
        email = emails.EmailParser(f)
    return email

def test_subject():
    doc = models.Document(path=MAIL_PATH_MAPBOX)

    with digest.open_document(doc) as f:
        email = emails.EmailParser(f)
    data = email.get_data()

    assert data['subject'] == "Introducing Mapbox Android Services"

def test_text():
    email_codin = get_email_for_path(MAIL_PATH_CODINGAME)
    assert email_codin.get_text().startswith("New on CodinGame: Check it out!")

    email_mapbox = get_email_for_path(MAIL_PATH_MAPBOX)
    assert "Android Services includes RxJava" in email_mapbox.get_text()

def test_people():
    email = get_email_for_path(MAIL_PATH_MAPBOX)
    data = email.get_data()

    assert type(data['to']) is list
    assert len(data['to']) == 1
    assert "<EMAIL>" in data['to']

    assert type(data['from']) is list
    assert len(data['from']) == 1
    assert "<EMAIL>" in data[0]

def test_path():
    email = get_email_for_path(MAIL_PATH_CAMPUS)
    assert email.get_data()['path'] == MAIL_PATH_CAMPUS

def test_title():
    email = get_email_for_path(MAIL_PATH_MAPBOX)
    data = email.get_data()

    assert 'title' in data
    assert MAIL_PATH_MAPBOX in data['title']

def test_normal_attachments():
    email = get_email_for_path(MAIL_PATH_CAMPUS)
    attachments = email.get_data().get('attachments')

    assert attachments
    assert type(attachments) is dict
    assert len(attachments) == 2

def test_attachment_with_long_filename():
    email = get_email_for_path(MAIL_PATH_LONG_FILENAMES)
    attachments = email.get_data().get('attachments')

    assert len(attachments) == 3



{'fraction_non_alphanumeric': 0.11776155717761558, 'fraction_numerical': 0.0267639902676399, 'mean_word_length': 3.246900826446281, 'pattern_counts': {'":': 0, '<': 24, '<?xml version=': 0, '>': 24, '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': '206526', 'n_tokens_mistral': 1498, 'n_tokens_neox': 1402, 'n_words': 305}