<commit_before># coding: utf-8
# Copyright (c) 2012 <NAME>
# Distributed under the MIT license


from __future__ import unicode_literals
import optparse
import sys

from django.conf import settings as django_settings


#: Shortcut for --db-engine options.
DB_ENGINES = {
    'sqlite': 'django.db.backends.sqlite3',
    'psql': 'django.db.backends.postgresql_psycopg2',
    'mysql': 'django.db.backends.mysql',
    'oracle': 'django.db.backends.oracle',
    'postgis': 'django.contrib.gis.db.backends.postgis',
}


class RunTests(object):
    """Handle running the tests and parsing command line arguments.

    Class attributes:
        TESTED_APPS (str list): names of Django apps to test
        EXTRA_APPS (str list): names of other Django apps that need testing
        EXTRA_SETTINGS (dict): additional settings to use beyond those generated
            in make_settings
        URLCONF (str): name of the base urlconf module, if needed
        DEFAULT_DB_* (str): defaults for the DATABASE['default'] setting

    Attributes:
        app_names (str list): short name of the apps to test
    """
    EXTRA_APPS = ()
    EXTRA_SETTINGS = {}
    TESTED_APPS = ()
    URLCONF = ''

    DEFAULT_DB_ENGINE = 'sqlite'
    DEFAULT_DB_NAME = 'db.sqlite'
    DEFAULT_DB_USER = ''
    DEFAULT_DB_PASSWORD = ''
    DEFAULT_DB_HOST = ''
    DEFAULT_DB_PORT = ''

    def __init__(self):
        self.app_names = [app.split('.')[-1] for app in self.TESTED_APPS]

    def get_usage(self):
        """Prepare the usage string"""
        usage = """%prog [options] app1 app2 ...

Run tests for the selected Python apps (if empty, run tests for all apps)

Valid apps: """ + ', '.join(sorted(self.app_names))

    def make_db_options(self, parser):
        """Prepare all db-related options."""
        db_options = optparse.OptionGroup(parser, "Database options")

        db_options.add_option('--db-engine', dest='db_engine',
            help="Use DBENGINE database engine. Valid options are %s or other "
            "relevant values for the 'ENGINE' setting" % ', '.join(DB_ENGINES),
            metavar=DBENGINE)
        db_options.add_option('--db-name', dest='db_name',
            help='Connect to DBNAME database', metavar=DBNAME)
        db_options.add_option('--db-user', dest='db_user',
            help='Connect to database using DBUSER role', metavar=DBUSER)
        db_options.add_option('--db-password', dest='db_password',
            help='Connect to database with DBPASSWORD', metavar=DBPASSWORD)
        db_options.add_option('--db-host', dest='db_host',
            help='Connect to database at DBHOST', metavar=DBHOST)
        db_options.add_option('--db-port', dest='db_port',
            help='Connect to database port DBPORT', metavar=DBPORT)
        return db_options

    def make_output_options(self, parser):
        """Prepare all output-related options."""
        output_options = optparse.OptionGroup(parser, "Output options")

        output_options.add_option('-v', '--verbose', action='store_true',
            dest='verbose', help='Increase test verbosity')
        output_options.add_option('-q', '--quiet', action='store_true',
            dest='quiet', help='Decrease test verbosity')
        output_options.add_option('--report-format', dest='report_format',
            help="Generate reports in FORMAT format", metavar='FORMAT')
        output_options.add_option('--report-destination', dest='report_dest',
            help="Store reports in DEST folder/file", metavar='DEST')

        return output_options

    def prepare_parser(self):
        """Prepare the option parser."""
        usage = self.get_usage()
        parser = optparse.OptionParser(usage=usage)
        parser.add_option('-v', '--verbose', action='store_true', dest='verbosity', help='Increase test verbosity')

        parser.add_option_group(self.make_db_options(parser))
        parser.add_option_group(self.make_output_options(parser))


    def enhance_parser(self, parser):
        """Extension point for adding custom options and groups to the option parser."""
        pass

    def check_options(self, parser, options, apps):
        """Check all options.

        Args:
            parser (optparse.OptionParser): the parser used to parse the command line
            options (optparse.Options): the parsed options
            apps (str list): the provided application names

        The main use of `parser` is for `parser.error()` calls
        """
        for app in apps:
            if app not in self.app_names:
                parser.error("Invalid application %s" % app)

    def parse_options(self, argv):
        """Handle all command line arguments.

        Args:
            argv (str list): the list of command line arguments
<commit_msg>Fix options<commit_after># coding: utf-8
# Copyright (c) 2012 <NAME>
# Distributed under the MIT license


from __future__ import unicode_literals
import optparse
import sys

from django.conf import settings as django_settings


#: Shortcut for --db-engine options.
DB_ENGINES = {
    'sqlite': 'django.db.backends.sqlite3',
    'psql': 'django.db.backends.postgresql_psycopg2',
    'mysql': 'django.db.backends.mysql',
    'oracle': 'django.db.backends.oracle',
    'postgis': 'django.contrib.gis.db.backends.postgis',
}


class RunTests(object):
    """Handle running the tests and parsing command line arguments.

    Class attributes:
        TESTED_APPS (str list): names of Django apps to test
        EXTRA_APPS (str list): names of other Django apps that need testing
        EXTRA_SETTINGS (dict): additional settings to use beyond those generated
            in make_settings
        URLCONF (str): name of the base urlconf module, if needed
        DEFAULT_DB_* (str): defaults for the DATABASE['default'] setting

    Attributes:
        app_names (str list): short name of the apps to test
    """
    EXTRA_APPS = ()
    EXTRA_SETTINGS = {}
    TESTED_APPS = ()
    URLCONF = ''

    DEFAULT_DB_ENGINE = 'sqlite'
    DEFAULT_DB_NAME = 'db.sqlite'
    DEFAULT_DB_USER = ''
    DEFAULT_DB_PASSWORD = ''
    DEFAULT_DB_HOST = ''
    DEFAULT_DB_PORT = ''

    def __init__(self):
        self.app_names = [app.split('.')[-1] for app in self.TESTED_APPS]

    def get_usage(self):
        """Prepare the usage string"""
        usage = """%prog [options] app1 app2 ...

