Skip to content

Commit

Permalink
Fix broken stuff once again, added tests this time
Browse files Browse the repository at this point in the history
  • Loading branch information
fangpenlin committed Jan 23, 2025
1 parent 2e678f4 commit e310f9a
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 7 deletions.
4 changes: 3 additions & 1 deletion beanhub_import/processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,9 @@ def process_imports(
continue
rel_filepath = filepath.relative_to(input_dir)
extractor_name = (
input_config.config.extractor if input_config is not None else None
input_config.config.extractor
if input_config.config is not None
else None
)
if extractor_name is None:
with filepath.open("rt") as fo:
Expand Down
10 changes: 4 additions & 6 deletions tests/fixtures/processor/auto-detect/import.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
inputs:
- match: "*.csv"
config:
prepend_postings:
- account: Assets:Bank:US:Mercury
amount:
number: "{{ amount }}"
currency: "{{ currency | default('USD', true) }}"

imports:
- match:
Expand All @@ -16,6 +10,10 @@ imports:
file: "output.bean"
txn:
postings:
- account: Assets:Bank:US:Mercury
amount:
number: "{{ amount }}"
currency: "{{ currency | default('USD', true) }}"
- account: "Expenses"
amount:
number: "{{ -amount }}"
Expand Down
22 changes: 22 additions & 0 deletions tests/fixtures/processor/input-without-config/import.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
inputs:
- match: "*.csv"
config:
prepend_postings:
- account: Assets:Bank:US:Mercury
amount:
number: "{{ amount }}"
currency: "{{ currency | default('USD', true) }}"

imports:
- match:
extractor:
equals: "mercury"
actions:
- type: add_txn
file: "output.bean"
txn:
postings:
- account: "Expenses"
amount:
number: "{{ -amount }}"
currency: "{{ currency | default('USD', true) }}"
2 changes: 2 additions & 0 deletions tests/fixtures/processor/input-without-config/mercury.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Date (UTC),Description,Amount,Status,Source Account,Bank Description,Reference,Note,Last Four Digits,Name On Card,Category,GL Code,Timestamp,Original Currency
04-15-2024,Jane Doe,-1500.00,Sent,Mercury Checking xx1234,Send Money transaction initiated on Mercury,Profit distribution,,,,,,04-15-2024 14:35:37,
23 changes: 23 additions & 0 deletions tests/test_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -993,6 +993,29 @@ def get_result():
),
],
),
(
"input-without-config",
[
GeneratedTransaction(
file="output.bean",
id="mercury.csv:-1",
sources=["mercury.csv"],
date="2024-04-15",
flag="*",
narration="Jane Doe",
postings=[
GeneratedPosting(
account="Assets:Bank:US:Mercury",
amount=Amount(number="-1500.00", currency="USD"),
),
GeneratedPosting(
account="Expenses",
amount=Amount(number="1500.00", currency="USD"),
),
],
),
],
),
],
)
def test_process_imports(
Expand Down

0 comments on commit e310f9a

Please sign in to comment.