Files
stack/tests/rex/test_pipe.py

67 lines
2.0 KiB
Python

"""Tests for rex.pipe — extract() and ingest() entry points."""
from __future__ import annotations
from unittest.mock import MagicMock
import pytest
from rex.pipe import extract, ingest
class TestExtract:
def test_raises_not_implemented(self) -> None:
with pytest.raises(NotImplementedError):
extract("fake.lst", format="sas_listing")
class TestIngest:
def test_without_store_raises_not_implemented(self) -> None:
with pytest.raises(NotImplementedError):
ingest(
paths=["a.lst"],
format="sas_listing",
context=MagicMock(),
)
def test_with_store_delegates(self) -> None:
store = MagicMock()
store.extract_batch.return_value = "PULLKEY1"
store.get_pull.return_value = {
"target": "input_layer.medical_claim",
"rows_total": 42,
}
store.get_files.return_value = [
{"source_path": "a.lst", "status": "complete", "error": ""},
{"source_path": "b.lst", "status": "failed", "error": "bad file"},
]
result = ingest(
paths=["a.lst", "b.lst"],
format="sas_listing",
context=MagicMock(),
store=store,
)
assert result["pull_key"] == "PULLKEY1"
assert result["files_processed"] == 2
assert result["rows_total"] == 42
assert len(result["errors"]) == 1
assert result["errors"][0] == ("b.lst", "bad file")
def test_with_store_and_target_override(self) -> None:
store = MagicMock()
store.extract_batch.return_value = "PK2"
store.get_pull.return_value = {"target": "", "rows_total": 10}
store.get_files.return_value = []
result = ingest(
paths=["x.lst"],
format="fmt",
context=MagicMock(),
target="input_layer.eligibility",
store=store,
)
assert result["table_ref"] == "input_layer.eligibility"
assert result["errors"] == []