<commit_before>"""Base test case class for coverage testing."""

import imp, os, random, sys, tempfile, textwrap, unittest
from cStringIO import StringIO

import path     # from http://www.jorendorff.com/articles/python/path/

import coverage


class CoverageTest(unittest.TestCase):
    def setUp(self):
        # Create a temporary directory.
        self.noise = str(random.random())[2:]
        self.temproot = path.path(tempfile.gettempdir()) / 'test_coverage' 
        self.tempdir = self.temproot / self.noise
        self.tempdir.makedirs()
        self.olddir = os.getcwd()
        os.chdir(self.tempdir)

        # Modules should be importable from this temp directory.
        self.oldsyspath = sys.path[:]
        sys.path.insert(0, '')

        # Keep a counter to make every call to checkCoverage unique.
        self.n = 0
        
    def tearDown(self):
        sys.path = self.oldsyspath
        # Get rid of the temporary directory.
        os.chdir(self.olddir)
        self.temproot.rmtree()

    def makeFile(self, modname, text):
        """ Create a temp file with modname as the module name, and text as the
            contents.
        """
        text = textwrap.dedent(text)
        
        # Create the python file.
        f = open(modname + '.py', 'w')
        f.write(text)<commit_msg>Remove the tests' dependence on the 3rd party path module.<commit_after>"""Base test case class for coverage testing."""

import imp, os, random, shutil, sys, tempfile, textwrap, unittest
from cStringIO import StringIO

import coverage


class CoverageTest(unittest.TestCase):
    def setUp(self):
        # Create a temporary directory.
        self.noise = str(random.random())[2:]
        self.temproot = os.path.join(tempfile.gettempdir(), 'test_coverage')
        self.tempdir = os.path.join(self.temproot, self.noise)
        os.makedirs(self.tempdir)
        self.olddir = os.getcwd()
        os.chdir(self.tempdir)

        # Modules should be importable from this temp directory.
        self.oldsyspath = sys.path[:]
        sys.path.insert(0, '')

        # Keep a counter to make every call to checkCoverage unique.
        self.n = 0
        
    def tearDown(self):
        sys.path = self.oldsyspath
        # Get rid of the temporary directory.
        os.chdir(self.olddir)
        shutil.rmtree(self.temproot)

    def makeFile(self, modname, text):
        """ Create a temp file with modname as the module name, and text as the
            contents.
        """
        text = textwrap.dedent(text)
        
        # Create the python file.
        f = open(modname + '.py', 'w')
        f.write(text)
{'fraction_non_alphanumeric': 0.10602044680045437, 'fraction_numerical': 0.0026505111700113595, 'mean_word_length': 2.2779156327543424, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 1, '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': '1737822', 'n_tokens_mistral': 810, 'n_tokens_neox': 787, 'n_words': 225}