<commit_before>"""
Unit test tasks
"""
import os
import re
import sys
from optparse import make_option

from paver.easy import cmdopts, needs, sh, task

from pavelib.utils.envs import Env
from pavelib.utils.passthrough_opts import PassthroughTask
from pavelib.utils.test import suites
from pavelib.utils.timer import timed

try:
    from pygments.console import colorize
except ImportError:
    colorize = lambda color, text: text

__test__ = False  # do not collect


@needs(
    'pavelib.prereqs.install_prereqs',
    'pavelib.utils.test.utils.clean_reports_dir',
)
@cmdopts([
    ("system=", "s", "System to act on"),
    ("test-id=", "t", "Test id"),
    ("fail-fast", "x", "Fail suite on first failed test"),
    ("fasttest", "a", "Run without collectstatic"),
    make_option(
        "--django_version", dest="django_version",
        help="Run against which Django version (1.8, 1.9, 1.10, -or- 1.11)."
    ),
    make_option(
        "--eval-attr", dest="eval_attr",
        help="Only run tests matching given attribute expression."
    ),
    make_option(
        '-c', '--cov-args', default='',
        help='adds as args to coverage for the test run'
    ),
    ('skip-clean', 'C', 'skip cleaning repository before running tests'),
    make_option('-p', '--processes', dest='processes', default=0, help='number of processes to use running tests'),
    make_option('-r', '--randomize', action='store_true', help='run the tests in a random order'),
    make_option('--no-randomize', action='store_false', dest='randomize', help="don't run the tests in a random order"),
    make_option("--verbose", action="store_const", const=2, dest="verbosity"),
    make_option("-q", "--quiet", action="store_const", const=0, dest="verbosity"),
    make_option("-v", "--verbosity", action="count", dest="verbosity", default=1),
    make_option(
        "--disable_capture", action="store_true", dest="disable_capture",
        help="Disable capturing of stdout/stderr"
    ),
    make_option(
        '--disable-migrations',
        action='store_true',
        dest='disable_migrations',
        help="Create tables directly from apps' models. Can also be used by exporting DISABLE_MIGRATIONS=1."
    ),
    make_option(
        '--enable-migrations',
        action='store_false',
        dest='disable_migrations',
        help="Create tables by applying migrations."
    ),
], share_with=['pavelib.utils.test.utils.clean_reports_dir'])
@PassthroughTask
@timed
def test_system(options, passthrough_options):
    """
    Run tests on our djangoapps for lms and cms
    """
    system = getattr(options, 'system', None)
    test_id = getattr(options, 'test_id', None)
    django_version = getattr(options, 'django_version', None)

    assert(system in (None, 'lms', 'cms'))
    assert(django_version in (None, '1.8', '1.9', '1.10', '1.11'))

    if test_id:
        # Testing a single test ID.
        # Ensure the proper system for the test id.
        if not system:
            system = test_id.split('/')[0]
        if system in ['common', 'openedx']:
            system = 'lms'
        system_tests = [suites.SystemTestSuite(
            system,
            passthrough_options=passthrough_options,
            **options.test_system
        )]
    else:
        # Testing a single system -or- both systems.
        if system:
            systems = [system]
        else:
            # No specified system or test_id, so run all tests of both systems.
            systems = ['cms', 'lms']
        system_tests = []
        for syst in systems:
            system_tests.append(suites.SystemTestSuite(
                syst,
                passthrough_options=passthrough_options,
                **options.test_system
            ))

    test_suite = suites.PythonTestSuite(
        'python tests',
        subsuites=system_tests,
        passthrough_options=passthrough_options,
        **options.test_system
    )
    test_suite.run()


@needs(
    'pavelib.prereqs.install_prereqs',
    'pavelib.utils.test.utils.clean_reports_dir',
)
@cmdopts([
    ("lib=", "l", "lib to test"),
    ("test-id=", "t", "Test id"),
    ("failed", "f", "Run only failed tests"),
    ("fail-fast", "x", "Run only failed tests"),
    make_option(
        "--django_version", dest="django_version",
        help="Run against which Django version (1.8, 1.9, 1.10, -or- 1.11)."
    ),
    make_option(
        '-c', '--cov-args', default='',
        help='adds as args to coverage for the test run'
    ),
    ('skip-clean', 'C', 'skip cleaning repository before running tests'),
    make_option("--verbose", action="store_const", const=2, dest="verbosity"),
    make_option("-q", "--quiet", action="store_const", const=0, dest="verbosity"),
    make_option("-v", "--verbosity", action="count", dest="verbosity", default=1),
    make_option(
        "--disable_capture", action="store_true", dest="disable_capture",
        help="Disable capturing of stdout/stderr"
    ),
], share_with=['pavelib.utils.test.utils.clean_reports_dir'])
@PassthroughTask
@timed
def test_lib(options, passthrough_options):
    """
    Run tests for common/lib/ and pavelib/ (paver-tests)
    """
    lib = getattr(options, 'lib', None)
    test_id = getattr(options, 'test_id', lib)
    django_version = getattr(options, 'django_version', None)

    assert(django_version in (None, '1.8', '1.9', '1.10', '1.11'))<commit_msg>paver flag to run unittests without coverage<commit_after>"""
Unit test tasks
"""
import os
import re
import sys
from optparse import make_option

from paver.easy import cmdopts, needs, sh, task

from pavelib.utils.envs import Env
from pavelib.utils.passthrough_opts import PassthroughTask
from pavelib.utils.test import suites
from pavelib.utils.timer import timed

