<commit_before>from __future__ import absolute_import

import sys

from nose.plugins.base import Plugin

from doubles.lifecycle import setup, verify, teardown
from doubles.exceptions import MockExpectationError


class NoseIntegration(Plugin):
    name = 'doubles'

    def beforeTest(self, test):
        setup()

    def afterTest(self, test):
        teardown()

    def prepareTestCase(self, test):
        def wrapped(result):
            test.test.run()
            if result.failures or result.errors:
                return
            try:
                verify()
            except MockExpectationError:
                result.addFailure(test.test,  sys.exc_info())
        return wrapped
<commit_msg>Make nose integration a bit safer<commit_after>from __future__ import absolute_import

import sys

from nose.plugins.base import Plugin

from doubles.lifecycle import setup, verify, teardown, current_space
from doubles.exceptions import MockExpectationError


class NoseIntegration(Plugin):
    name = 'doubles'

    def beforeTest(self, test):
        setup()

    def afterTest(self, test):
        if current_space():
            teardown()

    def prepareTestCase(self, test):
        def wrapped(result):
            test.test.run()
            if result.failures or result.errors:
                return
            try:
                if current_space():
                    verify()
            except MockExpectationError:
                result.addFailure(test.test,  sys.exc_info())
        return wrapped

{'fraction_non_alphanumeric': 0.07380796864794252, 'fraction_numerical': 0.0, 'mean_word_length': 2.225263157894737, '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': '4176949', 'n_tokens_mistral': 413, 'n_tokens_neox': 389, 'n_words': 112}