Changeset - 1cbc9d3dc933
[Not reviewed]
0 2 0
Brett Smith - 4 years ago 2020-06-11 17:07:14
brettcsmith@brettcsmith.org
tests: Add _meta_type kwarg to testutil.Posting.
2 files changed with 20 insertions and 37 deletions:
0 comments (0 inline, 0 general)
tests/test_reports_related_postings.py
Show inline comments
...
 
@@ -250,10 +250,5 @@ def test_meta_values_many_types():
 
def test_all_meta_links_zero(count):
 
    postings = (
 
        testutil.Posting('Income:Donations', -n, testkey=str(n))
 
        for n in range(count)
 
    )
 
    related = core.RelatedPostings(
 
        post._replace(meta=data.Metadata(post.meta))
 
        for post in postings
 
    )
 
    related = core.RelatedPostings(testutil.Posting(
 
        'Income:Donations', -n, testkey=str(n), _meta_type=data.Metadata,
 
    ) for n in range(count))
 
    assert next(related.all_meta_links('approval'), None) is None
...
 
@@ -261,13 +256,9 @@ def test_all_meta_links_zero(count):
 
def test_all_meta_links_singletons():
 
    postings = (
 
        testutil.Posting('Income:Donations', -10, statement=value)
 
        for value in itertools.chain(
 
            testutil.NON_LINK_METADATA_STRINGS,
 
            testutil.LINK_METADATA_STRINGS,
 
            testutil.NON_STRING_METADATA_VALUES,
 
        ))
 
    related = core.RelatedPostings(
 
        post._replace(meta=data.Metadata(post.meta))
 
        for post in postings
 
    )
 
    related = core.RelatedPostings(testutil.Posting(
 
        'Income:Donations', -10, statement=value, _meta_type=data.Metadata,
 
    ) for value in itertools.chain(
 
        testutil.NON_LINK_METADATA_STRINGS,
 
        testutil.LINK_METADATA_STRINGS,
 
        testutil.NON_STRING_METADATA_VALUES,
 
    ))
 
    assert set(related.all_meta_links('statement')) == testutil.LINK_METADATA_STRINGS
...
 
@@ -275,10 +266,5 @@ def test_all_meta_links_singletons():
 
def test_all_meta_links_multiples():
 
    postings = (
 
        testutil.Posting('Income:Donations', -10, approval=' '.join(value))
 
        for value in itertools.permutations(testutil.LINK_METADATA_STRINGS, 2)
 
    )
 
    related = core.RelatedPostings(
 
        post._replace(meta=data.Metadata(post.meta))
 
        for post in postings
 
    )
 
    related = core.RelatedPostings(testutil.Posting(
 
        'Income:Donations', -10, approval=' '.join(value), _meta_type=data.Metadata,
 
    ) for value in itertools.permutations(testutil.LINK_METADATA_STRINGS, 2))
 
    assert set(related.all_meta_links('approval')) == testutil.LINK_METADATA_STRINGS
...
 
@@ -286,10 +272,5 @@ def test_all_meta_links_multiples():
 
def test_all_meta_links_preserves_order():
 
    postings = (
 
        testutil.Posting('Income:Donations', -10, approval=c)
 
        for c in '121323'
 
    )
 
    related = core.RelatedPostings(
 
        post._replace(meta=data.Metadata(post.meta))
 
        for post in postings
 
    )
 
    related = core.RelatedPostings(testutil.Posting(
 
        'Income:Donations', -10, approval=c, _meta_type=data.Metadata,
 
    ) for c in '121323')
 
    assert list(related.all_meta_links('approval')) == list('123')
tests/testutil.py
Show inline comments
...
 
@@ -118,3 +118,3 @@ def Posting(account, number,
 
            currency='USD', cost=None, price=None, flag=None,
 
            type_=bc_data.Posting, **meta):
 
            _post_type=bc_data.Posting, _meta_type=None, **meta):
 
    if cost is not None:
...
 
@@ -123,3 +123,5 @@ def Posting(account, number,
 
        meta = None
 
    return type_(
 
    elif _meta_type:
 
        meta = _meta_type(meta)
 
    return _post_type(
 
        account,
0 comments (0 inline, 0 general)