-
-
Notifications
You must be signed in to change notification settings - Fork 55
Triage open/closed issues: parser fixes + opt-in transaction grouping #124
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
2ec2ffa
Parse non-standard :61: statement lines (#111, #117, #121)
wolph 76a7624
Strip dangling BIC/IBAN labels from detail segments (#109)
wolph 3600304
Add opt-in transaction_boundary grouping (#110); stdout regression te…
wolph 5b60a57
Address PR review (#124)
wolph 9152878
Address PR review round 2 (#124)
wolph File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,44 +1,46 @@ | ||
| import datetime | ||
|
|
||
| import mt940 | ||
|
|
||
|
|
||
| def _statement( | ||
| transactions: mt940.models.Transactions, **kwargs: object | ||
| ) -> dict: | ||
| statement = mt940.tags.Statement() | ||
| data = dict(amount='123', status='D', **kwargs) | ||
| return statement(transactions, data) | ||
|
|
||
|
|
||
| def test_entry_dates_wrapping_years(): | ||
| transactions = mt940.models.Transactions() | ||
| statement = mt940.tags.Statement() | ||
| data = dict( | ||
| amount='123', | ||
| status='D', | ||
| year=2000, | ||
| ) | ||
|
|
||
| # Regular statement | ||
| statement( | ||
| transactions, | ||
| dict( | ||
| data.items(), | ||
| month=1, | ||
| day=1, | ||
| ), | ||
| # Regular statement without an entry date: only the value date is set. | ||
| regular = _statement(transactions, year=2000, month=1, day=1) | ||
| assert regular['date'] == datetime.date(2000, 1, 1) | ||
| assert 'entry_date' not in regular | ||
|
|
||
| # Entry date in the same year as the value date: no correction applied. | ||
| same_year = _statement( | ||
| transactions, year=2000, month=6, day=15, entry_month=6, entry_day=10 | ||
| ) | ||
| assert same_year['date'] == datetime.date(2000, 6, 15) | ||
| assert same_year['entry_date'] == datetime.date(2000, 6, 10) | ||
| assert same_year['guessed_entry_date'] == same_year['entry_date'] | ||
|
|
||
| # Statement which wraps to the future | ||
| statement( | ||
| transactions, | ||
| dict( | ||
| data.items(), | ||
| month=12, | ||
| day=31, | ||
| entry_day=1, | ||
| entry_month=1, | ||
| ), | ||
| # Entry date wraps into the next year (value date Dec, entry date Jan). | ||
| forward = _statement( | ||
| transactions, year=2000, month=12, day=31, entry_month=1, entry_day=1 | ||
| ) | ||
| # Statement which wraps the past year | ||
| statement( | ||
| transactions, | ||
| dict( | ||
| data.items(), | ||
| month=1, | ||
| day=1, | ||
| entry_day=31, | ||
| entry_month=12, | ||
| ), | ||
| assert forward['date'] == datetime.date(2000, 12, 31) | ||
| assert forward['entry_date'] == datetime.date(2001, 1, 1) | ||
| assert forward['guessed_entry_date'] == forward['entry_date'] | ||
|
|
||
| # Entry date wraps into the previous year (value date Jan, entry date | ||
| # Dec) -- issue #121. `entry_date` must be resolved, not left in the | ||
| # value date's year. | ||
| backward = _statement( | ||
| transactions, year=2000, month=1, day=1, entry_month=12, entry_day=31 | ||
| ) | ||
| assert backward['date'] == datetime.date(2000, 1, 1) | ||
| assert backward['entry_date'] == datetime.date(1999, 12, 31) | ||
| assert backward['guessed_entry_date'] == backward['entry_date'] |
This file contains hidden or 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,26 @@ | ||
| """Issue #106: parsing must not depend on sys.stdout/sys.stderr being usable. | ||
|
|
||
| Sandboxed / serverless environments (and some GUI apps) run with | ||
| ``sys.stdout``/``sys.stderr`` set to ``None``. Parsing valid data must work | ||
| there without raising ``AttributeError: 'NoneType' object has no attribute | ||
| 'encoding'``. | ||
| """ | ||
|
|
||
| import mt940 | ||
|
|
||
| VALID = """:20:STARTUMS | ||
| :25:NL12RABO0123456789 | ||
| :28C:0 | ||
| :60F:C220706EUR100,00 | ||
| :61:2207060706C10,00NTRFref//bank | ||
| :86:116?00Payment | ||
| :62F:C220706EUR110,00 | ||
| """ | ||
|
|
||
|
|
||
| def test_parses_without_stdout_and_stderr(monkeypatch): | ||
| monkeypatch.setattr('sys.stdout', None) | ||
| monkeypatch.setattr('sys.stderr', None) | ||
| transactions = mt940.parse(VALID) | ||
| assert len(transactions) == 1 | ||
| assert str(transactions[0].data['amount']) == '10.00 EUR' |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.