csv-parser: add _validate_mapping helper
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
parent
8dcf662945
commit
f44b77df6f
2 changed files with 106 additions and 0 deletions
|
|
@ -96,3 +96,59 @@ def test_detect_dialect_empty_raises():
|
|||
|
||||
with pytest.raises(LLMParseError):
|
||||
_detect_dialect(b"")
|
||||
|
||||
|
||||
def test_validate_mapping_accepts_well_formed():
|
||||
from app.services.llm_csv_parser import _validate_mapping
|
||||
|
||||
headers = ["Symbol", "Quantity", "Avg Price", "Currency"]
|
||||
first_row = ["AAPL", "100", "150.25", "USD"]
|
||||
mapping = {
|
||||
"ticker_col": "Symbol",
|
||||
"qty_col": "Quantity",
|
||||
"cost_col": "Avg Price",
|
||||
"currency_col": "Currency",
|
||||
"name_col": None,
|
||||
}
|
||||
_validate_mapping(mapping, headers, first_row) # no raise
|
||||
|
||||
|
||||
def test_validate_mapping_missing_ticker_raises():
|
||||
from app.services.llm_csv_parser import LLMParseError, _validate_mapping
|
||||
|
||||
headers = ["Symbol", "Quantity"]
|
||||
first_row = ["AAPL", "100"]
|
||||
mapping = {"ticker_col": None, "qty_col": "Quantity"}
|
||||
with pytest.raises(LLMParseError, match="ticker"):
|
||||
_validate_mapping(mapping, headers, first_row)
|
||||
|
||||
|
||||
def test_validate_mapping_missing_qty_raises():
|
||||
from app.services.llm_csv_parser import LLMParseError, _validate_mapping
|
||||
|
||||
headers = ["Symbol", "Quantity"]
|
||||
first_row = ["AAPL", "100"]
|
||||
mapping = {"ticker_col": "Symbol", "qty_col": None}
|
||||
with pytest.raises(LLMParseError, match="qty"):
|
||||
_validate_mapping(mapping, headers, first_row)
|
||||
|
||||
|
||||
def test_validate_mapping_unknown_column_raises():
|
||||
from app.services.llm_csv_parser import LLMParseError, _validate_mapping
|
||||
|
||||
headers = ["Symbol", "Quantity"]
|
||||
first_row = ["AAPL", "100"]
|
||||
mapping = {"ticker_col": "Symbol", "qty_col": "NotARealColumn"}
|
||||
with pytest.raises(LLMParseError, match="NotARealColumn"):
|
||||
_validate_mapping(mapping, headers, first_row)
|
||||
|
||||
|
||||
def test_validate_mapping_non_numeric_qty_raises():
|
||||
from app.services.llm_csv_parser import LLMParseError, _validate_mapping
|
||||
|
||||
headers = ["Symbol", "Description"]
|
||||
first_row = ["AAPL", "Apple Inc"]
|
||||
# Mapping says qty is "Description", but "Apple Inc" can't parse as a number.
|
||||
mapping = {"ticker_col": "Symbol", "qty_col": "Description"}
|
||||
with pytest.raises(LLMParseError, match="numeric"):
|
||||
_validate_mapping(mapping, headers, first_row)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue