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

import copy
from datetime import datetime
from functools import partial

from mamba import runnable
from mamba.example import PendingExample


class ExampleGroup(runnable.Runnable):

    def __init__(self, description, parent=None, tags=None):
        super(ExampleGroup, self).__init__(parent=parent, tags=tags)

        self.description = description
        self.examples = []
        self.hooks = {
            'before_each': [],
            'after_each': [],
            'before_all': [],
            'after_all': []
        }
        self.helpers = {}

    def __iter__(self):
        return iter(self.examples)

    def execute(self, reporter, execution_context, tags=None):
        if not self._children_included_in_execution(tags):
            return

        self._start(reporter)
        try:
            self._bind_helpers_to(execution_context)
            self.execute_hook('before_all', execution_context)

            for example in self:
                example.execute(reporter,
                                copy.copy(execution_context),
                                tags=tags)

            self.execute_hook('after_all', execution_context)
        except Exception:
            self.set_failed()

        self._finish(reporter)

    def _children_included_in_execution(self, tags):
        return any(example.included_in_execution(tags) for example in self)

    def _start(self, reporter):
        self._begin = datetime.utcnow()
        reporter.example_group_started(self)

    def _bind_helpers_to(self, execution_context):
        for name, method in self.helpers.items():
            setattr(execution_context, name, partial(method, execution_context))

    def execute_hook(self, hook, execution_context):
        if self.parent is not None:
            self.parent.execute_hook(hook, execution_context)

        for registered in self.hooks.get(hook, []):
            try:
                if hasattr(registered, 'im_func'):
                    registered.im_func(execution_context)
                elif callable(registered):
                    registered(execution_context)
            except Exception:
                self.fail()

    def _finish(self, reporter):
        self.elapsed_time = datetime.utcnow() - self._begin
        reporter.example_group_finished(self)

    @property
    def name(self):
        return self.description.split('--')[0]

    def append(self, example):
        self.examples.append(example)
        example.parent = self

    def failed(self):
        return any(example.failed() for example in self.examples)

    def fail(self):
        super(ExampleGroup, self).fail()

        for example in self.examples:
            example.fail()


class PendingExampleGroup(ExampleGroup):

    def execute(self, reporter, execution_context, tags=None):
        reporter.example_group_pending(self)

        for example in self:
            example.execute(reporter, copy.copy(execution_context))

    def append(self, example):
        if not type(example) in [PendingExample, PendingExampleGroup]:
            raise TypeError('A pending example or example group expected')

        super(PendingExampleGroup, self).append(example)
<commit_msg>Replace set_failed call to failed<commit_after># -*- coding: utf-8 -*-

import copy
from datetime import datetime
from functools import partial

from mamba import runnable
from mamba.example import PendingExample


class ExampleGroup(runnable.Runnable):

    def __init__(self, description, parent=None, tags=None):
        super(ExampleGroup, self).__init__(parent=parent, tags=tags)

        self.description = description
        self.examples = []
        self.hooks = {
            'before_each': [],
            'after_each': [],
            'before_all': [],
            'after_all': []
        }
        self.helpers = {}

    def __iter__(self):
        return iter(self.examples)

    def execute(self, reporter, execution_context, tags=None):
        if not self._children_included_in_execution(tags):
            return

        self._start(reporter)
        try:
            self._bind_helpers_to(execution_context)
            self.execute_hook('before_all', execution_context)

            for example in self:
                example.execute(reporter,
                                copy.copy(execution_context),
                                tags=tags)

            self.execute_hook('after_all', execution_context)
        except Exception :
            self.failed()

        self._finish(reporter)

    def _children_included_in_execution(self, tags):
        return any(example.included_in_execution(tags) for example in self)

    def _start(self, reporter):
        self._begin = datetime.utcnow()
        reporter.example_group_started(self)

    def _bind_helpers_to(self, execution_context):
        for name, method in self.helpers.items():
            setattr(execution_context, name, partial(method, execution_context))

    def execute_hook(self, hook, execution_context):
        if self.parent is not None:
            self.parent.execute_hook(hook, execution_context)

        for registered in self.hooks.get(hook, []):
            try:
                if hasattr(registered, 'im_func'):
                    registered.im_func(execution_context)
                elif callable(registered):
                    registered(execution_context)
            except Exception:
                self.fail()

    def _finish(self, reporter):
        self.elapsed_time = datetime.utcnow() - self._begin
        reporter.example_group_finished(self)

    @property
    def name(self):
        return self.description.split('--')[0]

    def append(self, example):
        self.examples.append(example)
        example.parent = self

    def failed(self):
        return any(example.failed() for example in self.examples)

    def fail(self):
        super(ExampleGroup, self).fail()

        for example in self.examples:
            example.fail()


class PendingExampleGroup(ExampleGroup):

    def execute(self, reporter, execution_context, tags=None):
        reporter.example_group_pending(self)

        for example in self:
            example.execute(reporter, copy.copy(execution_context))

    def append(self, example):
        if not type(example) in [PendingExample, PendingExampleGroup]:
            raise TypeError('A pending example or example group expected')

        super(PendingExampleGroup, self).append(example)

{'fraction_non_alphanumeric': 0.09321642824180895, 'fraction_numerical': 0.0006152899553914783, 'mean_word_length': 2.348094747682801, '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': '3705509', 'n_tokens_mistral': 1775, 'n_tokens_neox': 1686, 'n_words': 388}