Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

render: image_converter: Support slash in revision. #7937

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion dvc/render/image_converter.py
Expand Up @@ -20,7 +20,8 @@ def _write_image(
image_data: bytes,
) -> "StrPath":
img_path = os.path.join(
path, f"{revision}_{filename.replace(os.sep, '_')}"
path,
f"{revision}_{filename}".replace(os.sep, "_").replace("/", "_"),
)
with open(img_path, "wb") as fd:
fd.write(image_data)
Expand Down
16 changes: 16 additions & 0 deletions tests/unit/render/test_image_converter.py
Expand Up @@ -28,3 +28,19 @@ def test_image_converter_with_out(tmp_dir):
}

assert (tmp_dir / "foo" / "r_image.png").read_bytes() == b"content"


def test_image_converter_with_slash_in_revision(tmp_dir):
"""Regression test for #7934"""
data = b"content"
converter = ImageConverter({"out": tmp_dir / "foo"})

datapoints, _ = converter.convert(data, "feature/r", "image.png")

assert datapoints[0] == {
REVISION_FIELD: "feature/r",
"filename": "image.png",
SRC_FIELD: str(tmp_dir / "foo" / "feature_r_image.png"),
}

assert (tmp_dir / "foo" / "feature_r_image.png").read_bytes() == b"content"