Skip to content

Commit

Permalink
add --save-artifacts arg (#70)
Browse files Browse the repository at this point in the history
  • Loading branch information
tsv1 authored Jan 7, 2024
1 parent cb5ab3f commit 0ec2599
Show file tree
Hide file tree
Showing 15 changed files with 472 additions and 55 deletions.
2 changes: 1 addition & 1 deletion tests/core/exp/local_storage/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ class CustomPluginConfig(PluginConfig):

@pytest.fixture()
def local_storage(plugin: Plugin, tmp_path: Path):
return LocalStorage(plugin, tmp_path)
return LocalStorage(plugin, project_dir=tmp_path)
8 changes: 4 additions & 4 deletions tests/core/exp/local_storage/test_local_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ async def test_get_without_flush(plugin: Plugin, tmp_path: Path):
with given:
key, value = "<key>", "<value>"

local_storage1 = LocalStorage(plugin, tmp_path)
local_storage1 = LocalStorage(plugin, project_dir=tmp_path)
await local_storage1.put(key, value)

local_storage2 = LocalStorage(plugin, tmp_path)
local_storage2 = LocalStorage(plugin, project_dir=tmp_path)

with when:
res = await local_storage2.get(key)
Expand All @@ -66,11 +66,11 @@ async def test_get_with_flush(plugin: Plugin, tmp_path: Path):
with given:
key, value = "<key>", "<value>"

local_storage1 = LocalStorage(plugin, tmp_path)
local_storage1 = LocalStorage(plugin, project_dir=tmp_path)
await local_storage1.put(key, value)
await local_storage1.flush()

local_storage2 = LocalStorage(plugin, tmp_path)
local_storage2 = LocalStorage(plugin, project_dir=tmp_path)

with when:
res = await local_storage2.get(key)
Expand Down
6 changes: 4 additions & 2 deletions tests/core/test_artifacts.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ def test_memory_artifact_binary_only():
MemoryArtifact("log", "text/plain", "text")

with then:
assert exc_info.type is AssertionError
assert exc_info.type is TypeError
assert str(exc_info.value) == "'data' must be of type bytes"


def test_memory_artifact_eq():
Expand Down Expand Up @@ -108,7 +109,8 @@ def test_file_artifact_path_only():
FileArtifact("log", "text/plain", "./log.txt")

with then:
assert exc_info.type is AssertionError
assert exc_info.type is TypeError
assert str(exc_info.value) == "'path' must be an instance of pathlib.Path"


def test_file_artifact_eq():
Expand Down
45 changes: 38 additions & 7 deletions tests/plugins/artifacted/_utils.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
from argparse import ArgumentParser, Namespace
from collections import deque
from pathlib import Path
from time import monotonic_ns
from typing import Optional

import pytest

from vedro import Scenario
from vedro import Config as _Config
from vedro import FileArtifact
from vedro import Scenario as VedroScenario
from vedro.core import Dispatcher, VirtualScenario, VirtualStep
from vedro.events import ArgParsedEvent, ArgParseEvent, ConfigLoadedEvent
from vedro.plugins.artifacted import Artifacted, ArtifactedPlugin, MemoryArtifact


Expand All @@ -24,6 +29,11 @@ def step_artifacts() -> deque:
return deque()


@pytest.fixture()
def project_dir(tmp_path: Path) -> Path:
return tmp_path


@pytest.fixture()
def artifacted(dispatcher: Dispatcher, scenario_artifacts: deque,
step_artifacts: deque) -> ArtifactedPlugin:
Expand All @@ -34,16 +44,37 @@ def artifacted(dispatcher: Dispatcher, scenario_artifacts: deque,
return artifacted


def make_vscenario() -> VirtualScenario:
class _Scenario(Scenario):
__file__ = Path(f"scenario_{monotonic_ns()}.py").absolute()
def make_vscenario(file_path: str = "scenarios/scenario.py") -> VirtualScenario:
class Scenario(VedroScenario):
__file__ = Path(file_path).absolute()

return VirtualScenario(_Scenario, steps=[])
return VirtualScenario(Scenario, steps=[])


def make_vstep() -> VirtualStep:
return VirtualStep(lambda: None)


def create_artifact() -> MemoryArtifact:
return MemoryArtifact(f"test-{monotonic_ns()}", "text/plain", b"")
def create_memory_artifact(content: str = "text") -> MemoryArtifact:
return MemoryArtifact(f"test-{monotonic_ns()}.txt", "text/plain", content.encode())


def create_file_artifact(path: Path, content: str = "text") -> FileArtifact:
path.write_text(content)
return FileArtifact(f"test-{monotonic_ns()}.txt", "text/plain", path)


async def fire_config_loaded_event(dispatcher: Dispatcher, project_dir_: Path) -> None:
class Config(_Config):
project_dir = project_dir_

await dispatcher.fire(ConfigLoadedEvent(Path(), Config))


async def fire_arg_parsed_event(dispatcher: Dispatcher, *,
save_artifacts: bool = False,
artifacts_dir: Optional[Path] = None) -> None:
await dispatcher.fire(ArgParseEvent(ArgumentParser()))

namespace = Namespace(save_artifacts=save_artifacts, artifacts_dir=artifacts_dir)
await dispatcher.fire(ArgParsedEvent(namespace))
Loading

0 comments on commit 0ec2599

Please sign in to comment.