2023-06-04 22:31:08 +00:00
|
|
|
from pathlib import Path
|
2024-11-07 03:57:31 +00:00
|
|
|
from typing import Generator, Callable
|
2023-06-04 22:31:08 +00:00
|
|
|
|
|
|
|
import pytest
|
|
|
|
|
|
|
|
from intake.source import LocalSource
|
|
|
|
|
|
|
|
|
|
|
|
def clean_source(source_path: Path):
|
|
|
|
for item in source_path.iterdir():
|
|
|
|
if item.name.endswith(".item"):
|
|
|
|
item.unlink()
|
|
|
|
(source_path / "state").unlink(missing_ok=True)
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
2024-11-07 03:57:31 +00:00
|
|
|
def using_source() -> Generator[Callable, None, LocalSource]:
|
2023-06-04 22:31:08 +00:00
|
|
|
test_data = Path(__file__).parent
|
2024-11-07 03:57:31 +00:00
|
|
|
sources: list[Path] = []
|
2023-06-04 22:31:08 +00:00
|
|
|
|
|
|
|
def _using_source(name: str):
|
|
|
|
source_path = test_data / name
|
|
|
|
clean_source(source_path)
|
|
|
|
sources.append(source_path)
|
|
|
|
return LocalSource(test_data, name)
|
2024-09-21 21:55:10 +00:00
|
|
|
|
2023-06-04 22:31:08 +00:00
|
|
|
yield _using_source
|
|
|
|
|
|
|
|
for source_path in sources:
|
|
|
|
clean_source(source_path)
|