Exemple #1
0
def test_learn_mail():
    """Tests for learn_mail."""
    fmail = open('examples/spam.eml', 'rb')
    ftext = fmail.read()
    mail = new_message(ftext)
    fmail.close()

    if cmd_exists('spamc'):
        # We forget the mail:
        spamproc.learn_mail(mail, 'forget')
        # We forget the mail:
        ret, ret_o = spamproc.learn_mail(mail, 'forget')
        assert ret is 6, "Mail should be already unlearned."
        # We try to learn it (as spam):
        ret, ret_o = spamproc.learn_mail(mail, 'spam')
        assert ret is 5, "Mail should have been learned"
        # The second time it should be already learned:
        ret, ret_o = spamproc.learn_mail(mail, 'spam')
        assert ret is 6, "Mail should be already learned."
    else:
        # We forget the mail:
        with pytest.raises(OSError,
                           match="No such file",
                           message="Should rise OSError."):
            spamproc.learn_mail(mail, 'forget')
Exemple #2
0
def test_learn_mail():
    """Tests for learn_mail, with a running SA instance."""
    fmail = open('tests/examples/spam.eml', 'rb')
    ftext = fmail.read()
    mail = new_message(ftext)
    fmail.close()

    # We forget the mail:
    spamproc.learn_mail(mail, 'forget')
    # We forget the mail:
    ret, ret_o = spamproc.learn_mail(mail, 'forget')
    assert ret is 6, "Mail should be already unlearned."
    # We try to learn it (as spam):
    ret, ret_o = spamproc.learn_mail(mail, 'spam')
    assert ret is 5, "Mail should have been learned"
    # The second time it should be already learned:
    ret, ret_o = spamproc.learn_mail(mail, 'spam')
    assert ret is 6, "Mail should be already learned."
Exemple #3
0
def test_learn_mail():
    """Tests for learn_mail."""
    fmail = open('examples/spam.eml', 'rb')
    ftext = fmail.read()
    mail = new_message(ftext)
    fmail.close()

    if cmd_exists('spamc'):
        # We forget the mail:
        spamproc.learn_mail(mail, 'forget')
        # We forget the mail:
        ret, ret_o = spamproc.learn_mail(mail, 'forget')
        assert ret is 6, "Mail should be already unlearned."
        # We try to learn it (as spam):
        ret, ret_o = spamproc.learn_mail(mail, 'spam')
        assert ret is 5, "Mail should have been learned"
        # The second time it should be already learned:
        ret, ret_o = spamproc.learn_mail(mail, 'spam')
        assert ret is 6, "Mail should be already learned."
    else:
        # We forget the mail:
        with pytest.raises(OSError, match="No such file"):
            spamproc.learn_mail(mail, 'forget')
            pytest.fail("Should rise OSError.")