<commit_before>#!/usr/bin/env python
# -*- coding: utf-8 -*-

import unittest

import os, sys
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

from DebianChangesBot.messages import *
from DebianChangesBot.mailparsers import *
from DebianChangesBot.utils import parse_mail

from glob import glob

class TestFixtures(unittest.TestCase):

    def _test_dir(self, dir, parser, expected_type, test=lambda x: bool(x)):
        dir = os.path.join(os.path.dirname(os.path.abspath(__file__)),
            'fixtures', dir, '*')

        for filename in glob(dir):
            try:
                headers, body = parse_mail(file(filename))
                msg = parser.parse(headers, body)
            except Exception:
                print "Exception when parsing %s" % filename
                raise

            if type(msg) != expected_type:
                print
                print filename, "did not match"
            self.assertEqual(type(msg), expected_type)
            self.assert_(test(msg))

    def testAcceptedUpload(self):
        self._test_dir('accepted_upload', AcceptedUploadParser, AcceptedUploadMessage)

    def testBugClosed(self):
        self._test_dir('bug_closed', BugClosedParser, BugClosedMessage)

    def testBugSubmitted(self):
        self._test_dir('bug_submitted', BugSubmittedParser, BugSubmittedMessage)

    def testSecurityAnnounce(self):
        self._test_dir('security_announce', SecurityAnnounceParser, SecurityAnnounceMessage)

    def testNoMatch(self):
        for parser in AcceptedUploadParser, BugClosedParser, BugSubmittedParser, SecurityAnnounceParser:
            self._test_dir('non_messages', parser, type(None), test=lambda x: not bool(x))

if __name__ == "__main__":
    unittest.main()
<commit_msg>Print filename when message does not pass test<commit_after>#!/usr/bin/env python
# -*- coding: utf-8 -*-

import unittest

import os, sys
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

from DebianChangesBot.messages import *
from DebianChangesBot.mailparsers import *
from DebianChangesBot.utils import parse_mail

from glob import glob

class TestFixtures(unittest.TestCase):

    def _test_dir(self, dir, parser, expected_type, test=lambda x: bool(x)):
        dir = os.path.join(os.path.dirname(os.path.abspath(__file__)),
            'fixtures', dir, '*')

        for filename in glob(dir):
            try:
                headers, body = parse_mail(file(filename))
                msg = parser.parse(headers, body)
            except Exception:
                print "Exception when parsing %s" % filename
                raise

            if type(msg) != expected_type:
                print
                print filename, "did not match"
            self.assertEqual(type(msg), expected_type)

            if not test(msg):
                print
                print filename, "did not pass test"
            self.assert_(test(msg))

    def testAcceptedUpload(self):
        self._test_dir('accepted_upload', AcceptedUploadParser, AcceptedUploadMessage)

    def testBugClosed(self):
        self._test_dir('bug_closed', BugClosedParser, BugClosedMessage)

    def testBugSubmitted(self):
        self._test_dir('bug_submitted', BugSubmittedParser, BugSubmittedMessage)

    def testSecurityAnnounce(self):
        self._test_dir('security_announce', SecurityAnnounceParser, SecurityAnnounceMessage)

    def testNoMatch(self):
        for parser in AcceptedUploadParser, BugClosedParser, BugSubmittedParser, SecurityAnnounceParser:
            self._test_dir('non_messages', parser, type(None), test=lambda x: not bool(x))

if __name__ == "__main__":
    unittest.main()

{'fraction_non_alphanumeric': 0.10064935064935066, 'fraction_numerical': 0.0005411255411255411, 'mean_word_length': 2.962486602357985, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, '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': '6502804', 'n_tokens_mistral': 1077, 'n_tokens_neox': 1015, 'n_words': 237}