Changeset - 95ba1638d282
[Not reviewed]
0 2 0
Brett Smith - 4 years ago 2020-06-04 13:49:39
brettcsmith@brettcsmith.org
filters: remove_opening_balance_txn does replacement instead of del.
2 files changed with 13 insertions and 2 deletions:
0 comments (0 inline, 0 general)
conservancy_beancount/filters.py
Show inline comments
...
 
@@ -87,5 +87,12 @@ def remove_opening_balance_txn(entries: Entries) -> Optional[Transaction]:
 
                break
 
    else:
 
        return None
 
    del entries[index]
 
    # Deleting from the beginning of a list is O(n) slow in Python:
 
    # <https://wiki.python.org/moin/TimeComplexity>
 
    # So don't do that, and instead replace the transaction with a placeholder
 
    # directive.
 
    # The type:ignore is because of the funny way Beancount builds directives.
 
    entries[index] = bc_data.Custom(  # type:ignore[operator]
 
        entry.meta, entry.date, "Removed opening balances", [],
 
    )
 
    return entry
tests/test_filters.py
Show inline comments
...
 
@@ -153,5 +153,9 @@ def test_remove_opening_balance_txn(opening_txn):
 
        entries.insert(1, opening_txn)
 
    actual = filters.remove_opening_balance_txn(entries)
 
    assert actual is opening_txn
 
    assert len(entries) == 2
 
    assert opening_txn not in entries
 
    assert not any(
 
        post.account.startswith('Equity:')
 
        for entry in entries
 
        for post in getattr(entry, 'postings', ())
 
    )
0 comments (0 inline, 0 general)