Run tests for the selected Python apps (if empty, run tests for all apps)

Valid apps: """ + ', '.join(sorted(self.app_names))

    def make_db_options(self, parser):
        """Prepare all db-related options."""
        db_options = optparse.OptionGroup(parser, "Database options")

        db_options.add_option('--db-engine', dest='db_engine',
            help="Use DBENGINE database engine. Valid options are %s or other "
            "relevant values for the 'ENGINE' setting" % ', '.join(DB_ENGINES),
            metavar='DBENGINE')
        db_options.add_option('--db-name', dest='db_name',
            help='Connect to DBNAME database', metavar='DBNAME')
        db_options.add_option('--db-user', dest='db_user',
            help='Connect to database using DBUSER role', metavar='DBUSER')
        db_options.add_option('--db-password', dest='db_password',
            help='Connect to database with DBPASSWORD', metavar='DBPASSWORD')
        db_options.add_option('--db-host', dest='db_host',
            help='Connect to database at DBHOST', metavar='DBHOST')
        db_options.add_option('--db-port', dest='db_port',
            help='Connect to database port DBPORT', metavar='DBPORT')
        return db_options

    def make_output_options(self, parser):
        """Prepare all output-related options."""
        output_options = optparse.OptionGroup(parser, "Output options")

        output_options.add_option('-v', '--verbose', action='store_true',
            dest='verbose', help='Increase test verbosity')
        output_options.add_option('-q', '--quiet', action='store_true',
            dest='quiet', help='Decrease test verbosity')
        output_options.add_option('--report-format', dest='report_format',
            help="Generate reports in FORMAT format", metavar='FORMAT')
        output_options.add_option('--report-destination', dest='report_dest',
            help="Store reports in DEST folder/file", metavar='DEST')

        return output_options

    def prepare_parser(self):
        """Prepare the option parser."""
        usage = self.get_usage()
        parser = optparse.OptionParser(usage=usage)

        parser.add_option_group(self.make_db_options(parser))
        parser.add_option_group(self.make_output_options(parser))


    def enhance_parser(self, parser):
        """Extension point for adding custom options and groups to the option parser."""
        pass

    def check_options(self, parser, options, apps):
        """Check all options.

        Args:
            parser (optparse.OptionParser): the parser used to parse the command line
            options (optparse.Options): the parsed options
            apps (str list): the provided application names

        The main use of `parser` is for `parser.error()` calls
        """
        for app in apps:
            if app not in self.app_names:
                parser.error("Invalid application %s" % app)

    def parse_options(self, argv):
        """Handle all command line arguments.

        Args:
            argv (str list): the list of command line arguments

{'fraction_non_alphanumeric': 0.11645435244161359, 'fraction_numerical': 0.0021231422505307855, 'mean_word_length': 2.9075072583990047, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '1271204', 'n_tokens_mistral': 2769, 'n_tokens_neox': 2687, 'n_words': 760}