<commit_before>import mock

from readthedocs.doc_builder.environments import BuildEnvironment


class EnvironmentMockGroup(object):
    '''Mock out necessary environment pieces'''

    def __init__(self):
        self.patches = {
            'popen': mock.patch('subprocess.Popen'),
            'process': mock.Mock(),

            'api_versions': mock.patch(
                'readthedocs.projects.models.Project.api_versions'),
            'api': mock.patch('slumber.Resource'),

            'append_conf': mock.patch(
                'readthedocs.doc_builder.backends.sphinx.BaseSphinx.append_conf'),
            'move': mock.patch(
                'readthedocs.doc_builder.backends.sphinx.BaseSphinx.move'),
            'conf_dir': mock.patch(
                'readthedocs.projects.models.Project.conf_dir'),
            'html_build': mock.patch(
                'readthedocs.doc_builder.backends.sphinx.HtmlBuilder.build'),
            'html_move': mock.patch(
                'readthedocs.doc_builder.backends.sphinx.HtmlBuilder.move'),
            'pdf_build': mock.patch(
                'readthedocs.doc_builder.backends.sphinx.PdfBuilder.build'),
            'pdf_move': mock.patch(
                'readthedocs.doc_builder.backends.sphinx.PdfBuilder.move'),
            'epub_build': mock.patch(
                'readthedocs.doc_builder.backends.sphinx.EpubBuilder.build'),
            'epub_move': mock.patch(
                'readthedocs.doc_builder.backends.sphinx.EpubBuilder.move'),
            'glob': mock.patch('readthedocs.doc_builder.backends.sphinx.glob'),

            'docker': mock.patch('readthedocs.doc_builder.environments.Client'),
            'docker_client': mock.Mock(),
        }
        self.mocks = {}

    def start(self):
        '''Create a patch object for class patches'''
        for patch in self.patches:
            self.mocks[patch] = self.patches[patch].start()
        self.mocks['process'].communicate.return_value = ('', '')
        self.mocks['process'].returncode = 0
        self.mocks['popen'].return_value = self.mocks['process']
        self.mocks['docker'].return_value = self.mocks['docker_client']
        self.mocks['glob'].return_value = ['/tmp/rtd/foo.tex']
        self.mocks['conf_dir'].return_value = '/tmp/rtd'

    def stop(self):
        for patch in self.patches:
            try:
                self.patches[patch].stop()
            except RuntimeError:
                pass

    def configure_mock(self, mock, kwargs):
        '''Configure object mocks'''
        self.mocks[mock].configure_mock(**kwargs)

    def __getattr__(self, name):
        try:
            return self.mocks[name]
        except KeyError:
            raise AttributeError()
<commit_msg>Forgot to clock the nonblock lock mock<commit_after>import mock

from readthedocs.doc_builder.environments import BuildEnvironment


class EnvironmentMockGroup(object):
    '''Mock out necessary environment pieces'''

    def __init__(self):
        self.patches = {
            'popen': mock.patch('subprocess.Popen'),
            'process': mock.Mock(),
            'api': mock.patch('slumber.Resource'),

            'api_versions': mock.patch(
                'readthedocs.projects.models.Project.api_versions'),
            'non_blocking_lock': mock.patch(
                'readthedocs.vcs_support.utils.NonBlockingLock.__enter__'),

            'append_conf': mock.patch(
                'readthedocs.doc_builder.backends.sphinx.BaseSphinx.append_conf'),
            'move': mock.patch(
                'readthedocs.doc_builder.backends.sphinx.BaseSphinx.move'),
            'conf_dir': mock.patch(
                'readthedocs.projects.models.Project.conf_dir'),
            'html_build': mock.patch(
                'readthedocs.doc_builder.backends.sphinx.HtmlBuilder.build'),
            'html_move': mock.patch(
                'readthedocs.doc_builder.backends.sphinx.HtmlBuilder.move'),
            'pdf_build': mock.patch(
                'readthedocs.doc_builder.backends.sphinx.PdfBuilder.build'),
            'pdf_move': mock.patch(
                'readthedocs.doc_builder.backends.sphinx.PdfBuilder.move'),
            'epub_build': mock.patch(
                'readthedocs.doc_builder.backends.sphinx.EpubBuilder.build'),
            'epub_move': mock.patch(
                'readthedocs.doc_builder.backends.sphinx.EpubBuilder.move'),
            'glob': mock.patch('readthedocs.doc_builder.backends.sphinx.glob'),

            'docker': mock.patch('readthedocs.doc_builder.environments.Client'),
            'docker_client': mock.Mock(),
        }
        self.mocks = {}

    def start(self):
        '''Create a patch object for class patches'''
        for patch in self.patches:
            self.mocks[patch] = self.patches[patch].start()
        self.mocks['process'].communicate.return_value = ('', '')
        self.mocks['process'].returncode = 0
        self.mocks['popen'].return_value = self.mocks['process']
        self.mocks['docker'].return_value = self.mocks['docker_client']
        self.mocks['glob'].return_value = ['/tmp/rtd/foo.tex']
        self.mocks['conf_dir'].return_value = '/tmp/rtd'

    def stop(self):
        for patch in self.patches:
            try:
                self.patches[patch].stop()
            except RuntimeError:
                pass

    def configure_mock(self, mock, kwargs):
        '''Configure object mocks'''
        self.mocks[mock].configure_mock(**kwargs)

    def __getattr__(self, name):
        try:
            return self.mocks[name]
        except KeyError:
            raise AttributeError()

{'fraction_non_alphanumeric': 0.12994652406417112, 'fraction_numerical': 0.00035650623885918, 'mean_word_length': 2.2452284557547717, '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': '5889101', 'n_tokens_mistral': 1735, 'n_tokens_neox': 1652, 'n_words': 237}