try:
    from pygments.console import colorize
except ImportError:
    colorize = lambda color, text: text

__test__ = False  # do not collect


@needs(
    'pavelib.prereqs.install_prereqs',
    'pavelib.utils.test.utils.clean_reports_dir',
)
@cmdopts([
    ("system=", "s", "System to act on"),
    ("test-id=", "t", "Test id"),
    ("fail-fast", "x", "Fail suite on first failed test"),
    ("fasttest", "a", "Run without collectstatic"),
    make_option(
        "--django_version", dest="django_version",
        help="Run against which Django version (1.8, 1.9, 1.10, -or- 1.11)."
    ),
    make_option(
        "--eval-attr", dest="eval_attr",
        help="Only run tests matching given attribute expression."
    ),
    make_option(
        '-c', '--cov-args', default='',
        help='adds as args to coverage for the test run'
    ),
    ('skip-clean', 'C', 'skip cleaning repository before running tests'),
    make_option('-p', '--processes', dest='processes', default=0, help='number of processes to use running tests'),
    make_option('-r', '--randomize', action='store_true', help='run the tests in a random order'),
    make_option('--no-randomize', action='store_false', dest='randomize', help="don't run the tests in a random order"),
    make_option("--verbose", action="store_const", const=2, dest="verbosity"),
    make_option("-q", "--quiet", action="store_const", const=0, dest="verbosity"),
    make_option("-v", "--verbosity", action="count", dest="verbosity", default=1),
    make_option(
        "--disable_capture", action="store_true", dest="disable_capture",
        help="Disable capturing of stdout/stderr"
    ),
    make_option(
        "--disable-coverage", action="store_false", dest="with_coverage",
        help="Run the unit tests directly through pytest, NOT coverage"
    ),
    make_option(
        '--disable-migrations',
        action='store_true',
        dest='disable_migrations',
        help="Create tables directly from apps' models. Can also be used by exporting DISABLE_MIGRATIONS=1."
    ),
    make_option(
        '--enable-migrations',
        action='store_false',
        dest='disable_migrations',
        help="Create tables by applying migrations."
    ),
], share_with=['pavelib.utils.test.utils.clean_reports_dir'])
@PassthroughTask
@timed
def test_system(options, passthrough_options):
    """
    Run tests on our djangoapps for lms and cms
    """
    system = getattr(options, 'system', None)
    test_id = getattr(options, 'test_id', None)
    django_version = getattr(options, 'django_version', None)

    assert(system in (None, 'lms', 'cms'))
    assert(django_version in (None, '1.8', '1.9', '1.10', '1.11'))

    if test_id:
        # Testing a single test ID.
        # Ensure the proper system for the test id.
        if not system:
            system = test_id.split('/')[0]
        if system in ['common', 'openedx']:
            system = 'lms'
        system_tests = [suites.SystemTestSuite(
            system,
            passthrough_options=passthrough_options,
            **options.test_system
        )]
    else:
        # Testing a single system -or- both systems.
        if system:
            systems = [system]
        else:
            # No specified system or test_id, so run all tests of both systems.
            systems = ['cms', 'lms']
        system_tests = []
        for syst in systems:
            system_tests.append(suites.SystemTestSuite(
                syst,
                passthrough_options=passthrough_options,
                **options.test_system
            ))

    test_suite = suites.PythonTestSuite(
        'python tests',
        subsuites=system_tests,
        passthrough_options=passthrough_options,
        **options.test_system
    )
    test_suite.run()


@needs(
    'pavelib.prereqs.install_prereqs',
    'pavelib.utils.test.utils.clean_reports_dir',
)
@cmdopts([
    ("lib=", "l", "lib to test"),
    ("test-id=", "t", "Test id"),
    ("failed", "f", "Run only failed tests"),
    ("fail-fast", "x", "Run only failed tests"),
    make_option(
        "--django_version", dest="django_version",
        help="Run against which Django version (1.8, 1.9, 1.10, -or- 1.11)."
    ),
    make_option(
        '-c', '--cov-args', default='',
        help='adds as args to coverage for the test run'
    ),
    ('skip-clean', 'C', 'skip cleaning repository before running tests'),
    make_option("--verbose", action="store_const", const=2, dest="verbosity"),
    make_option("-q", "--quiet", action="store_const", const=0, dest="verbosity"),
    make_option("-v", "--verbosity", action="count", dest="verbosity", default=1),
    make_option(
        "--disable_capture", action="store_true", dest="disable_capture",
        help="Disable capturing of stdout/stderr"
    ),
    make_option(
        "--disable-coverage", action="store_false", dest="with_coverage",
        help="Run the unit tests directly through pytest, NOT coverage"
    ),
], share_with=['pavelib.utils.test.utils.clean_reports_dir'])
@PassthroughTask
@timed
def test_lib(options, passthrough_options):
    """
    Run tests for common/lib/ and pavelib/ (paver-tests)
    """
    lib = getattr(options, 'lib', None)
    test_id = getattr(options, 'test_id', lib)
    django_version = getattr(options, 'django_version', None)

    assert(django_version in (None, '1.8', '1.9', '1.10', '1.11'))
{'fraction_non_alphanumeric': 0.147024504084014, 'fraction_numerical': 0.008796337851180325, 'mean_word_length': 3.029656419529837, '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': '7173102', 'n_tokens_mistral': 3546, 'n_tokens_neox': 3465, 'n_words': 899}