diff --git a/src/python/pants/backend/docker/goals/package_image.py b/src/python/pants/backend/docker/goals/package_image.py index efb0cdedf9e..ad04038060f 100644 --- a/src/python/pants/backend/docker/goals/package_image.py +++ b/src/python/pants/backend/docker/goals/package_image.py @@ -77,9 +77,7 @@ def format_tag(self, tag: str, interpolation_context: DockerInterpolationContext source = DockerInterpolationContext.TextSource( address=self.address, target_alias="docker_image", field_alias=self.tags.alias ) - return interpolation_context.format( - tag, source=source, error_cls=DockerImageTagValueError - ).lower() + return interpolation_context.format(tag, source=source, error_cls=DockerImageTagValueError) def format_repository( self, default_repository: str, interpolation_context: DockerInterpolationContext diff --git a/src/python/pants/backend/docker/goals/package_image_test.py b/src/python/pants/backend/docker/goals/package_image_test.py index 3f367a7d0eb..adbb2df4ee8 100644 --- a/src/python/pants/backend/docker/goals/package_image_test.py +++ b/src/python/pants/backend/docker/goals/package_image_test.py @@ -980,3 +980,28 @@ def test_get_context_root( ) def test_parse_image_id_from_docker_build_output(expected: str, stdout: str, stderr: str) -> None: assert expected == parse_image_id_from_docker_build_output(stdout.encode(), stderr.encode()) + + +@pytest.mark.parametrize( + "raw_values, expect_raises, image_refs", + [ + (dict(name="lowercase"), no_exception(), ("lowercase:latest",)), + (dict(name="CamelCase"), no_exception(), ("camelcase:latest",)), + (dict(image_tags=["CamelCase"]), no_exception(), ("image:CamelCase",)), + (dict(registries=["REG1.example.net"]), no_exception(), ("REG1.example.net/image:latest",)), + ], +) +def test_image_ref_formatting( + raw_values: dict, expect_raises: ContextManager, image_refs: tuple[str, ...] +) -> None: + address = Address("test", target_name=raw_values.pop("name", "image")) + tgt = DockerImageTarget(raw_values, address) + field_set = DockerFieldSet.create(tgt) + default_repository = "{name}" + registries = DockerRegistries.from_dict({}) + interpolation_context = DockerInterpolationContext.from_dict({}) + with expect_raises: + assert ( + field_set.image_refs(default_repository, registries, interpolation_context) + == image_refs + ) diff --git a/src/python/pants/testutil/pytest_util.py b/src/python/pants/testutil/pytest_util.py index 1eb96682136..19d599a306f 100644 --- a/src/python/pants/testutil/pytest_util.py +++ b/src/python/pants/testutil/pytest_util.py @@ -31,11 +31,17 @@ def no_exception(): When declaring parametrized tests, the test function can take a exceptions expectation as input, and always use a with-block for the code under test. - @pytest.mark.parametrize('answer, expect_raises', [ - (42, no_exception()), - (12, pytest.raises(WrongAnswer)), - ]) - def test_search_for_the_meaning_of_life_universe_and_everything(answer, expect_raises): + @pytest.mark.parametrize( + "answer, expect_raises", + [ + (42, no_exception()), + (12, pytest.raises(WrongAnswer)), + ] + ) + def test_search_for_the_meaning_of_life_universe_and_everything( + answer: int, + expect_raises: typing.ContextManager, + ): with expect_raises: computer.validate_result(answer) """