コード例 #1
0
    def test_release_with_already_existing_version(self):
        with pytest.raises(SystemExit) as pytest_wrapped_e:
            build_utils.get_sanitized_arguments(
                [
                    f"--{build_utils.FLAG_RELEASE}",
                    f"--{build_utils.FLAG_TEST}",
                    f"--{build_utils.FLAG_MAKE}",
                    f"--{build_utils.FLAG_VERSION}=1.0.0",
                ]
            )

        assert pytest_wrapped_e.type == SystemExit
        assert pytest_wrapped_e.value.code == build_utils.EXIT_CODE_INVALID_VERSION
コード例 #2
0
    def test_release_with_invalid_version_in_main_branch(self):
        with pytest.raises(SystemExit) as pytest_wrapped_e:
            build_utils.get_sanitized_arguments(
                [
                    f"--{build_utils.FLAG_RELEASE}",
                    f"--{build_utils.FLAG_TEST}",
                    f"--{build_utils.FLAG_MAKE}",
                    f"--{build_utils.FLAG_VERSION}=foo",
                ]
            )

        assert pytest_wrapped_e.type == SystemExit
        assert pytest_wrapped_e.value.code == build_utils.EXIT_CODE_INVALID_VERSION
コード例 #3
0
def get_sanitized_arguments(
    arguments: List[str] = None, argument_parser: argparse.ArgumentParser = None
) -> Dict[str, Union[str, bool, List[str]]]:
    """Return sanitized default arguments when they are valid.

    Sanitized means that, for example, the version is already checked and set depending on our build guidelines.
    If arguments are not valid, exit the script run.

    Args:
        arguments (List[str], optional): List of arguments that are used instead of the arguments passed to the process. Defaults to `None`.
        argument_parser (arparse.ArgumentParser, optional): An argument parser which is passed as a parents parser to the default ArgumentParser to be able to use additional flags besides the default ones. Must be initialized with `add_help=False` flag like argparse.ArgumentParser(add_help=False)!

    Returns:
        Dict[str, Union[str, bool, List[str]]]: The parsed default arguments thar are already checked for validity.
    """
    if argument_parser is None:
        argument_parser = argparse.ArgumentParser()

    argument_parser.add_argument(
        "--" + FLAG_PYPI_TOKEN.replace("_", "-"),
        help="Personal access token for PyPI account.",
        required=False,
        default=None,
    )
    argument_parser.add_argument(
        "--" + FLAG_PYPI_REPOSITORY.replace("_", "-"),
        help="PyPI repository for publishing artifacts.",
        required=False,
        default=None,
    )

    return build_utils.get_sanitized_arguments(
        arguments=arguments, argument_parser=argument_parser
    )
コード例 #4
0
    def test_with_too_small_patch(self):
        too_small_patch_version = "1.1.2"
        with pytest.raises(build_utils.VersionInvalidPatchNumber) as pytest_wrapped_e:
            build_utils._get_version(
                version=too_small_patch_version,
                existing_versions=build_utils._get_version_tags(),
            )
        assert pytest_wrapped_e.type is build_utils.VersionInvalidPatchNumber

        with pytest.raises(SystemExit) as pytest_wrapped_e:
            build_utils.get_sanitized_arguments(
                [f"--{build_utils.FLAG_VERSION}={too_small_patch_version}"]
            )

        assert pytest_wrapped_e.type == SystemExit
        assert pytest_wrapped_e.value.code == build_utils.EXIT_CODE_INVALID_VERSION
コード例 #5
0
def get_sanitized_arguments(
    arguments: List[str] = None, argument_parser: argparse.ArgumentParser = None
) -> Dict[str, Union[str, bool, List[str]]]:
    """Return sanitized default arguments when they are valid.

    Sanitized means that, for example, the version is already checked and set depending on our build guidelines.
    If arguments are not valid, exit the script run.

    Args:
        arguments (List[str], optional): List of arguments that are used instead of the arguments passed to the process. Defaults to `None`.
        argument_parser (arparse.ArgumentParser, optional): An argument parser which is passed as a parents parser to the default ArgumentParser to be able to use additional flags besides the default ones. Must be initialized with `add_help=False` flag like argparse.ArgumentParser(add_help=False)!

    Returns:
        Dict[str, Union[str, bool, List[str]]]: The parsed default arguments thar are already checked for validity.
    """
    if argument_parser is None:
        argument_parser = argparse.ArgumentParser()

    argument_parser.add_argument(
        "--" + FLAG_DOCKER_IMAGE_PREFIX.replace("_", "-"),
        help="With this flag you can provide a prefix for a Docker image, e.g. 'mltooling/' or even a repository path. When leaving blank, the default Dockerhub Repository is used.",
        required=False,
        default=None,
    )

    return build_utils.get_sanitized_arguments(
        arguments=arguments, argument_parser=argument_parser
    )
コード例 #6
0
 def test_build_with_force_with_version(self):
     sanitized_args = build_utils.get_sanitized_arguments(
         [
             f"--{build_utils.FLAG_MAKE}",
             f"--{build_utils.FLAG_FORCE}",
             "--version=1.1.0",
         ]
     )
     assert sanitized_args[build_utils.FLAG_VERSION] == "1.1.0"
コード例 #7
0
 def test_release(self):
     sanitized_arguments = build_utils.get_sanitized_arguments(
         [
             f"--{build_utils.FLAG_RELEASE}",
             f"--{build_utils.FLAG_TEST}",
             f"--{build_utils.FLAG_MAKE}",
             f"--{build_utils.FLAG_VERSION}={valid_patch_version}",
         ]
     )
     assert isinstance(sanitized_arguments[build_utils.FLAG_VERSION], str)
     assert sanitized_arguments[build_utils.FLAG_VERSION] == valid_patch_version
コード例 #8
0
    def test_release_without_version(self):
        with pytest.raises(SystemExit) as pytest_wrapped_e:
            build_utils.get_sanitized_arguments([f"--{build_utils.FLAG_RELEASE}"])

        assert pytest_wrapped_e.type == SystemExit
        assert pytest_wrapped_e.value.code == build_utils.EXIT_CODE_INVALID_ARGUMENTS