<commit_before>#!/usr/bin/env python
# vim: ai ts=4 sts=4 et sw=4

import os
import sys


def run_tests(options, args, ci=False):
    from django.conf import settings
    if ci:
        settings.NOSE_ARGS = [
            '--with-xcoverage',
            '--cover-tests',
            '--cover-package=rapidsms',
        ]
    from django.test.utils import get_runner
    TestRunner = get_runner(settings)
    test_runner = TestRunner(verbosity=int(options.verbosity),
                             interactive=options.interactive,
                             failfast=False)
    if not args:
        args = ['rapidsms']
    failures = test_runner.run_tests(args)
    sys.exit(failures)


def main():
    from optparse import OptionParser
    usage = "%prog [options] [module module module ...]"
    parser = OptionParser(usage=usage)
    parser.add_option('-v', '--verbosity', action='store', dest='verbosity',
                      default=1, type='choice', choices=['0', '1', '2', '3'],
                      help='Verbosity level; 0=minimal output, 1=normal '
                           'output, 2=all output')
    parser.add_option('--noinput', action='store_false', dest='interactive',
                      default=True,
                      help='Tells Django to NOT prompt the user for input of '
                           'any kind.')
    parser.add_option('--settings',
                      help='Python path to settings module, e.g. '
                           '"myproject.settings". If this isn\'t provided, '
                           'the DJANGO_SETTINGS_MODULE environment variable '
                           'will be used.')
    parser.add_option('--ci', action='store_true', dest='ci',
                      default=False,
                      help='Run tests with CI environment')
    options, args = parser.parse_args()
    if options.settings:
        os.environ['DJANGO_SETTINGS_MODULE'] = options.settings
    elif "DJANGO_SETTINGS_MODULE" not in os.environ:
        parser.error("DJANGO_SETTINGS_MODULE is not set in the environment. "
                     "Set it or use --settings.")
    else:
        options.settings = os.environ['DJANGO_SETTINGS_MODULE']
    # I couldn't figure out how to get "CI" in as a command line argument,
    # because nosetests would also interpret the argument.
    ci = os.environ.get('CI', False)
    ci = False
    run_tests(options, ci=ci, args=args)


if __name__ == '__main__':
    main()
<commit_msg>Django 1.7 needs to be explicitly setup in standalone scripts<commit_after>#!/usr/bin/env python
# vim: ai ts=4 sts=4 et sw=4

import os
import sys

import django
from django.conf import settings
from django.test.utils import get_runner


def run_tests(options, args, ci=False):
    if django.VERSION > (1, 7):
        # http://django.readthedocs.org/en/latest/releases/1.7.html#standalone-scripts
        django.setup()

    if ci:
        settings.NOSE_ARGS = [
            '--with-xcoverage',
            '--cover-tests',
            '--cover-package=rapidsms',
        ]

    TestRunner = get_runner(settings)
    test_runner = TestRunner(verbosity=int(options.verbosity),
                             interactive=options.interactive,
                             failfast=False)
    if not args:
        args = ['rapidsms']
    failures = test_runner.run_tests(args)
    sys.exit(failures)


def main():
    from optparse import OptionParser
    usage = "%prog [options] [module module module ...]"
    parser = OptionParser(usage=usage)
    parser.add_option('-v', '--verbosity', action='store', dest='verbosity',
                      default=1, type='choice', choices=['0', '1', '2', '3'],
                      help='Verbosity level; 0=minimal output, 1=normal '
                           'output, 2=all output')
    parser.add_option('--noinput', action='store_false', dest='interactive',
                      default=True,
                      help='Tells Django to NOT prompt the user for input of '
                           'any kind.')
    parser.add_option('--settings',
                      help='Python path to settings module, e.g. '
                           '"myproject.settings". If this isn\'t provided, '
                           'the DJANGO_SETTINGS_MODULE environment variable '
                           'will be used.')
    parser.add_option('--ci', action='store_true', dest='ci',
                      default=False,
                      help='Run tests with CI environment')
    options, args = parser.parse_args()
    if options.settings:
        os.environ['DJANGO_SETTINGS_MODULE'] = options.settings
    elif "DJANGO_SETTINGS_MODULE" not in os.environ:
        parser.error("DJANGO_SETTINGS_MODULE is not set in the environment. "
                     "Set it or use --settings.")
    else:
        options.settings = os.environ['DJANGO_SETTINGS_MODULE']
    # I couldn't figure out how to get "CI" in as a command line argument,
    # because nosetests would also interpret the argument.
    ci = os.environ.get('CI', False)
    ci = False
    run_tests(options, ci=ci, args=args)


if __name__ == '__main__':
    main()

{'fraction_non_alphanumeric': 0.11489776046738072, 'fraction_numerical': 0.005452775073028238, 'mean_word_length': 2.0336680448907267, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4113118', 'n_tokens_mistral': 1487, 'n_tokens_neox': 1448, 'n_words': 377}