-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
172 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
from pathlib import Path | ||
|
||
from baby_steps import given, then, when | ||
from pytest import raises | ||
|
||
from vedro.core import FileArtifact, MemoryArtifact | ||
|
||
|
||
def test_memory_artifact(): | ||
with given: | ||
name = "log" | ||
mime_type = "text/plain" | ||
data = b"" | ||
|
||
with when: | ||
artifact = MemoryArtifact(name, mime_type, data) | ||
|
||
with then: | ||
assert artifact.name == name | ||
assert artifact.mime_type == mime_type | ||
assert artifact.data == data | ||
|
||
|
||
def test_memory_artifact_repr(): | ||
with given: | ||
name = "log" | ||
mime_type = "text/plain" | ||
data = b"" | ||
|
||
with when: | ||
artifact = MemoryArtifact(name, mime_type, data) | ||
|
||
with then: | ||
assert repr(artifact) == f"MemoryArtifact<{name!r}, {mime_type!r}, size={len(data)}>" | ||
|
||
|
||
def test_memory_artifact_binary_only(): | ||
with raises(Exception) as exc_info: | ||
MemoryArtifact("log", "text/plain", "text") | ||
|
||
with then: | ||
assert exc_info.type is AssertionError | ||
|
||
|
||
def test_file_artifact(): | ||
with given: | ||
name = "log" | ||
mime_type = "text/plain" | ||
path = Path() | ||
|
||
with when: | ||
artifact = FileArtifact(name, mime_type, path) | ||
|
||
with then: | ||
assert artifact.name == name | ||
assert artifact.mime_type == mime_type | ||
assert artifact.path == path | ||
|
||
|
||
def test_file_artifact_repr(): | ||
with given: | ||
name = "log" | ||
mime_type = "text/plain" | ||
path = Path() | ||
|
||
with when: | ||
artifact = FileArtifact(name, mime_type, path) | ||
|
||
with then: | ||
print(repr(artifact)) | ||
assert repr(artifact) == f"FileArtifact<{name!r}, {mime_type!r}, {path!r}>" | ||
|
||
|
||
def test_file_artifact_path_only(): | ||
with raises(Exception) as exc_info: | ||
FileArtifact("log", "text/plain", "./log.txt") | ||
|
||
with then: | ||
assert exc_info.type is AssertionError |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
from abc import ABC | ||
from pathlib import Path | ||
|
||
__all__ = ("Artifact", "MemoryArtifact", "FileArtifact",) | ||
|
||
|
||
class Artifact(ABC): | ||
pass | ||
|
||
|
||
class MemoryArtifact(Artifact): | ||
def __init__(self, name: str, mime_type: str, data: bytes) -> None: | ||
assert isinstance(data, bytes) | ||
self._name = name | ||
self._data = data | ||
self._mime_type = mime_type | ||
|
||
@property | ||
def name(self) -> str: | ||
return self._name | ||
|
||
@property | ||
def mime_type(self) -> str: | ||
return self._mime_type | ||
|
||
@property | ||
def data(self) -> bytes: | ||
return self._data | ||
|
||
def __repr__(self) -> str: | ||
size = len(self._data) | ||
return f"{self.__class__.__name__}<{self._name!r}, {self._mime_type!r}, size={size}>" | ||
|
||
|
||
class FileArtifact(Artifact): | ||
def __init__(self, name: str, mime_type: str, path: Path) -> None: | ||
assert isinstance(path, Path) | ||
self._name = name | ||
self._path = path | ||
self._mime_type = mime_type | ||
|
||
@property | ||
def name(self) -> str: | ||
return self._name | ||
|
||
@property | ||
def mime_type(self) -> str: | ||
return self._mime_type | ||
|
||
@property | ||
def path(self) -> Path: | ||
return self._path | ||
|
||
def __repr__(self) -> str: | ||
return f"{self.__class__.__name__}<{self._name!r}, {self._mime_type!r}, {self._path!r}>" |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters