-
Notifications
You must be signed in to change notification settings - Fork 443
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add integration test for mongodb saving files and folders
- Loading branch information
1 parent
7677841
commit 34609c5
Showing
2 changed files
with
69 additions
and
0 deletions.
There are no files selected for viewing
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,69 @@ | ||
import dataclasses as dc | ||
import filecmp | ||
import os | ||
import typing as t | ||
|
||
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: | ||
artifact_strore = FileSystemArtifactStore(f"{tmpdir}") | ||
artifact_strore._serializers = serializers | ||
return artifact_strore | ||
|
||
|
||
def test_save_and_load_directory(test_db): | ||
# test save and load directory | ||
directory = os.path.join(os.getcwd(), "superduperdb") | ||
test_component = TestComponent(path=directory, identifier="test") | ||
test_db.add(test_component) | ||
test_component_loaded = test_db.load("TestComponent", "test") | ||
test_component_loaded.init() | ||
# assert that the paths are different | ||
assert test_component.path != test_component_loaded.path | ||
# assert that the directory names are the same | ||
assert ( | ||
os.path.split(test_component.path)[-1] | ||
== os.path.split(test_component_loaded.path)[-1] | ||
) | ||
# assert that the directory sizes are the same | ||
assert os.path.getsize(test_component.path) == os.path.getsize( | ||
test_component_loaded.path | ||
) | ||
|
||
|
||
def test_save_and_load_file(test_db): | ||
# test save and load file | ||
file = os.path.abspath(__file__) | ||
test_component = TestComponent(path=file, identifier="test") | ||
test_db.add(test_component) | ||
test_component_loaded = test_db.load("TestComponent", "test") | ||
test_component_loaded.init() | ||
# assert that the paths are different | ||
assert test_component.path != test_component_loaded.path | ||
# assert that the file names are the same | ||
assert ( | ||
os.path.split(test_component.path)[-1] | ||
== os.path.split(test_component_loaded.path)[-1] | ||
) | ||
# assert that the file sizes are the same | ||
assert filecmp.cmp(test_component.path, test_component_loaded.path) |