<commit_before>
__usage__ = """Usage: %(program)s [-l log_level] [-n] [-h] app

Where OPTIONS is one or more of:

    -l,--log
        log level (DEBUG, INFO, WARNING, ERROR)

    -n,--no-color
        avoid using color in output
                
    -h,--help
        show usage and exit
        
and 'app' is the name of the app which tests we should drive
NOTE: the name app should be without the '.dev.hostname' ending part
"""

import os
import sys
import time
import getopt
import logging
import urllib2
import simplejson
import socket
# global socket timeout, seemed to help with a weird connection reset issue in appengine
socket.setdefaulttimeout(60)

program = sys.argv[0]

logging.basicConfig()
logger = logging.getLogger("main")
                
class colors:
    OK    = '\033[92m'
    FAIL  = '\033[91m'
    RESET = '\033[0m'

#-----------------------------------------------------------------------# 
                        
def drive_test(url):
    test = urllib2.urlopen(url + "?output=jsonsummary")
    return simplejson.loads(test.read())
                
def drive_app(app,color):
    out = sys.stdout
    
    acre_host = os.environ["ACRE_HOST_BASE"]
    acre_port = os.environ["ACRE_PORT"]
    host_delimiter_path = os.environ["ACRE_HOST_DELIMITER_PATH"]
    host = app + "." + host_delimiter_path + "." + acre_host + ":" + acre_port
    
    url = "http://" + host + "/acre/test?mode=discover&output=json"
    f = urllib2.urlopen(url)
    results = simplejson.loads(f.read())
    
    total_failures = 0
    total_tests = 0
    
    for t in results['testfiles']:
        test_url = t['run_url']
        test_results = drive_test(test_url)
        tests = test_results['total']
        failures = test_results['failures']
        total_tests += tests
        total_failures += failures
        test_name = test_url.split("test_")[1] + " "
        out.write(test_name.ljust(40,'.'))
        if color:
            if failures == 0:
                out.write(colors.OK)
            else:
                out.write(colors.FAIL)
        out.write(" %i/%i" % (failures, tests))
        if color:
            out.write(colors.RESET)
        out.write("\n")
        
    out.write("\n")
    
    out.write("Total: ")
    if color:
        if total_failures == 0:
            out.write(colors.OK)
        else:
            out.write(colors.FAIL)
    out.write("%i/%i" % (total_failures, total_tests))
    if color:
        out.write(colors.RESET)
    out.write("\n")
        
#-----------------------------------------------------------------------# 

def usage(msg=''):

    if msg:
        print >> sys.stderr, msg
        print >> sys.stderr
    print >> sys.stderr, __usage__ % globals()

def main():

    LOG_LEVEL = logging.ERROR
    color = True
    
    try:
        opts, args = getopt.getopt(sys.argv[1:], "hnl:", ["help", "no-color", "log="])
    except getopt.GetoptError, msg:
        usage(msg)
        sys.exit(1)
        
    if not len(args) == 1:
        usage()
        sys.exit(1)
    else:
        app = args[0]
        
    for o, a in opts:
        if o in ("-h", "--help"):
            usage()
            sys.exit()
        if o in ("-n", "--no-color"):
            color = False
        if o in ("-l", "--log"):
            LOG_LEVEL = eval('logging.' + a)

    logger.setLevel(LOG_LEVEL)
                
    drive_app(app,color)
    
#-----------------------------------------------------------------------# 

if __name__ == "__main__":
    main()
                
#---------------------------- End of File ------------------------------#
<commit_msg>return non zero if there tests fail, or no tests were run<commit_after>
__usage__ = """Usage: %(program)s [-l log_level] [-n] [-h] app

Where OPTIONS is one or more of:

    -l,--log
        log level (DEBUG, INFO, WARNING, ERROR)

    -n,--no-color
        avoid using color in output
                
    -h,--help
        show usage and exit
        
and 'app' is the name of the app which tests we should drive
NOTE: the name app should be without the '.dev.hostname' ending part
"""

import os
import sys
import time
import getopt
import logging
import urllib2
import simplejson
import socket
# global socket timeout, seemed to help with a weird connection reset issue in appengine
socket.setdefaulttimeout(60)

program = sys.argv[0]

logging.basicConfig()
logger = logging.getLogger("main")
                
class colors:
    OK    = '\033[92m'
    FAIL  = '\033[91m'
    RESET = '\033[0m'

#-----------------------------------------------------------------------# 
                        
def drive_test(url):
    test = urllib2.urlopen(url + "?output=jsonsummary")
    return simplejson.loads(test.read())
                
def drive_app(app,color):
    out = sys.stdout
    
    acre_host = os.environ["ACRE_HOST_BASE"]
    acre_port = os.environ["ACRE_PORT"]
    host_delimiter_path = os.environ["ACRE_HOST_DELIMITER_PATH"]
    host = app + "." + host_delimiter_path + "." + acre_host + ":" + acre_port
    
    url = "http://" + host + "/acre/test?mode=discover&output=json"
    f = urllib2.urlopen(url)
    results = simplejson.loads(f.read())
    
    total_failures = 0
    total_tests = 0
    
    for t in results['testfiles']:
        test_url = t['run_url']
        test_results = drive_test(test_url)
        tests = test_results['total']
        failures = test_results['failures']
        total_tests += tests
        total_failures += failures
        test_name = test_url.split("test_")[1] + " "
        out.write(test_name.ljust(40,'.'))
        if color:
            if failures == 0:
                out.write(colors.OK)
            else:
                out.write(colors.FAIL)
        out.write(" %i/%i" % (failures, tests))
        if color:
            out.write(colors.RESET)
        out.write("\n")
        
    ret = 0
    out.write("\n")
    out.write("Total: ")
    if color:
        if total_failures == 0:
            out.write(colors.OK)
        else: 
            ret = 1
            out.write(colors.FAIL)
    out.write("%i/%i" % (total_failures, total_tests))
    if color:
        out.write(colors.RESET)
    out.write("\n")
    if total_tests == 0:
        out.write("no tests were found or run\n")
        ret = 1
    return ret
        
#-----------------------------------------------------------------------# 

def usage(msg=''):

    if msg:
        print >> sys.stderr, msg
        print >> sys.stderr
    print >> sys.stderr, __usage__ % globals()

def main():

    LOG_LEVEL = logging.ERROR
    color = True
    
    try:
        opts, args = getopt.getopt(sys.argv[1:], "hnl:", ["help", "no-color", "log="])
    except getopt.GetoptError, msg:
        usage(msg)
        sys.exit(1)
        
    if not len(args) == 1:
        usage()
        sys.exit(1)
    else:
        app = args[0]
        
    for o, a in opts:
        if o in ("-h", "--help"):
            usage()
            sys.exit()
        if o in ("-n", "--no-color"):
            color = False
        if o in ("-l", "--log"):
            LOG_LEVEL = eval('logging.' + a)

    logger.setLevel(LOG_LEVEL)
    sys.exit(drive_app(app,color))
    
#-----------------------------------------------------------------------# 

if __name__ == "__main__":
    main()
                
#---------------------------- End of File ------------------------------#

{'fraction_non_alphanumeric': 0.19758119309688815, 'fraction_numerical': 0.009240385922000272, 'mean_word_length': 1.5458318920788654, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 15, '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': '5959168', 'n_tokens_mistral': 2293, 'n_tokens_neox': 2231, 'n_words': 558}