Exemple #1
0
def initialize_coverage(args):
    """
    :type args: CoverageConfig
    :rtype: coverage
    """
    if args.delegate:
        raise Delegate()

    if args.requirements:
        install_command_requirements(args)

    try:
        import coverage
    except ImportError:
        coverage = None

    if not coverage:
        raise ApplicationError('You must install the "coverage" python module to use this command.')

    return coverage
Exemple #2
0
def initialize_coverage(args):
    """
    :type args: CoverageConfig
    :rtype: coverage
    """
    if args.delegate:
        raise Delegate()

    if args.requirements:
        install_command_requirements(args)

    try:
        import coverage
    except ImportError:
        coverage = None

    if not coverage:
        raise ApplicationError('You must install the "coverage" python module to use this command.')

    return coverage
Exemple #3
0
def command_sanity(args):
    """
    :type args: SanityConfig
    """
    changes = get_changes_filter(args)
    require = (args.require or []) + changes
    targets = SanityTargets(args.include, args.exclude, require)

    if not targets.include:
        raise AllTargetsSkipped()

    if args.delegate:
        raise Delegate(require=changes)

    install_command_requirements(args)

    tests = sanity_get_tests()

    if args.test:
        tests = [t for t in tests if t.name in args.test]
    else:
        disabled = [
            t.name for t in tests if not t.enabled and not args.allow_disabled
        ]
        tests = [t for t in tests if t.enabled or args.allow_disabled]

        if disabled:
            display.warning(
                'Skipping tests disabled by default without --allow-disabled: %s'
                % ', '.join(sorted(disabled)))

    if args.skip_test:
        tests = [t for t in tests if t.name not in args.skip_test]

    total = 0
    failed = []

    for test in tests:
        if args.list_tests:
            display.info(test.name)
            continue

        if isinstance(test, SanityMultipleVersion):
            versions = SUPPORTED_PYTHON_VERSIONS
        else:
            versions = (None, )

        for version in versions:
            if args.python and version and version != args.python_version:
                continue

            display.info(
                'Sanity check using %s%s' %
                (test.name, ' with Python %s' % version if version else ''))

            options = ''

            if isinstance(test, SanityCodeSmellTest):
                result = test.test(args, targets)
            elif isinstance(test, SanityMultipleVersion):
                result = test.test(args, targets, python_version=version)
                options = ' --python %s' % version
            elif isinstance(test, SanitySingleVersion):
                result = test.test(args, targets)
            else:
                raise Exception('Unsupported test type: %s' % type(test))

            result.write(args)

            total += 1

            if isinstance(result, SanityFailure):
                failed.append(result.test + options)

    if failed:
        message = 'The %d sanity test(s) listed below (out of %d) failed. See error output above for details.\n%s' % (
            len(failed), total, '\n'.join(failed))

        if args.failure_ok:
            display.error(message)
        else:
            raise ApplicationError(message)
Exemple #4
0
def command_sanity(args):
    """
    :type args: SanityConfig
    """
    changes = get_changes_filter(args)
    require = (args.require or []) + changes
    targets = SanityTargets(args.include, args.exclude, require)

    if not targets.include:
        raise AllTargetsSkipped()

    if args.delegate:
        raise Delegate(require=changes)

    install_command_requirements(args)

    tests = sanity_get_tests()

    if args.test:
        tests = [t for t in tests if t.name in args.test]

    if args.skip_test:
        tests = [t for t in tests if t.name not in args.skip_test]

    total = 0
    failed = []

    for test in tests:
        if args.list_tests:
            display.info(test.name)
            continue

        if test.intercept:
            versions = SUPPORTED_PYTHON_VERSIONS
        else:
            versions = None,

        for version in versions:
            if args.python and version and version != args.python:
                continue

            display.info('Sanity check using %s%s' % (test.name, ' with Python %s' % version if version else ''))

            options = ''

            if test.script:
                result = test.func(args, targets, test.script)
            elif test.intercept:
                result = test.func(args, targets, python_version=version)
                options = ' --python %s' % version
            else:
                result = test.func(args, targets)

            result.write(args)

            total += 1

            if isinstance(result, SanityFailure):
                failed.append(result.test + options)

    if failed:
        message = 'The %d sanity test(s) listed below (out of %d) failed. See error output above for details.\n%s' % (
            len(failed), total, '\n'.join(failed))

        if args.failure_ok:
            display.error(message)
        else:
            raise ApplicationError(message)
Exemple #5
0
def command_sanity(args):
    """
    :type args: SanityConfig
    """
    changes = get_changes_filter(args)
    require = (args.require or []) + changes
    targets = SanityTargets(args.include, args.exclude, require)

    if not targets.include:
        raise AllTargetsSkipped()

    if args.delegate:
        raise Delegate(require=changes)

    install_command_requirements(args)

    tests = sanity_get_tests()

    if args.test:
        tests = [t for t in tests if t.name in args.test]
    else:
        disabled = [t.name for t in tests if not t.enabled and not args.allow_disabled]
        tests = [t for t in tests if t.enabled or args.allow_disabled]

        if disabled:
            display.warning('Skipping tests disabled by default without --allow-disabled: %s' % ', '.join(sorted(disabled)))

    if args.skip_test:
        tests = [t for t in tests if t.name not in args.skip_test]

    total = 0
    failed = []

    for test in tests:
        if args.list_tests:
            display.info(test.name)
            continue

        if isinstance(test, SanityMultipleVersion):
            versions = SUPPORTED_PYTHON_VERSIONS
        else:
            versions = (None,)

        for version in versions:
            if args.python and version and version != args.python_version:
                continue

            display.info('Sanity check using %s%s' % (test.name, ' with Python %s' % version if version else ''))

            options = ''

            if isinstance(test, SanityCodeSmellTest):
                result = test.test(args, targets)
            elif isinstance(test, SanityMultipleVersion):
                result = test.test(args, targets, python_version=version)
                options = ' --python %s' % version
            elif isinstance(test, SanitySingleVersion):
                result = test.test(args, targets)
            else:
                raise Exception('Unsupported test type: %s' % type(test))

            result.write(args)

            total += 1

            if isinstance(result, SanityFailure):
                failed.append(result.test + options)

    if failed:
        message = 'The %d sanity test(s) listed below (out of %d) failed. See error output above for details.\n%s' % (
            len(failed), total, '\n'.join(failed))

        if args.failure_ok:
            display.error(message)
        else:
            raise ApplicationError(message)
