feat: move fs_datacatalogue to fs_repository
This commit is contained in:
@@ -1,61 +0,0 @@
|
||||
import shutil
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
from plesna.datastore.fs_datacatalogue import FSDataCatalogue
|
||||
from plesna.models.storage import Schema
|
||||
|
||||
FIXTURE_DIR = Path(__file__).parent.parent / Path("./raw_datas/")
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def location(tmp_path):
|
||||
loc = tmp_path
|
||||
username_loc = loc / "username"
|
||||
username_loc.mkdir()
|
||||
salary_loc = loc / "salary"
|
||||
salary_loc.mkdir()
|
||||
example_src = FIXTURE_DIR
|
||||
assert example_src.exists()
|
||||
|
||||
for f in example_src.glob("*"):
|
||||
if "username" in str(f):
|
||||
shutil.copy(f, username_loc)
|
||||
else:
|
||||
shutil.copy(f, salary_loc)
|
||||
|
||||
return loc
|
||||
|
||||
|
||||
def test_init(location):
|
||||
repo = FSDataCatalogue("example", location)
|
||||
assert repo.ls() == [
|
||||
"username",
|
||||
"salary",
|
||||
]
|
||||
|
||||
assert repo.ls(recursive=True) == [
|
||||
"username",
|
||||
"salary",
|
||||
]
|
||||
|
||||
|
||||
def test_list_schema(location):
|
||||
repo = FSDataCatalogue("example", location)
|
||||
|
||||
assert repo.schemas == [".", "username", "salary"]
|
||||
assert repo.schema(".").ref == Schema(id=".", value=".")
|
||||
assert repo.schema("username").ref == Schema(id="username", value="username")
|
||||
|
||||
def test_list_tables_schema(location):
|
||||
repo = FSDataCatalogue("example", location)
|
||||
|
||||
assert repo.schema(".").tables == []
|
||||
assert repo.schema("username").tables == [
|
||||
'username.csv',
|
||||
'username-password-recovery-code.xlsx',
|
||||
'username-password-recovery-code.xls',
|
||||
]
|
||||
assert repo.schema("salary").tables == ["salary.pdf"]
|
||||
|
||||
77
tests/storage/test_fs_repository.py
Normal file
77
tests/storage/test_fs_repository.py
Normal file
@@ -0,0 +1,77 @@
|
||||
import shutil
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
from plesna.models.storage import Schema
|
||||
from plesna.storage.repository.fs_repository import FSRepository
|
||||
|
||||
FIXTURE_DIR = Path(__file__).parent.parent / Path("./raw_datas/")
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def location(tmp_path):
|
||||
loc = tmp_path
|
||||
username_loc = loc / "username"
|
||||
username_loc.mkdir()
|
||||
salary_loc = loc / "salary"
|
||||
salary_loc.mkdir()
|
||||
example_src = FIXTURE_DIR
|
||||
assert example_src.exists()
|
||||
|
||||
for f in example_src.glob("*"):
|
||||
if "username" in str(f):
|
||||
shutil.copy(f, username_loc)
|
||||
else:
|
||||
shutil.copy(f, salary_loc)
|
||||
|
||||
return loc
|
||||
|
||||
|
||||
def test_init(location):
|
||||
repo = FSRepository("example", location, "example")
|
||||
assert repo.ls() == [
|
||||
"username",
|
||||
"salary",
|
||||
]
|
||||
|
||||
assert repo.ls(recursive=True) == [
|
||||
"username",
|
||||
"salary",
|
||||
"username/username.csv",
|
||||
"username/username-password-recovery-code.xlsx",
|
||||
"username/username-password-recovery-code.xls",
|
||||
"salary/salary.pdf",
|
||||
]
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def repository(location) -> FSRepository:
|
||||
return FSRepository("example", location, "example")
|
||||
|
||||
|
||||
def test_list_schema(location, repository):
|
||||
assert repository.schemas() == ["username", "salary"]
|
||||
assert repository.schema("username").name == "username"
|
||||
assert repository.schema("username").id == str(location / "username")
|
||||
assert repository.schema("username").repo_id == str(location)
|
||||
assert repository.schema("username").value == str(location / "username")
|
||||
|
||||
|
||||
def test_list_tables_schema(repository):
|
||||
assert repository.schema("username").tables == [
|
||||
"username.csv",
|
||||
"username-password-recovery-code.xlsx",
|
||||
"username-password-recovery-code.xls",
|
||||
]
|
||||
assert repository.schema("salary").tables == ["salary.pdf"]
|
||||
|
||||
|
||||
def test_describe_table(location, repository):
|
||||
table = repository.table("username", "username.csv")
|
||||
assert table.id == str(location / "username" / "username.csv")
|
||||
assert table.repo_id == str(location)
|
||||
assert table.schema_id == str(location / "username")
|
||||
assert table.name == "username.csv"
|
||||
assert table.value == str(location / "username" / "username.csv")
|
||||
assert table.partitions == []
|
||||
Reference in New Issue
Block a user