Changeset - 99dbd1ac9596
[Not reviewed]
0 2 0
Brett Smith - 4 years ago 2020-04-22 13:17:58
brettcsmith@brettcsmith.org
tests: Promote date_seq to testutil.
2 files changed with 6 insertions and 6 deletions:
0 comments (0 inline, 0 general)
tests/test_reports_related_postings.py
Show inline comments
...
 
@@ -18,31 +18,26 @@ import collections
 
import datetime
 
import itertools
 

	
 
from decimal import Decimal
 

	
 
import pytest
 

	
 
from . import testutil
 

	
 
from conservancy_beancount import data
 
from conservancy_beancount.reports import core
 

	
 
def date_seq(date=testutil.FY_MID_DATE, step=1):
 
    while True:
 
        yield date
 
        date = date + datetime.timedelta(days=step)
 

	
 
def accruals_and_payments(acct, src_acct, dst_acct, start_date, *amounts):
 
    dates = date_seq(start_date)
 
    dates = testutil.date_seq(start_date)
 
    for amt, currency in amounts:
 
        yield testutil.Transaction(date=next(dates), postings=[
 
            (acct, amt, currency),
 
            (dst_acct if amt < 0 else src_acct, -amt, currency),
 
        ])
 

	
 
@pytest.fixture
 
def credit_card_cycle():
 
    return list(accruals_and_payments(
 
        'Liabilities:CreditCard',
 
        'Assets:Checking',
 
        'Expenses:Other',
tests/testutil.py
Show inline comments
...
 
@@ -46,24 +46,29 @@ def check_post_meta(txn, *expected_meta, default=None):
 
def combine_values(*value_seqs):
 
    stop = 0
 
    for seq in value_seqs:
 
        try:
 
            stop = max(stop, len(seq))
 
        except TypeError:
 
            pass
 
    return itertools.islice(
 
        zip(*(itertools.cycle(seq) for seq in value_seqs)),
 
        stop,
 
    )
 

	
 
def date_seq(date=FY_MID_DATE, step=1):
 
    while True:
 
        yield date
 
        date += datetime.timedelta(days=step)
 

	
 
def parse_date(s, fmt='%Y-%m-%d'):
 
    return datetime.datetime.strptime(s, fmt).date()
 

	
 
def test_path(s):
 
    if s is None:
 
        return s
 
    s = Path(s)
 
    if not s.is_absolute():
 
        s = TESTS_DIR / s
 
    return s
 

	
 
def Amount(number, currency='USD'):
0 comments (0 inline, 0 general)