Skip to content

Commit 7a0f3e4

Browse files
committed
tests: remove now-moved trntype import from tests/test_utils.py
1 parent 75ab04b commit 7a0f3e4

File tree

1 file changed

+16
-45
lines changed

1 file changed

+16
-45
lines changed

tests/test_utils.py

Lines changed: 16 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,16 @@
1111
sys.path.append(str(Path(__file__).resolve().parents[1]))
1212

1313
from utils.build_ofx import build_ofx
14-
from utils.cleaning import infer_trntype_series
1514
from utils.date_time import ofx_datetime, parse_time_to_timedelta
1615
from utils.id import make_fitid
1716
from utils.validate import assert_ofx_ready
1817

1918
from utils.rules import load_rules
2019
from utils.etl import load_and_prepare
21-
from utils.llm_enrichment import enrich_transactions_with_llm, _resolve_mlx_client_config
20+
from utils.llm_enrichment import (
21+
enrich_transactions_with_llm,
22+
_resolve_mlx_client_config,
23+
)
2224

2325

2426
@pytest.fixture
@@ -33,7 +35,6 @@ def df_without_dates():
3335
)
3436

3537

36-
3738
def test_assert_ofx_ready_accepts_valid_dataframe():
3839
df = pd.DataFrame(
3940
{
@@ -82,6 +83,7 @@ def test_assert_ofx_ready_accepts_fallback_timestamp():
8283

8384
assert result == fallback
8485

86+
8587
@pytest.fixture
8688
def sample_transaction_csv(tmp_path):
8789
df = pd.DataFrame(
@@ -96,7 +98,6 @@ def sample_transaction_csv(tmp_path):
9698
return csv_path
9799

98100

99-
100101
def test_ofx_datetime_formats_timestamp():
101102
ts = pd.Timestamp("2023-05-01 12:34:56", tz="UTC")
102103
assert ofx_datetime(ts) == "20230501123456.000[0:UTC]"
@@ -129,9 +130,13 @@ def test_make_fitid_generates_deterministic_hash():
129130
"name": "name",
130131
}
131132
)
132-
expected = hashlib.md5(
133-
"20230501000000.000[0:UTC]|12.34|Test Transaction|memo|name|0".encode()
134-
).hexdigest().upper()
133+
expected = (
134+
hashlib.md5(
135+
"20230501000000.000[0:UTC]|12.34|Test Transaction|memo|name|0".encode()
136+
)
137+
.hexdigest()
138+
.upper()
139+
)
135140
assert make_fitid(row, 0) == expected
136141

137142

@@ -186,7 +191,6 @@ def test_build_ofx_defaults_missing_dtposted(df_without_dates):
186191
assert re.fullmatch(r"\d{14}\.\d{3}\[0:UTC\]", dtposted_value)
187192

188193

189-
190194
def test_build_ofx_uses_fallback_timestamp_for_ranges():
191195
fallback = pd.Timestamp("2023-03-31", tz="UTC")
192196
df = pd.DataFrame(
@@ -217,39 +221,6 @@ def test_build_ofx_requires_amount_column():
217221
build_ofx(df, accttype="checking", acctid="12345")
218222

219223

220-
def test_infer_trntype_series_uses_custom_rules(tmp_path):
221-
config_path = tmp_path / "rules.json"
222-
config_path.write_text(
223-
json.dumps(
224-
{
225-
"source_aliases": {"XYZ": "PAYMENT"},
226-
"keyword_rules": {
227-
"extend": [
228-
{
229-
"pattern": r"\bESPRESSO\b",
230-
"trntype": "CASH",
231-
}
232-
]
233-
},
234-
}
235-
)
236-
)
237-
238-
custom_rules = load_rules(config_path)
239-
240-
amounts = pd.Series([10.0, -12.5])
241-
trntype_text = pd.Series(["xyz", None])
242-
cleaned_desc = pd.Series([None, "Morning espresso run"])
243-
244-
result = infer_trntype_series(
245-
amounts,
246-
trntype_text,
247-
cleaned_desc,
248-
rules=custom_rules,
249-
)
250-
251-
assert list(result) == ["PAYMENT", "CASH"]
252-
253224
def test_load_and_prepare_handles_csv(sample_transaction_csv):
254225
df = load_and_prepare(sample_transaction_csv)
255226

@@ -280,9 +251,9 @@ def generate_batch(self, prompts):
280251
)
281252
elif "Hardware" in prompt:
282253
responses.append(
283-
"Here you go: {\"payee\": \"Ace Hardware\","
284-
" \"category\": \"Home Improvement\","
285-
" \"description\": \"Hardware run\"}"
254+
'Here you go: {"payee": "Ace Hardware",'
255+
' "category": "Home Improvement",'
256+
' "description": "Hardware run"}'
286257
)
287258
else:
288259
responses.append("No idea")
@@ -392,6 +363,7 @@ def fake_generate(model, tokenizer, prompt, **kwargs):
392363
assert len(fake_module.calls) == len(df)
393364
assert all(call[0] == "single" for call in fake_module.calls)
394365

366+
395367
def test_load_and_prepare_enriches_when_llm_client_provided(tmp_path):
396368
csv_path = tmp_path / "transactions.csv"
397369
pd.DataFrame(
@@ -410,4 +382,3 @@ def test_load_and_prepare_enriches_when_llm_client_provided(tmp_path):
410382
assert df.loc[0, "payee_llm"] == "Daily Grind Coffee"
411383
assert df.loc[0, "category_llm"] == "Food & Drink"
412384
assert df.loc[1, "payee_llm"] == "Ace Hardware"
413-

0 commit comments

Comments
 (0)