Changeset - 965aeabde95e
[Not reviewed]
0 1 0
Ben Sturmfels (bsturmfels) - 2 years ago 2022-02-22 22:58:53
ben@sturm.com.au
reconcile: Update tests with renamed module.
1 file changed with 11 insertions and 5 deletions:
0 comments (0 inline, 0 general)
tests/test_reconcile.py
Show inline comments
 
import datetime
 
import decimal
 
import os
 
import tempfile
 
import textwrap
 

	
 
from conservancy_beancount.reconcile.prototype_amex_reconciler import (
 
from conservancy_beancount.reconcile.statement_reconciler import (
 
    match_statement_and_books,
 
    remove_payee_junk,
 
    date_proximity,
 
    remove_duplicate_words,
 
    payee_match,
 
    metadata_for_match,
 
    write_metadata_to_books,
 
    totals,
 
)
 

	
 
# These data structures represent individual transactions as taken from the
 
# statement ("S") or the books ("B").
 

	
 
# Statement transaction examples.
 
S1 = {
 
    'date': datetime.date(2022, 1, 1),
 
    'amount': decimal.Decimal('10.00'),
 
    'payee': 'Patreon         / Patreon   / 123456/ ST-A1B2C3D4G5H6       /',
 
    'check_id': '',
 
    'line': 222,
...
 
@@ -34,12 +38,13 @@ S3 = {
 
    'amount': decimal.Decimal('30.00'),
 
    'payee': 'USPS PO 4067540039 0PORTLAND            OR',
 
    'check_id': '',
 
    'line': 444,
 
}
 

	
 
# Books transaction examples.
 
B1 = {
 
    'date': datetime.date(2022, 1, 1),
 
    'amount': decimal.Decimal('10.00'),
 
    'payee': 'Patreon',
 
    'check_id': '',
 
    'filename': '2022/imports.beancount',
...
 
@@ -112,12 +117,17 @@ B3_unmatched_check_id = {
 

	
 

	
 
def test_one_exact_match():
 
    statement = [S1]
 
    books = [B1]
 
    assert match_statement_and_books(statement, books) == [
 
        # Match, match, notes.
 
        #
 
        # The matches are a list so we can implement subset-sum matching where
 
        # multiple books transactions may match to a single statement
 
        # transaction.
 
        ([S1], [B1], []),
 
    ]
 

	
 
def test_multiple_exact_matches():
 
    statement = [S1, S2]
 
    books = [B1, B2]
...
 
@@ -177,24 +187,21 @@ def test_payee_mismatch_not_ok_when_multiple_that_amount_and_date():
 
    assert match == [
 
        ([S3], [], ['no match']),
 
        ([], [B3_payee_mismatch_1], ['no match']),
 
        ([], [B3_payee_mismatch_2], ['no match']),
 
    ]
 

	
 
# def test_subset_sum_with_same_date_and_payee():
 

	
 
def test_remove_payee_junk():
 
    assert remove_payee_junk('WIDGETSRUS INC PAYMENT 1') == 'WIDGETSRUS'
 
    assert remove_payee_junk('0000010017') == '10017'
 

	
 
def test_date_proximity():
 
    assert date_proximity(datetime.date(2021, 8, 23), datetime.date(2021, 8, 23)) == 1.0
 
    assert date_proximity(datetime.date(2021, 8, 23), datetime.date(2021, 8, 23) - datetime.timedelta(days=30)) == 0.5
 
    assert date_proximity(datetime.date(2021, 8, 23), datetime.date(2021, 8, 23) - datetime.timedelta(days=60)) == 0.0
 

	
 

	
 
def test_remove_duplicate_words():
 
    assert remove_duplicate_words('Hi Foo Kow FOO') == 'Hi Foo Kow'
 

	
 
def test_remove_duplicate_words():
 
    assert remove_duplicate_words('Hi Foo Kow FOO') == 'Hi Foo Kow'
 

	
...
 
@@ -237,13 +244,12 @@ def test_totals():
 
    assert totals([
 
        ([S1], [B1], []),
 
        ([S2], [], []),
 
        ([], [B3_next_day], []),
 
    ]) == (decimal.Decimal('10'), decimal.Decimal('20'), decimal.Decimal('30'))
 

	
 

	
 
def test_payee_not_considered_if_check_id_present():
 
    # These records match aside from check-id.
 
    statement = [S3]
 
    books = [B3_unmatched_check_id]
 
    assert match_statement_and_books(statement, books) == [
 
        ([S3], [], ['no match']),
0 comments (0 inline, 0 general)