Exemple #6
0
def command_sanity(args):
    """
    :type args: SanityConfig
    """
    changes = get_changes_filter(args)
    require = args.require + changes
    targets = SanityTargets.create(args.include, args.exclude, require)

    if not targets.include:
        raise AllTargetsSkipped()

    if args.delegate:
        raise Delegate(require=changes, exclude=args.exclude)

    install_command_requirements(args)

    tests = sanity_get_tests()

    if args.test:
        tests = [target for target in tests if target.name in args.test]
    else:
        disabled = [
            target.name for target in tests
            if not target.enabled and not args.allow_disabled
        ]
        tests = [
            target for target in tests if target.enabled or args.allow_disabled
        ]

        if disabled:
            display.warning(
                'Skipping tests disabled by default without --allow-disabled: %s'
                % ', '.join(sorted(disabled)))

    if args.skip_test:
        tests = [
            target for target in tests if target.name not in args.skip_test
        ]

    total = 0
    failed = []

    for test in tests:
        if args.list_tests:
            display.info(test.name)
            continue

        available_versions = get_available_python_versions(
            SUPPORTED_PYTHON_VERSIONS)

        if args.python:
            # specific version selected
            versions = (args.python, )
        elif isinstance(test, SanityMultipleVersion):
            # try all supported versions for multi-version tests when a specific version has not been selected
            versions = test.supported_python_versions
        elif not test.supported_python_versions or args.python_version in test.supported_python_versions:
            # the test works with any version or the version we're already running
            versions = (args.python_version, )
        else:
            # available versions supported by the test
            versions = tuple(
                sorted(
                    set(available_versions)
                    & set(test.supported_python_versions)))
            # use the lowest available version supported by the test or the current version as a fallback (which will be skipped)
            versions = versions[:1] or (args.python_version, )

        for version in versions:
            if isinstance(test, SanityMultipleVersion):
                skip_version = version
            else:
                skip_version = None

            options = ''

            if test.supported_python_versions and version not in test.supported_python_versions:
                display.warning(
                    "Skipping sanity test '%s' on unsupported Python %s." %
                    (test.name, version))
                result = SanitySkipped(test.name, skip_version)
            elif not args.python and version not in available_versions:
                display.warning(
                    "Skipping sanity test '%s' on Python %s due to missing interpreter."
                    % (test.name, version))
                result = SanitySkipped(test.name, skip_version)
            else:
                check_pyyaml(args, version)

                if test.supported_python_versions:
                    display.info("Running sanity test '%s' with Python %s" %
                                 (test.name, version))
                else:
                    display.info("Running sanity test '%s'" % test.name)

                if isinstance(test, SanityCodeSmellTest):
                    settings = test.load_processor(args)
                elif isinstance(test, SanityMultipleVersion):
                    settings = test.load_processor(args, version)
                elif isinstance(test, SanitySingleVersion):
                    settings = test.load_processor(args)
                elif isinstance(test, SanityVersionNeutral):
                    settings = test.load_processor(args)
                else:
                    raise Exception('Unsupported test type: %s' % type(test))

                if test.all_targets:
                    usable_targets = targets.targets
                elif test.no_targets:
                    usable_targets = tuple()
                else:
                    usable_targets = targets.include

                if test.include_directories:
                    usable_targets += tuple(
                        TestTarget(path, None, None, '')
                        for path in paths_to_dirs(
                            [target.path for target in usable_targets]))

                usable_targets = sorted(
                    test.filter_targets(list(usable_targets)))
                usable_targets = settings.filter_skipped_targets(
                    usable_targets)
                sanity_targets = SanityTargets(targets.targets,
                                               tuple(usable_targets))

                if usable_targets or test.no_targets:
                    if isinstance(test, SanityCodeSmellTest):
                        result = test.test(args, sanity_targets, version)
                    elif isinstance(test, SanityMultipleVersion):
                        result = test.test(args, sanity_targets, version)
                        options = ' --python %s' % version
                    elif isinstance(test, SanitySingleVersion):
                        result = test.test(args, sanity_targets, version)
                    elif isinstance(test, SanityVersionNeutral):
                        result = test.test(args, sanity_targets)
                    else:
                        raise Exception('Unsupported test type: %s' %
                                        type(test))
                else:
                    result = SanitySkipped(test.name, skip_version)

            result.write(args)

            total += 1

            if isinstance(result, SanityFailure):
                failed.append(result.test + options)

    if failed:
        message = 'The %d sanity test(s) listed below (out of %d) failed. See error output above for details.\n%s' % (
            len(failed), total, '\n'.join(failed))

        if args.failure_ok:
            display.error(message)
        else:
            raise ApplicationError(message)