def main():
    """Run the tests."""
    parsed_args = _PARSER.parse_args()
    if parsed_args.test_target and parsed_args.test_path:
        raise Exception('At most one of test_path and test_target '
                        'should be specified.')
    if parsed_args.test_path and '.' in parsed_args.test_path:
        raise Exception('The delimiter in test_path should be a slash (/)')
    if parsed_args.test_target and '/' in parsed_args.test_target:
        raise Exception('The delimiter in test_target should be a dot (.)')

    if parsed_args.test_target:
        all_test_targets = [parsed_args.test_target]
    else:
        all_test_targets = _get_all_test_targets(
            test_path=parsed_args.test_path)

    # Prepare tasks.
    task_to_taskspec = {}
    tasks = []
    for test_target in all_test_targets:
        test = TestingTaskSpec(
            test_target, parsed_args.generate_coverage_report)
        task = TaskThread(test.run, name=test_target)
        task_to_taskspec[task] = test
        tasks.append(task)

    task_execution_failed = False
    try:
        _execute_tasks(tasks)
    except Exception:
        task_execution_failed = True

    for task in tasks:
        if task.exception:
            log(str(task.exception))

    print ''
    print '+------------------+'
    print '| SUMMARY OF TESTS |'
    print '+------------------+'
    print ''

    # Check we ran all tests as expected.
    total_count = 0
    total_errors = 0
    total_failures = 0
    for task in tasks:
        spec = task_to_taskspec[task]

        if not task.finished:
            print 'CANCELED  %s' % spec.test_target
            test_count = 0
        elif 'No tests were run' in str(task.exception):
            print 'ERROR     %s: No tests found.' % spec.test_target
            test_count = 0
        elif task.exception:
            exc_str = str(task.exception).decode('utf-8')
            print exc_str[exc_str.find('=') : exc_str.rfind('-')]

            tests_failed_regex_match = re.search(
                r'Test suite failed: ([0-9]+) tests run, ([0-9]+) errors, '
                '([0-9]+) failures',
                str(task.exception))

            try:
                test_count = int(tests_failed_regex_match.group(1))
                errors = int(tests_failed_regex_match.group(2))
                failures = int(tests_failed_regex_match.group(3))
                total_errors += errors
                total_failures += failures
                print 'FAILED    %s: %s errors, %s failures' % (
                    spec.test_target, errors, failures)
            except __HOLE__:
                # There was an internal error, and the tests did not run. (The
                # error message did not match `tests_failed_regex_match`.)
                test_count = 0
                print ''
                print '------------------------------------------------------'
                print '    WARNING: FAILED TO RUN TESTS.'
                print ''
                print '    This is most likely due to an import error.'
                print '------------------------------------------------------'
        else:
            try:
                tests_run_regex_match = re.search(
                    r'Ran ([0-9]+) tests? in ([0-9\.]+)s', task.output)
                test_count = int(tests_run_regex_match.group(1))
                test_time = float(tests_run_regex_match.group(2))
                print ('SUCCESS   %s: %d tests (%.1f secs)' %
                       (spec.test_target, test_count, test_time))
            except Exception:
                print (
                    'An unexpected error occurred. '
                    'Task output:\n%s' % task.output)

        total_count += test_count

    print ''
    if total_count == 0:
        raise Exception('WARNING: No tests were run.')
    else:
        print 'Ran %s test%s in %s test class%s.' % (
            total_count, '' if total_count == 1 else 's',
            len(tasks), '' if len(tasks) == 1 else 'es')

        if total_errors or total_failures:
            print '(%s ERRORS, %s FAILURES)' % (total_errors, total_failures)
        else:
            print 'All tests passed.'

    if task_execution_failed:
        raise Exception('Task execution failed.')
    elif total_errors or total_failures:
        raise Exception(
            '%s errors, %s failures' % (total_errors, total_failures))
dataset/ETHPy150Open oppia/oppia/scripts/backend_tests.py/main