-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
109 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import pytest | ||
from bean_utils import vec_query | ||
from conf import _load_config_from_dict | ||
from conf.config_data import Config | ||
from beancount.parser import parser | ||
from bean_utils.bean import parse_args | ||
|
||
|
||
@pytest.fixture | ||
def mock_config(): | ||
conf_data = { | ||
"beancount": { | ||
"account_distinguation_range": [1, 2], | ||
}, | ||
} | ||
config = _load_config_from_dict(conf_data) | ||
return config | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"account, arg, exp", | ||
[ | ||
("Assets:BoFA:Checking", 1, "BoFA"), | ||
("Assets:BoFA:Checking", [1, 1], "BoFA"), | ||
("Assets:BoFA:Checking", [1, 2], "BoFA:Checking"), | ||
("Assets:BoFA:Checking", [1, 5], "BoFA:Checking"), | ||
], | ||
) | ||
def test_convert_account(account, arg, exp, mock_config, monkeypatch): | ||
monkeypatch.setattr(vec_query.conf.config, "beancount", Config.from_dict({ | ||
"account_distinguation_range": arg, | ||
})) | ||
assert vec_query.convert_account(account) == exp | ||
|
||
|
||
def test_convert_to_natual_language(monkeypatch): | ||
trx_str = """ | ||
2022-01-01 * "Discount 'abc'" "Discount" | ||
Assets:US:BofA:Checking 4264.93 USD | ||
Equity:Opening-Balances -4264.93 USD | ||
""" | ||
monkeypatch.setattr(vec_query.conf.config, "beancount", Config.from_dict({ | ||
"account_distinguation_range": [1, 2], | ||
})) | ||
trx, _, _ = parser.parse_string(trx_str) | ||
|
||
result = vec_query.convert_to_natural_language(trx[0]) | ||
assert result == '"Discount \'abc\'" "Discount" US:BofA Opening-Balances' | ||
args = parse_args(result) | ||
assert args == ["Discount 'abc'", "Discount", "US:BofA", "Opening-Balances"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters