<commit_before>import tempfile
import os
import sys
import shutil
import contextlib
import subprocess

def check_output(args, stderr=None, retcode=0, input=None, *other, **keys):
    """Run a subprocess and return its output.
       If the return code from the subprocess does not match `retcode`, an
       `OSError` exception is raised.

       Note: this is similar to `subprocess.check_output` but that requires
       Python 2.7.
    """
    p = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=stderr,
                         stdin=subprocess.PIPE if input else None,
                         *other, **keys)
    stdout, stderr = p.communicate(input)
    if p.returncode != retcode:
        raise OSError("Process %s exited with code %d, output %s"
                      % (" ".join(args), p.returncode, stdout))
    return stdout

@contextlib.contextmanager
def temporary_directory():
    _tmpdir = tempfile.mkdtemp()
    yield _tmpdir
    shutil.rmtree(_tmpdir, ignore_errors=True)

@contextlib.contextmanager
def temporary_working_directory():
    _tmpdir = tempfile.mkdtemp()
    _olddir = os.getcwd()
    os.chdir(_tmpdir)
    yield _tmpdir
    os.chdir(_olddir)
    shutil.rmtree(_tmpdir, ignore_errors=True)

@contextlib.contextmanager
def mocked_object(parent, objname, replacement):
    """Temporarily replace parent.objname with replacement.
       Typically `parent` is a module or class object."""
    oldobj = getattr(parent, objname)<commit_msg>Convert output to str type under Python 3.<commit_after>import tempfile
import os
import sys
import shutil
import contextlib
import subprocess

def check_output(args, stderr=None, retcode=0, input=None, *other, **keys):
    """Run a subprocess and return its output.
       If the return code from the subprocess does not match `retcode`, an
       `OSError` exception is raised.

       Note: this is similar to `subprocess.check_output` but that requires
       Python 2.7.
    """
    p = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=stderr,
                         stdin=subprocess.PIPE if input else None,
                         universal_newlines=True, *other, **keys)
    stdout, stderr = p.communicate(input)
    if p.returncode != retcode:
        raise OSError("Process %s exited with code %d, output %s"
                      % (" ".join(args), p.returncode, stdout))
    return stdout

@contextlib.contextmanager
def temporary_directory():
    _tmpdir = tempfile.mkdtemp()
    yield _tmpdir
    shutil.rmtree(_tmpdir, ignore_errors=True)

@contextlib.contextmanager
def temporary_working_directory():
    _tmpdir = tempfile.mkdtemp()
    _olddir = os.getcwd()
    os.chdir(_tmpdir)
    yield _tmpdir
    os.chdir(_olddir)
    shutil.rmtree(_tmpdir, ignore_errors=True)

@contextlib.contextmanager
def mocked_object(parent, objname, replacement):
    """Temporarily replace parent.objname with replacement.
       Typically `parent` is a module or class object."""
    oldobj = getattr(parent, objname)
{'fraction_non_alphanumeric': 0.09512683578104139, 'fraction_numerical': 0.002336448598130841, 'mean_word_length': 3.233050847457627, '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': '7435374', 'n_tokens_mistral': 916, 'n_tokens_neox': 893, 'n_words': 261}