<commit_before>from os import getcwd
from sets import Set
from ctypes import *
import __builtin__

global here
global funny_joke
global test_functions

here = getcwd()
funny_joke = """Combien faut-il d'informaticiens pour changer une ampoule ?
Aucun. C'est un probleme hardware."""
test_functions = Set([])

def add_lib(lib_name):
    __builtin__.lib = cdll.LoadLibrary(here + "/" +  lib_name)

def joke():
    print(funny_joke)

def call(func, return_type):
    func.restype = return_type
    return func()

def Test(func):
    test_functions.add(func)

def all_tests():
    for test in test_functions:
        test()
<commit_msg>Adding printing system<commit_after>from os import getcwd
from sets import Set
from ctypes import *
from cStringIO import StringIO
from termcolor import cprint
import colorama
import sys
import __builtin__

global here
global funny_joke
global test_functions

here = getcwd()
test_functions = Set([])

# Constant format output strings
success_string  = '[OK] {}'
fail_string     = '[KO] {}'
success_color   = 'green'
fail_color      = 'red'
print_args      = []
print_success = lambda *args: cprint(success_string.format(*args),
                                     success_color)
print_fail    = lambda *args: cprint(fail_string.format(*args),
                                     fail_color)

# Init ripe with lib name
def init(lib_name):
    """lib_name -- name of the .so to load
    """
    colorama.init()
    __builtin__.lib = cdll.LoadLibrary(here + "/" +  lib_name)

# Decorator for functions attempting to be tested
def Test(func):
    """Decorator registering test functions.
    Test function have to return a boolean and can modify the output by
    changing ripe.header, ripe.footer, ripe.fail_msg, ripe.success_msg values.
    """
    test_functions.add(func)

# Stdout catching
class _Capturing(list):
    """Capturing capture printed content and add it in itself.
    Use guide:
    with Capturing() as stdout, stderr:
        do_something(my_object)
    """
    def __enter__(self):
        self._stdout = sys.stdout
        self._stderr = sys.stderr
        sys.stdout = self._stdoutio = StringIO()
        sys.stderr = self._stderrio = StringIO()
        return self
    def __exit__(self, *args):
        self.extend((self._stdoutio.getvalue().splitlines(),
                      self._stderrio.getvalue().splitlines()))
        sys.stdout = self._stdout
        sys.stderr = self._stderr

# Call method that capture return value, stdout and stderr
def call(func, ret_type, *args):
    """call(func, ret_type, *args) -> (ret_value, stdout, stderr)
    Call a fucntion and return it value cast with ret_type and also stdout
    and stderr.
    func     -- function ptr accessible through `lib` global variable.
    ret_type -- return type of the c function (ctypes type)
    """
    ret = None
    stdout = None
    stderr = None
    func.restype = ret_type
    with _Capturing() as streams:
        ret = func(*args)
    return (ret, streams[0], streams[1])

# TODO:
# def run(index): 
#    """Run tests with specific argument passed to the Test decorator"""

def run_tests():
    """Run all tests."""
    # TODO: save umber of tests done and restart to given one if handle_fail
    # is true
    for test in test_functions:
        print_args = [test.__name__]
        if test():
            print_success(*print_args)
        else:
            print_fail(*print_args)

{'fraction_non_alphanumeric': 0.0973115137346581, 'fraction_numerical': 0.0005844535359438924, 'mean_word_length': 2.9390103567318757, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7004831', 'n_tokens_mistral': 1038, 'n_tokens_neox': 1026, 'n_words': 329}