mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-01 23:08:43 +01:00
* plots: support images initial * plots: data: unify PlotsData * plots: data conversion refactor * plots: renderers: abstract functionality * plots: uncommenting tests * plots: self implement grouping * plots: rename group * plots: extract rendering tests * plots: move rendering tests to unit * plots: add image rendering tests * plots: dont use dpath to find vega plot * plots: test find_vega * plots: test render function * plots: move rendering out of repo package * plots: refactoring * plots: self review refactor
47 lines
1.1 KiB
Python
47 lines
1.1 KiB
Python
import os
|
|
|
|
import pytest
|
|
|
|
from dvc.render.image import ImageRenderer
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"extension, matches",
|
|
(
|
|
(".csv", False),
|
|
(".json", False),
|
|
(".tsv", False),
|
|
(".yaml", False),
|
|
(".jpg", True),
|
|
(".gif", True),
|
|
(".jpeg", True),
|
|
(".png", True),
|
|
),
|
|
)
|
|
def test_matches(extension, matches):
|
|
filename = "file" + extension
|
|
data = {
|
|
"HEAD": {"data": {filename: {}}},
|
|
"v1": {"data": {filename: {}}},
|
|
}
|
|
assert ImageRenderer.matches(data) == matches
|
|
|
|
|
|
def test_render(tmp_dir):
|
|
data = {"workspace": {"data": {"file.jpg": {"data": b"content"}}}}
|
|
|
|
page_dir = os.path.join("some", "path")
|
|
html = ImageRenderer(data).generate_html(page_dir)
|
|
|
|
assert (tmp_dir / page_dir).is_dir()
|
|
image_file = tmp_dir / page_dir / "static" / "workspace_file.jpg"
|
|
assert image_file.is_file()
|
|
|
|
with open(image_file, "rb") as fobj:
|
|
assert fobj.read() == b"content"
|
|
|
|
assert "<p>file.jpg</p>" in html
|
|
assert (
|
|
f'<img src="{os.path.join("static", "workspace_file.jpg")}">' in html
|
|
)
|