<commit_before>#! /usr/bin/env python

"""
Regression tests for modipyd
"""

import os
import sys
import unittest
from errno import ENOENT

sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
import modipyd

# ----------------------------------------------------------------
# Settings
# ----------------------------------------------------------------
# The directory contains test files.
FILES_DIR = os.path.join(os.path.dirname(__file__), 'files')


class TestModipydCollectFiles(unittest.TestCase):
    """Tests modipyd functionalities"""

    def test_files_dir_exists(self):
        self.assert_(os.path.exists(FILES_DIR))
        self.assert_(os.path.isdir(FILES_DIR))

    def test_not_found(self):
        filename = os.path.join(FILES_DIR, 'no file or directory')
        self.assert_(not os.path.exists(filename))

        try:
            modipyd.collect_files(filename)
        except IOError, ioe:
            self.assert_(ioe.errno is ENOENT)
            self.assertEqual(filename, ioe.filename)
        else:
            self.fail("Expected IOError")

    def empty_directory(self):
        directory = os.path.join(FILES_DIR, 'empty')
        if not os.path.exists(directory):
            os.mkdir(directory)
        self.assert_(os.path.exists(directory))
        self.assert_(os.path.isdir(directory))
        return directory

    def test_empty_directory(self):
        directory = self.empty_directory()
        files = list(modipyd.collect_files(directory))
        self.assert_(files is not None)
        self.assertEqual(0, len(files))


if __name__ == '__main__':
    unittest.main()
<commit_msg>Added assertNone/assertNotNone<commit_after>#! /usr/bin/env python

"""
Regression tests for modipyd
"""

import os
import sys
import unittest
from errno import ENOENT

sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
import modipyd

# ----------------------------------------------------------------
# Settings
# ----------------------------------------------------------------
# The directory contains test files.
FILES_DIR = os.path.join(os.path.dirname(__file__), 'files')

class TestCase(unittest.TestCase):
    """Custom TestCase class"""

    def failUnlessNone(self, expr, msg=None):
        """Fail the test unless the expression is None."""
        if expr is not None: raise self.failureException, msg

    def failIfNone(self, expr, msg=None):
        """Fail the test if the expression is None."""
        if expr is None: raise self.failureException, msg

    # Synonyms for assertion methods
    assertNone = failUnlessNone
    assertNotNone = failIfNone


class TestModipydCollectFiles(TestCase):
    """Tests modipyd functionalities"""

    def test_files_dir_exists(self):
        self.assert_(os.path.exists(FILES_DIR))
        self.assert_(os.path.isdir(FILES_DIR))

    def test_not_found(self):
        filename = os.path.join(FILES_DIR, 'no file or directory')
        self.assert_(not os.path.exists(filename))

        try:
            modipyd.collect_files(filename)
        except IOError, ioe:
            self.assertEqual(ENOENT, ioe.errno)
            self.assertEqual(filename, ioe.filename)
        else:
            self.fail("Expected IOError")

    def empty_directory(self):
        directory = os.path.join(FILES_DIR, 'empty')
        if not os.path.exists(directory):
            os.mkdir(directory)
        self.assert_(os.path.exists(directory))
        self.assert_(os.path.isdir(directory))
        return directory

    def test_empty_directory(self):
        directory = self.empty_directory()
        files = list(modipyd.collect_files(directory))
        self.assertNotNone(files)
        self.assertEqual(0, len(files))


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

{'fraction_non_alphanumeric': 0.17458211727248607, 'fraction_numerical': 0.0010612894667020429, 'mean_word_length': 2.318661971830986, 'pattern_counts': {'":': 0, '<': 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': '6914421', 'n_tokens_mistral': 1094, 'n_tokens_neox': 1059, 'n_words': 231}