<commit_before>import sys
import traceback
from .core import Result


class TextResult(Result):
    def __init__(self, stream=sys.stderr):
        self.stream = stream
        super().__init__()

    def _print(self, *args, sep=' ', end='\n', flush=True):
        print(*args, sep=sep, end=end, file=self.stream, flush=flush)

    def assertion_passed(self, *args, **kwargs):
        super().assertion_passed(*args, **kwargs)
        self._print('.', end='')

    def assertion_failed(self, *args, **kwargs):
        super().assertion_failed(*args, **kwargs)
        self._print('F', end='')

    def assertion_errored(self, *args, **kwargs):
        super().assertion_errored(*args, **kwargs)
        self._print('E', end='')

    def context_errored(self, *args, **kwargs):
        super().context_errored(*args, **kwargs)
        self._print('E', end='')

    def summarise(self):
        self._print('')
        if self.failed:
            for tup in self.context_errors + self.assertion_errors + self.assertion_failures:
                self.print_assertion_failure(*tup)
        self._print("----------------------------------------------------------------------")
        if self.failed:
            self._print('FAILED!')
            self._print(self.failure_numbers())
        else:
            self._print('PASSED!')
            self._print(self.success_numbers())

    def print_assertion_failure(self, assertion, exception, extracted_tb):
        self._print("======================================================================")
        self._print("FAIL:" if isinstance(exception, AssertionError) else "ERROR:", assertion.name)
        self._print("----------------------------------------------------------------------")
        self._print("Traceback (most recent call last):")
        self._print(''.join(traceback.format_list(extracted_tb)), end='')
        self._print(''.join(traceback.format_exception_only(exception.__class__, exception)), end='')<commit_msg>Minor refactor for reporting code<commit_after>import sys
import traceback
from .core import Result


class TextResult(Result):
    dashes = '-' * 70
    equalses = '=' * 70

    def __init__(self, stream=sys.stderr):
        self.stream = stream
        super().__init__()

    def _print(self, *args, sep=' ', end='\n', flush=True):
        print(*args, sep=sep, end=end, file=self.stream, flush=flush)

    def assertion_passed(self, *args, **kwargs):
        super().assertion_passed(*args, **kwargs)
        self._print('.', end='')

    def assertion_failed(self, *args, **kwargs):
        super().assertion_failed(*args, **kwargs)
        self._print('F', end='')

    def assertion_errored(self, *args, **kwargs):
        super().assertion_errored(*args, **kwargs)
        self._print('E', end='')

    def context_errored(self, *args, **kwargs):
        super().context_errored(*args, **kwargs)
        self._print('E', end='')

    def summarise(self):
        self._print('')
        if self.failed:
            for tup in self.context_errors + self.assertion_errors + self.assertion_failures:
                self.print_assertion_failure(*tup)
        self._print(self.dashes)
        if self.failed:
            self._print('FAILED!')
            self._print(self.failure_numbers())
        else:
            self._print('PASSED!')
            self._print(self.success_numbers())

    def print_assertion_failure(self, assertion, exception, extracted_tb):
        self._print(self.equalses)
        self._print("FAIL:" if isinstance(exception, AssertionError) else "ERROR:", assertion.name)
        self._print(self.dashes)
        self._print("Traceback (most recent call last):")
        self._print(''.join(traceback.format_list(extracted_tb)), end='')
        self._print(''.join(traceback.format_exception_only(exception.__class__, exception)), end='')
{'fraction_non_alphanumeric': 0.1990140114167099, 'fraction_numerical': 0.0010378827192527244, 'mean_word_length': 2.678435114503817, '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': '6783150', 'n_tokens_mistral': 1124, 'n_tokens_neox': 1072, 'n_words': 213}