<commit_before>#!/usr/bin/env python
# -*- coding: utf-8 -*-

# pyvows testing engine
# https://github.com/heynemann/pyvows

# Licensed under the MIT license:
# http://www.opensource.org/licenses/mit-license
# Copyright (c) 2011 <NAME> <EMAIL>

import sys
import re
import traceback

from lxml import etree
from colorama import init, Fore, Style

PROGRESS_SIZE = 50

class VowsDefaultReporter(object):
    honored = Fore.GREEN + Style.BRIGHT + '✓' + Fore.RESET + Style.RESET_ALL
    broken = Fore.RED + Style.BRIGHT + '✗' + Fore.RESET + Style.RESET_ALL

    def __init__(self, result):
        init(autoreset=True)
        self.result = result
        self.tab = " " * 2
        self.indent = 1

    def camel_split(self, string):
        return re.sub('((?=[A-Z][a-z])|(?<=[a-z])(?=[A-Z])|(?=[0-9]\b))', ' ', string).strip()

    def under_split(self, string):
        return ' '.join(string.split('_'))

    @classmethod
    def handle_success(cls, vow):
        sys.stdout.write(cls.honored)

    @classmethod
    def handle_error(cls, vow):
        sys.stdout.write(cls.broken)

    def pretty_print(self):
        print
        print
        if not self.result:
            print " %s No vows found! » 0 honored • 0 broken (0.0s)" % self.broken
            return

        for context in self.result.contexts:
            self.print_context(context['name'], context)
        print
        print "%s%s OK » %d honored • %d broken (%.6fs)" % (
                self.tab * self.indent,
                self.honored if self.result.successful else self.broken,
                self.result.successful_tests,
                self.result.errored_tests,
                self.result.ellapsed_time
        )

    def print_context(self, name, context):
        print "%s%s" % (self.tab * self.indent, self.camel_split(name).capitalize())
        self.indent += 1

        print_test = lambda icon, test_name: "%s%s %s" % (self.tab * self.indent, icon, self.camel_split(self.under_split(test_name)).capitalize())

        for test in context['tests']:
            if test['succeeded']:
                print print_test(VowsDefaultReporter.honored, test['name'])
            else:
                print print_test(VowsDefaultReporter.broken, test['name'])
                error = test['error']
                exc_type, exc_value, exc_traceback = error['type'], error['value'], error['traceback']
                error_msg = traceback.format_exception(exc_type, exc_value, exc_traceback)
                error_msg = (self.tab * (self.indent + 2)).join(error_msg)
                print "%s%s" % (self.tab * (self.indent + 2), Fore.RED + exc_value.message.encode('utf-8') + Fore.RESET)
                print
                print "%s%s" % (self.tab * (self.indent + 2), error_msg)

                if isinstance(test['topic'], Exception):
                    print
                    print "%s%s" % (self.tab * (self.indent + 3), Fore.RED + 'Original Exception' + Fore.RESET)
                    print
                    exc_type, exc_value, exc_traceback = test['context_instance'].topic_error
                    print "%s%s" % (self.tab * (self.indent + 3), Fore.RED + str(exc_value) + Fore.RESET)
                    error_msg = traceback.format_exception(exc_type, exc_value, exc_traceback)
                    error_msg = (self.tab * (self.indent + 3)).join(error_msg)
                    print "%s%s" % (self.tab * (self.indent + 3), error_msg)
 
                if 'file' in test:
                    print "%s%s" % (self.tab * (self.indent + 2), Fore.RED + "(found in %s at line %s)" % (test['file'], test['lineno']) + Fore.RESET)

        for context in context['contexts']:
            self.print_context(context['name'], context)

        self.indent -= 1
<commit_msg>Reporting only original error<commit_after>#!/usr/bin/env python
# -*- coding: utf-8 -*-

# pyvows testing engine
# https://github.com/heynemann/pyvows

# Licensed under the MIT license:
# http://www.opensource.org/licenses/mit-license
# Copyright (c) 2011 <NAME> <EMAIL>

import sys
import re
import traceback

from lxml import etree
from colorama import init, Fore, Style

PROGRESS_SIZE = 50

class VowsDefaultReporter(object):
    honored = Fore.GREEN + Style.BRIGHT + '✓' + Fore.RESET + Style.RESET_ALL
    broken = Fore.RED + Style.BRIGHT + '✗' + Fore.RESET + Style.RESET_ALL

    def __init__(self, result):
        init(autoreset=True)
        self.result = result
        self.tab = " " * 2
        self.indent = 1

    def camel_split(self, string):
        return re.sub('((?=[A-Z][a-z])|(?<=[a-z])(?=[A-Z])|(?=[0-9]\b))', ' ', string).strip()

    def under_split(self, string):
        return ' '.join(string.split('_'))

    @classmethod
    def handle_success(cls, vow):
        sys.stdout.write(cls.honored)

    @classmethod
    def handle_error(cls, vow):
        sys.stdout.write(cls.broken)

    def pretty_print(self):
        print
        print
        if not self.result:
            print " %s No vows found! » 0 honored • 0 broken (0.0s)" % self.broken
            return

        for context in self.result.contexts:
            self.print_context(context['name'], context)
        print
        print "%s%s OK » %d honored • %d broken (%.6fs)" % (
                self.tab * self.indent,
                self.honored if self.result.successful else self.broken,
                self.result.successful_tests,
                self.result.errored_tests,
                self.result.ellapsed_time
        )

    def print_context(self, name, context):
        print "%s%s" % (self.tab * self.indent, self.camel_split(name).capitalize())
        self.indent += 1

        print_test = lambda icon, test_name: "%s%s %s" % (self.tab * self.indent, icon, self.camel_split(self.under_split(test_name)).capitalize())

        for test in context['tests']:
            if test['succeeded']:
                print print_test(VowsDefaultReporter.honored, test['name'])
            else:
                print print_test(VowsDefaultReporter.broken, test['name'])
                if isinstance(test['topic'], Exception):
                    print
                    print "%s%s" % (self.tab * (self.indent + 3), Fore.RED + 'Original Exception' + Fore.RESET)
                    print
                    exc_type, exc_value, exc_traceback = test['context_instance'].topic_error
                    print "%s%s" % (self.tab * (self.indent + 3), Fore.RED + str(exc_value) + Fore.RESET)
                    error_msg = traceback.format_exception(exc_type, exc_value, exc_traceback)
                    error_msg = (self.tab * (self.indent + 3)).join(error_msg)
                    print "%s%s" % (self.tab * (self.indent + 3), error_msg)
                else:
                    error = test['error']
                    exc_type, exc_value, exc_traceback = error['type'], error['value'], error['traceback']
                    error_msg = traceback.format_exception(exc_type, exc_value, exc_traceback)
                    error_msg = (self.tab * (self.indent + 2)).join(error_msg)
                    print "%s%s" % (self.tab * (self.indent + 2), Fore.RED + exc_value.message.encode('utf-8') + Fore.RESET)
                    print
                    print "%s%s" % (self.tab * (self.indent + 2), error_msg)

                if 'file' in test:
                    print "%s%s" % (self.tab * (self.indent + 2), Fore.RED + "(found in %s at line %s)" % (test['file'], test['lineno']) + Fore.RESET)

        for context in context['contexts']:
            self.print_context(context['name'], context)

        self.indent -= 1

{'fraction_non_alphanumeric': 0.14054693662897713, 'fraction_numerical': 0.007099658164606889, 'mean_word_length': 2.121460812474354, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 7, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 2}, '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': '468075', 'n_tokens_mistral': 2448, 'n_tokens_neox': 2298, 'n_words': 528}