<commit_before>import os
from contextlib import contextmanager
from doctest import DocTestSuite
from tempfile import NamedTemporaryFile, TemporaryDirectory
from unittest import TestCase

from runcommands.commands import copy_file


def load_tests(loader, tests, ignore):
    tests.addTests(DocTestSuite("runcommands.util.decorators"))
    tests.addTests(DocTestSuite("runcommands.util.misc"))
    tests.addTests(DocTestSuite("runcommands.util.path"))
    tests.addTests(DocTestSuite("runcommands.util.string"))
    return tests


@contextmanager
def copy(contents, destination_dir=False, **kwargs):
    with NamedTemporaryFile("w", delete=False) as tp:
        tp.write(contents)

    source = tp.name

    if destination_dir:
        with TemporaryDirectory() as destination:
            path = copy_file(source, destination, **kwargs)
            yield source, destination, path
            os.remove(source)
    else:
        destination = source + ".copy"
        path = copy_file(source, destination, **kwargs)
        yield source, destination, path
        os.remove(source)<commit_msg>Change how doctests are set up<commit_after>import os
from contextlib import contextmanager
from doctest import DocTestSuite
from tempfile import NamedTemporaryFile, TemporaryDirectory
from unittest import TestCase

import runcommands.util.decorators
import runcommands.util.misc
import runcommands.util.path
import runcommands.util.string
from runcommands.commands import copy_file


def load_tests(loader, tests, ignore):
    tests.addTests(DocTestSuite(runcommands.util.decorators))
    tests.addTests(DocTestSuite(runcommands.util.misc))
    tests.addTests(DocTestSuite(runcommands.util.path))
    tests.addTests(DocTestSuite(runcommands.util.string))
    return tests


@contextmanager
def copy(contents, destination_dir=False, **kwargs):
    with NamedTemporaryFile("w", delete=False) as tp:
        tp.write(contents)

    source = tp.name

    if destination_dir:
        with TemporaryDirectory() as destination:
            path = copy_file(source, destination, **kwargs)
            yield source, destination, path
            os.remove(source)
    else:
        destination = source + ".copy"
        path = copy_file(source, destination, **kwargs)
        yield source, destination, path
        os.remove(source)
{'fraction_non_alphanumeric': 0.08710651142733937, 'fraction_numerical': 0.0, 'mean_word_length': 3.9572649572649574, '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': '1831228', 'n_tokens_mistral': 638, 'n_tokens_neox': 626, 'n_words': 160}