<commit_before>#!/usr/bin/env python
from subprocess import *
import sys
import re

__version__ = '0.1.2'
__author__ = '<NAME> <<EMAIL>>'
__license__ = 'NewBSDLicense'

OK_COLOR = "[32m%s[0m"
FAIL_COLOR = "[31m%s[0m"
ERROR_COLOR = "[33m%s[0m"
FUNC_COLOR = "[36m%s[0m"


def parse_result_line(line):
    err = False
    fail = False
    if 'errors' in line:
        err = True
    if 'failures' in line:
        fail = True
    if err and fail:
        f = line.split('=')[1].split(',')[0]
        e = line.split('=')[2].split(')')[0]
        result = "(" + FAIL_COLOR % "failures" + "=" + FAIL_COLOR % f + ", "
        result += ERROR_COLOR % "errors" + "=" + ERROR_COLOR % e + ")"
    elif fail and not err:
        l = line.split('=')[1].split(')')[0]
        result = "(" + FAIL_COLOR % "failures" + "=" + FAIL_COLOR % l + ")"
    elif err and not fail:
        l = line.split('=')[1].split(')')[0]
        result = "(" + ERROR_COLOR % "errors" + "=" + ERROR_COLOR % l + ")"
    return FAIL_COLOR % "FAILED" + " %s" % result


def parse_lineone(line):
    result = []
    line = line.strip()
    for l in line:
        if '.' == l:
            result.append(OK_COLOR % ".")
        elif 'E' == l:
            result.append(ERROR_COLOR % "E")
        elif 'F' == l:
            result.append(FAIL_COLOR % "F")
        else:
            result.append(l)
    return "".join(result)


def coloring_method(line):
    return FUNC_COLOR % line


def parse_unittest_result(lines):
    result = []
    err = re.compile("ERROR:")
    fail = re.compile("FAIL:")
    ok = re.compile("OK")
    failed = re.compile("FAILED")
    result.append(parse_lineone(lines[0])+'\n')
    for line in lines[1:]:
        if ok.match(line):
            r = OK_COLOR % "OK" + "\n"
        elif failed.match(line):
            r = parse_result_line(line)
        elif fail.match(line):
            r = FAIL_COLOR % "FAIL" + ":" + coloring_method(line[5:])
        elif err.match(line):
            r = ERROR_COLOR % "ERROR" + ":" + coloring_method(line[6:])
        else:
            r = line
        result.append(r)
    return "".join(result)


def main():
    if sys.argv[1:]:
        p = Popen(['python', sys.argv[1]], stdout=PIPE, stderr=PIPE)
        r = p.communicate()[1]
        print parse_unittest_result(r.splitlines(1))
    else:
        print parse_unittest_result(sys.stdin.readlines())


if __name__ == '__main__':
    main()<commit_msg>fixed: do not hang-up when no argument<commit_after>#!/usr/bin/env python
from subprocess import *
from select import poll, POLLIN
import sys
import re

__version__ = '0.1.2'
__author__ = '<NAME> <<EMAIL>>'
__license__ = 'NewBSDLicense'

OK_COLOR = "[32m%s[0m"
FAIL_COLOR = "[31m%s[0m"
ERROR_COLOR = "[33m%s[0m"
FUNC_COLOR = "[36m%s[0m"


def parse_result_line(line):
    err = False
    fail = False
    if 'errors' in line:
        err = True
    if 'failures' in line:
        fail = True
    if err and fail:
        f = line.split('=')[1].split(',')[0]
        e = line.split('=')[2].split(')')[0]
        result = "(" + FAIL_COLOR % "failures" + "=" + FAIL_COLOR % f + ", "
        result += ERROR_COLOR % "errors" + "=" + ERROR_COLOR % e + ")"
    elif fail and not err:
        l = line.split('=')[1].split(')')[0]
        result = "(" + FAIL_COLOR % "failures" + "=" + FAIL_COLOR % l + ")"
    elif err and not fail:
        l = line.split('=')[1].split(')')[0]
        result = "(" + ERROR_COLOR % "errors" + "=" + ERROR_COLOR % l + ")"
    return FAIL_COLOR % "FAILED" + " %s" % result


def parse_lineone(line):
    result = []
    line = line.strip()
    for l in line:
        if '.' == l:
            result.append(OK_COLOR % ".")
        elif 'E' == l:
            result.append(ERROR_COLOR % "E")
        elif 'F' == l:
            result.append(FAIL_COLOR % "F")
        else:
            result.append(l)
    return "".join(result)


def coloring_method(line):
    return FUNC_COLOR % line


def parse_unittest_result(lines):
    result = []
    err = re.compile("ERROR:")
    fail = re.compile("FAIL:")
    ok = re.compile("OK")
    failed = re.compile("FAILED")
    result.append(parse_lineone(lines[0])+'\n')
    for line in lines[1:]:
        if ok.match(line):
            r = OK_COLOR % "OK" + "\n"
        elif failed.match(line):
            r = parse_result_line(line)
        elif fail.match(line):
            r = FAIL_COLOR % "FAIL" + ":" + coloring_method(line[5:])
        elif err.match(line):
            r = ERROR_COLOR % "ERROR" + ":" + coloring_method(line[6:])
        else:
            r = line
        result.append(r)
    return "".join(result)


def main():
    if sys.argv[1:]:
        p = Popen(['python', sys.argv[1]], stdout=PIPE, stderr=PIPE)
        r = p.communicate()[1]
        print parse_unittest_result(r.splitlines(1))
    else:
        poller = poll()
        poller.register(sys.stdin, POLLIN)
        if len(poller.poll(1)) >= 1:
            print parse_unittest_result(sys.stdin.readlines())
        else:
            print "usage: pyrg pythontest.py"
            print "       python pythontest.py |& pyrg"
            print ""


if __name__ == '__main__':
    main()
{'fraction_non_alphanumeric': 0.17543520309477756, 'fraction_numerical': 0.012379110251450677, 'mean_word_length': 2.2852604828462515, 'pattern_counts': {'":': 4, '<': 9, '<?xml version=': 0, '>': 10, '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': '4676975', 'n_tokens_mistral': 1886, 'n_tokens_neox': 1824, 'n_words': 395}