From 69beabc7e82480d4b5fe45a9a5dd2dbf27543ef1 Mon Sep 17 00:00:00 2001 From: David de la Iglesia Castro Date: Mon, 8 Nov 2021 15:01:46 +0100 Subject: [PATCH] Fixed step formatting --- dvclive/data/image_pil.py | 2 +- tests/test_data/test_image.py | 19 ++++++++----------- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/dvclive/data/image_pil.py b/dvclive/data/image_pil.py index 81ba6131..3f6d4d93 100644 --- a/dvclive/data/image_pil.py +++ b/dvclive/data/image_pil.py @@ -19,7 +19,7 @@ def output_path(self) -> Path: f"Invalid image suffix '{Path(self.name).suffix}'" f" Must be one of {self.suffixes}" ) - return self.output_folder / self.name + return self.output_folder / "{step}" / self.name def dump(self, val, step) -> None: super().dump(val, step) diff --git a/tests/test_data/test_image.py b/tests/test_data/test_image.py index 46222546..5e7a8792 100644 --- a/tests/test_data/test_image.py +++ b/tests/test_data/test_image.py @@ -14,10 +14,10 @@ def test_PIL(tmp_dir): img = Image.new("RGB", (500, 500), (250, 250, 250)) dvclive.log("image.png", img) - assert (tmp_dir / dvclive.dir / "image.png").exists() + assert (tmp_dir / dvclive.dir / "0" / "image.png").exists() summary = _parse_json("dvclive.json") - assert summary["image.png"] == os.path.join(dvclive.dir, "image.png") + assert summary["image.png"] == os.path.join(dvclive.dir, "0", "image.png") def test_invalid_extension(tmp_dir): @@ -33,24 +33,21 @@ def test_numpy(tmp_dir, shape): img = np.ones(shape, np.uint8) * 255 dvclive.log("image.png", img) - assert (tmp_dir / dvclive.dir / "image.png").exists() + assert (tmp_dir / dvclive.dir / "0" / "image.png").exists() -@pytest.mark.parametrize( - "pattern", ["image_{step}.png", str(os.path.join("{step}", "image.png"))] -) -def test_step_formatting(tmp_dir, pattern): +def test_step_formatting(tmp_dir): dvclive = Live() img = np.ones((500, 500, 3), np.uint8) for _ in range(3): - dvclive.log(pattern, img) + dvclive.log("image.png", img) dvclive.next_step() for step in range(3): - assert (tmp_dir / dvclive.dir / pattern.format(step=step)).exists() + assert (tmp_dir / dvclive.dir / str(step) / "image.png").exists() summary = _parse_json("dvclive.json") - assert summary[pattern] == os.path.join( - dvclive.dir, pattern.format(step=step) + assert summary["image.png"] == os.path.join( + dvclive.dir, str(step), "image.png" )