-
Notifications
You must be signed in to change notification settings - Fork 437
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add file datatype type to support saving and reading files/folders in…
… the artifact store.
- Loading branch information
1 parent
baec125
commit 77ec8c8
Showing
8 changed files
with
180 additions
and
18 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
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
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
Empty file.
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,44 @@ | ||
import dataclasses as dc | ||
import os | ||
import typing as t | ||
from test.db_config import DBConfig | ||
|
||
import pytest | ||
|
||
from superduperdb.backends.local.artifacts import FileSystemArtifactStore | ||
from superduperdb.components.component import Component | ||
from superduperdb.components.datatype import ( | ||
DataType, | ||
file_serializer, | ||
serializers, | ||
) | ||
|
||
|
||
@dc.dataclass(kw_only=True) | ||
class TestComponent(Component): | ||
path: str | ||
type_id: t.ClassVar[str] = "TestComponent" | ||
|
||
_artifacts: t.ClassVar[t.Sequence[t.Tuple[str, "DataType"]]] = ( | ||
("path", file_serializer), | ||
) | ||
|
||
|
||
@pytest.fixture | ||
def artifact_strore(tmpdir) -> FileSystemArtifactStore: | ||
tmpdir = "uttest" | ||
artifact_strore = FileSystemArtifactStore(f"{tmpdir}") | ||
artifact_strore._serializers = serializers | ||
return artifact_strore | ||
|
||
|
||
@pytest.mark.parametrize("db", [DBConfig.mongodb_empty], indirect=True) | ||
def test_save_and_load_file(db, artifact_strore: FileSystemArtifactStore): | ||
db.artifact_store = artifact_strore | ||
test_component = TestComponent(path="superduperdb", identifier="test") | ||
db.add(test_component) | ||
test_component_loaded = db.load("TestComponent", "test") | ||
assert test_component.path != test_component_loaded.path | ||
assert os.path.getsize(test_component.path) == os.path.getsize( | ||
test_component_loaded.path | ||
) |