<commit_before># -*- coding: utf-8 -*-

import os
import re
import shutil
import sys
import tempfile
import unittest

try:
    from StringIO import StringIO
except ImportError:
    from io import StringIO

import gitshelve

SCRIPT_DIR = os.path.abspath(os.path.dirname(__file__))


class TestGitShelve(unittest.TestCase):
    def __init__(self, *args, **kwargs):
        unittest.TestCase.__init__(self, *args, **kwargs)
        try:
            self.assertRegex
        except AttributeError:
            self.assertRegex = self.assertRegexpMatches

    def __add_file_to_repo(self, name, file_type='file'):
        rootDir = self.gitDir
        if file_type == 'dir':
            rootDir = os.path.join(self.gitDir, name)
            os.makedirs(rootDir)
            name = '.empty'

        filename = os.path.join(rootDir, name)
        with open(filename, 'w') as f:
            f.write('temp')
        stream = os.popen('git add %s' % filename)
        out = stream.read()
        stream.close()
        self.assertEqual('', out)
        stream = os.popen('git commit -m temp')
        out = stream.read()
        stream.close()
        commitRE = re.compile('.* ([0-9a-f]{7}).*? temp')
        self.assertIn('1 file changed, 1 insertion', out)
        return commitRE.search(out).group(1)

    def __use_new_repo(self):
        self.gitDir = tempfile.mkdtemp()  # pylint: disable=W0201
        self.lastCWD = os.getcwd()  # pylint: disable=W0201
        os.chdir(self.gitDir)
        stream = os.popen('git init')
        self.assertIn("Initialized empty Git repository in", stream.read())
        stream.close()
        os.system('git config user.email "<EMAIL>"')
        os.system('git config user.name "<NAME>"')

    def __cleanup_repo(self):
        """Delete the git repository"""
        os.chdir(self.lastCWD)<commit_msg>use environment variables to set author and committer.  using the git config didn't work in travis-ci.org<commit_after># -*- coding: utf-8 -*-

import os
import re
import shutil
import sys
import tempfile
import unittest

try:
    from StringIO import StringIO
except ImportError:
    from io import StringIO

import gitshelve

SCRIPT_DIR = os.path.abspath(os.path.dirname(__file__))


class TestGitShelve(unittest.TestCase):
    def __init__(self, *args, **kwargs):
        unittest.TestCase.__init__(self, *args, **kwargs)
        try:
            self.assertRegex
        except AttributeError:
            self.assertRegex = self.assertRegexpMatches

    def __add_file_to_repo(self, name, file_type='file'):
        rootDir = self.gitDir
        if file_type == 'dir':
            rootDir = os.path.join(self.gitDir, name)
            os.makedirs(rootDir)
            name = '.empty'

        filename = os.path.join(rootDir, name)
        with open(filename, 'w') as f:
            f.write('temp')
        stream = os.popen('git add %s' % filename)
        out = stream.read()
        stream.close()
        self.assertEqual('', out)
        stream = os.popen('git commit -m temp')
        out = stream.read()
        stream.close()
        commitRE = re.compile('.* ([0-9a-f]{7}).*? temp')
        self.assertIn('1 file changed, 1 insertion', out)
        return commitRE.search(out).group(1)

    def __use_new_repo(self):
        self.gitDir = tempfile.mkdtemp()  # pylint: disable=W0201
        self.lastCWD = os.getcwd()  # pylint: disable=W0201
        os.chdir(self.gitDir)
        stream = os.popen('git init')
        self.assertIn("Initialized empty Git repository in", stream.read())
        stream.close()
        # use environment variables to set author and committer.
        # using the config didn't work in travis-ci.org.
        os.environ["GIT_AUTHOR_NAME"] = "<NAME>"
        os.environ["GIT_AUTHOR_EMAIL"] = "<EMAIL>"
        os.environ["GIT_COMMITTER_NAME"] = "<NAME>"
        os.environ["GIT_COMMITTER_EMAIL"] = "<EMAIL>"

    def __cleanup_repo(self):
        """Delete the git repository"""
        os.chdir(self.lastCWD)
{'fraction_non_alphanumeric': 0.12656641604010024, 'fraction_numerical': 0.007518796992481203, 'mean_word_length': 2.485589519650655, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '6923181', 'n_tokens_mistral': 1282, 'n_tokens_neox': 1250, 'n_words': 299}