<commit_before>import syslog, sys, argparse

""" This file runs the method accessed from the /tests/interactions endpoint.

It's a hack to get around the fact we use the Flask webserver in local testing;
this webserver can only handle one request at a time. If it's serving the test
request, it can't also server the API requests that the test method makes."""

class StdOut(object):
    """ subclass stdout to send everything to the logger
    """
    def write(self, string):
        syslog.syslog(string)

# syslog will push to local3, which is formatted to push stuff to papertrail
syslog.openlog(facility=syslog.LOG_LOCAL3)
#sys.stdout = StdOut()

# we have to do the import down here, so that totalimpact logging will use our new stdout
from totalimpact import views

# get args from the command line:
parser = argparse.ArgumentParser(description="Run interaction tests from the command line")
parser.add_argument("action_type", type=str, help="The action to test; available actions listed in fakes.py")
args = vars(parser.parse_args())
print args["action_type"]
syslog.syslog( "run_interaction_tests.py starting.")



#report = views.tests_interactions("make_collection", web=False)
#print "run_interaction_tests.py finished. Report: " + str(report)<commit_msg>Command line create_collection test works.<commit_after>import syslog, sys, argparse

""" This file runs the method accessed from the /tests/interactions endpoint.

It's a hack to get around the fact we use the Flask webserver in local testing;
this webserver can only handle one request at a time. If it's serving the test
request, it can't also server the API requests that the test method makes."""

class StdOut(object):
    """ subclass stdout to send everything to the logger
    """
    def write(self, string):
        syslog.syslog(string)

# syslog will push to local3, which is formatted to push stuff to papertrail
syslog.openlog(facility=syslog.LOG_LOCAL3)

# stdout won't be sent to terminal, but rather to logger.
sys.stdout = StdOut()

# we have to do the import down here, so that totalimpact logging will use our new stdout
from totalimpact import views

# get args from the command line:
parser = argparse.ArgumentParser(description="Run interaction tests from the command line")
parser.add_argument("action_type", type=str, help="The action to test; available actions listed in fakes.py")
args = vars(parser.parse_args())
print "run_interaction_tests.py starting."

report = views.tests_interactions("make_collection", web=False)
print "run_interaction_tests.py finished. Report: " + str(report)
{'fraction_non_alphanumeric': 0.08168795973674023, 'fraction_numerical': 0.001548586914440573, 'mean_word_length': 5.0093023255813955, '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': '7035085', 'n_tokens_mistral': 729, 'n_tokens_neox': 710, 'n_words': 309}