Пример #1
0
    def get_level(self, path: str, args: argparse.Namespace) -> Optional[str]:
        """Get level to scan package at."""
        path = os.path.abspath(path)

        profile_filename = "profile.yaml"
        if args.profile is not None:
            profile_filename = args.profile
        profile_resource = self.resources.get_file(profile_filename)
        if profile_resource is None:
            logging.error("Could not find profile file %s!", profile_filename)
            return None
        try:
            profile = Profile(profile_resource)
        except OSError as ex:
            # This isn't quite redundant with the profile_resource check: it's possible
            # that something else triggers an OSError, like permissions.
            logging.error("Failed to access profile file %s: %s",
                          profile_filename, ex)
            return None
        except ValueError as ex:
            logging.error("Profile file %s has errors: %s", profile_filename,
                          ex)
            return None

        package = Package(os.path.basename(path), path)
        level = profile.get_package_level(package)

        return level
Пример #2
0
    def get_level(self, path, args):
        """Get level to scan package at."""
        path = os.path.abspath(path)

        profile_filename = "profile.yaml"
        if args.profile is not None:
            profile_filename = args.profile
        profile_resource = self.resources.get_file(profile_filename)
        if profile_resource is None:
            print("Could not find profile file {}!".format(profile_filename))
            return None
        try:
            profile = Profile(profile_resource)
        except OSError as ex:
            # This isn't quite redundant with the profile_resource check: it's possible
            # that something else triggers an OSError, like permissions
            print("Failed to access profile file {}: {}".format(profile_filename, ex))
            return None
        except ValueError as ex:
            print("Profile file {} has errors: {}".format(profile_filename, ex))
            return None

        package = Package(os.path.basename(path), path)
        level = profile.get_package_level(package)

        return level
Пример #3
0
def test_profile_get_package_level_validpackage():
    """
    Test for when get_package_level is called with a package not in the packages list.

    Expected result: the package-specific value is returned
    """
    package = Package('package', os.path.dirname(__file__))
    profile = Profile(os.path.join(os.path.dirname(__file__), 'profile.yaml'))
    assert profile.get_package_level(package) == "package_specific"
Пример #4
0
def test_profile_get_package_level_invalidpackage():
    """
    Test for when get_package_level is called with a package not in the packages list.

    Expected result: default is returned
    """
    package = Package("nopackage", os.path.dirname(__file__))
    profile = Profile(os.path.join(os.path.dirname(__file__), "profile.yaml"))
    assert profile.get_package_level(package) == "default_value"
Пример #5
0
def test_profile_get_package_level_nopackage():
    """
    Test for when get_package_level is called with no packages defined.

    Expected result: default is returned
    """
    package = Package("test", os.path.dirname(__file__))
    profile = Profile(os.path.join(os.path.dirname(__file__), "profile-nopackage.yaml"))
    assert profile.get_package_level(package) == "default_value"
Пример #6
0
    def get_level(self, path, args):
        """Get level to scan package at."""
        path = os.path.abspath(path)

        profile_filename = "profile.yaml"
        if args.profile is not None:
            profile_filename = args.profile
        try:
            profile = Profile(self.resources.get_file(profile_filename))
        except TypeError:
            print("Could not find profile file {}!".format(profile_filename))
            return None

        package = Package(os.path.basename(path), path)
        level = profile.get_package_level(package)

        return level