forked from LaunchPlatform/beanhub-import
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: date fields are treated as strings (#44)
many issues that became non obvious in config file parse issues and matchers and correlation between matcher config and what format you should be comparing against. So now when extracting, use the `ExtractorBase.parse_date` as it will emit a date string in the format acceptable to beancount. From thereon, your matchers can expect to work with dates as a string in that format as you see it in your journals. Specifying a date format in your extractor classes or in your extractor config is merely to there to convert the date string found in your source files (pdf, csv etc).
- Loading branch information
Showing
9 changed files
with
167 additions
and
16 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 was deleted.
Oops, something went wrong.
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,63 @@ | ||
import arrow | ||
import pytest | ||
|
||
from beancount_importer_rules.data_types import StrRegexMatch | ||
from beancount_importer_rules.processor.matchers import ( | ||
match_str, | ||
) | ||
|
||
now = arrow.utcnow() | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"pattern, value, expected", | ||
[ | ||
( | ||
r"2021-01-01", | ||
r"2021-01-01", | ||
True, | ||
), | ||
( | ||
r"2021-01-01", | ||
r"2021-01-02", | ||
False, | ||
), | ||
( | ||
r"2021-01-01", | ||
None, | ||
False, | ||
), | ||
( | ||
r"2021-01-01", | ||
now.format("YYYY-MM-DD"), | ||
False, | ||
), | ||
( | ||
r"2021-01-01", | ||
"2021-01-01", | ||
True, | ||
), | ||
( | ||
r"2021-01-01", | ||
"2021-01-02", | ||
False, | ||
), | ||
( | ||
r"2021-01-.*", | ||
"2021-01-02", | ||
True, | ||
), | ||
( | ||
"2021", | ||
"2021-01-02", | ||
True, | ||
), | ||
], | ||
) | ||
def test_match_regex( | ||
pattern: str | StrRegexMatch, | ||
value: str | None, | ||
expected: bool, | ||
): | ||
outcome = match_str(pattern, value) == expected | ||
assert outcome |
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,18 @@ | ||
from beancount_importer_rules.templates import make_environment | ||
|
||
|
||
def test_make_environment(): | ||
env = make_environment() | ||
assert env | ||
assert env.filters["as_date"] | ||
assert env.filters["as_datetime"] | ||
assert env.filters["datetime_format"] | ||
assert env.filters["as_posix_path"] | ||
|
||
|
||
def test_format_datetime(): | ||
env = make_environment() | ||
template = "{{ date | as_date | datetime_format('%Y') }}" | ||
result = env.from_string(template).render({"date": "2022-01-01"}) | ||
|
||
assert result == "2022" |