<commit_before>"""Check that a check is working."""

from unittest import TestCase
import os
from textblob import TextBlob
import codecs


class Check(TestCase):

    """All tests inherit from Check."""

    __test__ = False

    @property
    def this_check(self):
        """The specific check."""
        raise NotImplementedError

    def check(self, lst):
        """Check if the test runs cleanly on the given text."""
        if isinstance(lst, basestring):
            lst = [lst]

        errors = []
        for text in lst:
            blob = TextBlob(text)
            errors.append(self.this_check.check(blob))

        return len(errors[0]) == 0

    def test_wpe(self):
        """Check whether the check is too noisy."""
        min_wpe = 50

        examples_dir = os.path.join(os.getcwd(), "tests", "corpus")
        examples = os.listdir(examples_dir)

        for example in examples:
            example_path = os.path.join(examples_dir, example)

            # Compute the number of words per (wpe) error.
            with codecs.open(example_path, "r", encoding='utf-8') as f:
                blob = TextBlob(f.read())
                num_errors = len(self.this_check.check(blob))
                num_words = len(blob.words)

            try:
                wpe = 1.0 * num_words / num_errors
            except ZeroDivisionError:<commit_msg>Don't lint .DS_Store file<commit_after>"""Check that a check is working."""

from unittest import TestCase
import os
from textblob import TextBlob
import codecs


class Check(TestCase):

    """All tests inherit from Check."""

    __test__ = False

    @property
    def this_check(self):
        """The specific check."""
        raise NotImplementedError

    def check(self, lst):
        """Check if the test runs cleanly on the given text."""
        if isinstance(lst, basestring):
            lst = [lst]

        errors = []
        for text in lst:
            blob = TextBlob(text)
            errors.append(self.this_check.check(blob))

        return len(errors[0]) == 0

    def test_wpe(self):
        """Check whether the check is too noisy."""
        min_wpe = 50

        examples_dir = os.path.join(os.getcwd(), "tests", "corpus")
        examples = os.listdir(examples_dir)

        for example in examples:
            example_path = os.path.join(examples_dir, example)

            if ".DS_Store" in example_path:
                break

            # Compute the number of words per (wpe) error.
            with codecs.open(example_path, "r", encoding='utf-8') as f:
                blob = TextBlob(f.read())
                num_errors = len(self.this_check.check(blob))
                num_words = len(blob.words)

            try:
                wpe = 1.0 * num_words / num_errors
            except ZeroDivisionError:
{'fraction_non_alphanumeric': 0.10530060476698684, 'fraction_numerical': 0.004980434009249377, 'mean_word_length': 2.0042735042735043, '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': '4960757', 'n_tokens_mistral': 838, 'n_tokens_neox': 784, 'n_words': 237}