<commit_before>from subunit import test_results


class TestResultFilter(test_results.TestResultFilter):
    """Test result filter."""

    def _get_concrete_result(self):
        # XXX: This is really crappy. It assumes that the test result we
        # actually care about is decorated and that we can find our way to the
        # one we care about. We want to report counts before filtering, so we
        # should actually use two result objects - one to count and one to
        # show. Arguably also the testsRun incrementing facility should be in
        # testtools / subunit
        concrete = self
        while True:
            next = getattr(concrete, 'decorated', None)
            if next is None:
                return concrete
            concrete = next

    def _filtered(self):
        super(TestResultFilter, self)._filtered()
        concrete = self._get_concrete_result()
        concrete.testsRun += 1

    def stopTest(self, test):
        # Filter out 'time' calls, because we want to forward those events
        # regardless of whether the test is filtered.
        buffered_calls = []
        for method, args, kwargs in self._buffered_calls:
            if method == 'time':
                self.decorated.time(*args, **kwargs)
            else:
                buffered_calls.append((method, args, kwargs))
        self._buffered_calls = buffered_calls
        super(TestResultFilter, self).stopTest(test)<commit_msg>Mark upstreaming<commit_after>from subunit import test_results


class TestResultFilter(test_results.TestResultFilter):
    """Test result filter."""

    def _get_concrete_result(self):
        # XXX: This is really crappy. It assumes that the test result we
        # actually care about is decorated and that we can find our way to the
        # one we care about. We want to report counts before filtering, so we
        # should actually use two result objects - one to count and one to
        # show. Arguably also the testsRun incrementing facility should be in
        # testtools / subunit
        concrete = self
        while True:
            next = getattr(concrete, 'decorated', None)
            if next is None:
                return concrete
            concrete = next

    def _filtered(self):
        super(TestResultFilter, self)._filtered()
        concrete = self._get_concrete_result()
        concrete.testsRun += 1

    def stopTest(self, test):
        # Filter out 'time' calls, because we want to forward those events
        # regardless of whether the test is filtered.
        #
        # XXX: Should this be pushed into subunit?
        buffered_calls = []
        for method, args, kwargs in self._buffered_calls:
            if method == 'time':
                self.decorated.time(*args, **kwargs)
            else:
                buffered_calls.append((method, args, kwargs))
        self._buffered_calls = buffered_calls
        super(TestResultFilter, self).stopTest(test)
{'fraction_non_alphanumeric': 0.0708502024291498, 'fraction_numerical': 0.0006747638326585695, 'mean_word_length': 2.276243093922652, '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': '6480100', 'n_tokens_mistral': 762, 'n_tokens_neox': 744, 'n_words': 285}