2025-01-03 14:54:18 +00:00
|
|
|
import shutil
|
|
|
|
from pathlib import Path
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
|
|
|
|
from plesna.storage.repository.fs_repository import FSRepository
|
|
|
|
|
|
|
|
FIXTURE_DIR = Path(__file__).parent.parent / Path("./raw_datas/")
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
def location(tmp_path):
|
2025-01-05 05:42:51 +00:00
|
|
|
schema = tmp_path / "schema"
|
2025-01-03 14:54:18 +00:00
|
|
|
example_src = FIXTURE_DIR
|
|
|
|
assert example_src.exists()
|
|
|
|
|
2025-01-05 05:42:51 +00:00
|
|
|
shutil.copytree(src=example_src.absolute(), dst=schema.absolute())
|
2025-01-03 14:54:18 +00:00
|
|
|
|
2025-01-05 05:42:51 +00:00
|
|
|
return tmp_path
|
2025-01-03 14:54:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_init(location):
|
|
|
|
repo = FSRepository("example", location, "example")
|
|
|
|
assert repo.ls() == [
|
2025-01-05 05:42:51 +00:00
|
|
|
"schema",
|
|
|
|
]
|
|
|
|
assert repo.ls(dir="schema") == [
|
2025-01-03 14:54:18 +00:00
|
|
|
"username",
|
2025-01-05 05:42:51 +00:00
|
|
|
"recovery",
|
2025-01-03 14:54:18 +00:00
|
|
|
"salary",
|
|
|
|
]
|
|
|
|
|
|
|
|
assert repo.ls(recursive=True) == [
|
2025-01-05 05:42:51 +00:00
|
|
|
"schema",
|
|
|
|
"schema/username",
|
|
|
|
"schema/recovery",
|
|
|
|
"schema/salary",
|
|
|
|
"schema/username/username.csv",
|
|
|
|
"schema/recovery/2022.csv",
|
|
|
|
"schema/recovery/2023.csv",
|
|
|
|
"schema/recovery/2024.csv",
|
|
|
|
"schema/salary/salary.pdf",
|
2025-01-03 14:54:18 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
def repository(location) -> FSRepository:
|
|
|
|
return FSRepository("example", location, "example")
|
|
|
|
|
|
|
|
|
2025-01-05 10:27:52 +00:00
|
|
|
def test_list_schemas(repository):
|
|
|
|
assert repository.schemas() == ["example-schema"]
|
|
|
|
|
|
|
|
|
|
|
|
def test_describe_schema(location, repository):
|
|
|
|
schema = repository.schema("example-schema")
|
|
|
|
assert schema.name == "schema"
|
|
|
|
assert schema.id == "example-schema"
|
|
|
|
assert schema.repo_id == str(location)
|
|
|
|
assert schema.value == str(location / "schema")
|
2025-01-05 13:34:16 +00:00
|
|
|
assert schema.tables == [
|
|
|
|
"example-schema-username",
|
|
|
|
"example-schema-recovery",
|
|
|
|
"example-schema-salary",
|
|
|
|
]
|
2025-01-03 14:54:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_list_tables_schema(repository):
|
2025-01-05 13:34:16 +00:00
|
|
|
assert repository.schema("example-schema").tables == [
|
|
|
|
"example-schema-username",
|
|
|
|
"example-schema-recovery",
|
|
|
|
"example-schema-salary",
|
|
|
|
]
|
|
|
|
assert repository.tables("example-schema") == [
|
|
|
|
"example-schema-username",
|
|
|
|
"example-schema-recovery",
|
|
|
|
"example-schema-salary",
|
|
|
|
]
|
|
|
|
assert repository.tables() == [
|
|
|
|
"example-schema-username",
|
|
|
|
"example-schema-recovery",
|
|
|
|
"example-schema-salary",
|
|
|
|
]
|
2025-01-03 14:54:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_describe_table(location, repository):
|
2025-01-05 10:27:52 +00:00
|
|
|
table = repository.table("example-schema-username")
|
2025-01-05 05:42:51 +00:00
|
|
|
|
2025-01-05 10:27:52 +00:00
|
|
|
assert table.id == "example-schema-username"
|
2025-01-03 14:54:18 +00:00
|
|
|
assert table.repo_id == str(location)
|
2025-01-05 05:42:51 +00:00
|
|
|
assert table.schema_id == str(location / "schema")
|
|
|
|
assert table.name == "username"
|
|
|
|
assert table.value == str(location / "schema" / "username")
|
|
|
|
assert table.partitions == ["username.csv"]
|
|
|
|
assert table.datas == [table.value + "/username.csv"]
|
|
|
|
|
|
|
|
|
|
|
|
def test_describe_table_with_partitions(location, repository):
|
2025-01-05 10:27:52 +00:00
|
|
|
table = repository.table("example-schema-recovery")
|
2025-01-05 05:42:51 +00:00
|
|
|
|
2025-01-05 10:27:52 +00:00
|
|
|
assert table.id == "example-schema-recovery"
|
2025-01-05 05:42:51 +00:00
|
|
|
assert table.repo_id == str(location)
|
|
|
|
assert table.schema_id == str(location / "schema")
|
|
|
|
assert table.name == "recovery"
|
|
|
|
assert table.value == str(location / "schema" / "recovery")
|
|
|
|
assert table.partitions == [
|
|
|
|
"2022.csv",
|
|
|
|
"2023.csv",
|
|
|
|
"2024.csv",
|
|
|
|
]
|
|
|
|
assert table.datas == [
|
|
|
|
table.value + "/2022.csv",
|
|
|
|
table.value + "/2023.csv",
|
|
|
|
table.value + "/2024.csv",
|
|
|
|
]
|