tests: Add _meta_type kwarg to testutil.Posting.
This commit is contained in:
parent
f76fa35fad
commit
1cbc9d3dc9
2 changed files with 20 additions and 37 deletions
|
@ -248,50 +248,31 @@ def test_meta_values_many_types():
|
||||||
|
|
||||||
@pytest.mark.parametrize('count', range(3))
|
@pytest.mark.parametrize('count', range(3))
|
||||||
def test_all_meta_links_zero(count):
|
def test_all_meta_links_zero(count):
|
||||||
postings = (
|
related = core.RelatedPostings(testutil.Posting(
|
||||||
testutil.Posting('Income:Donations', -n, testkey=str(n))
|
'Income:Donations', -n, testkey=str(n), _meta_type=data.Metadata,
|
||||||
for n in range(count)
|
) for n in range(count))
|
||||||
)
|
|
||||||
related = core.RelatedPostings(
|
|
||||||
post._replace(meta=data.Metadata(post.meta))
|
|
||||||
for post in postings
|
|
||||||
)
|
|
||||||
assert next(related.all_meta_links('approval'), None) is None
|
assert next(related.all_meta_links('approval'), None) is None
|
||||||
|
|
||||||
def test_all_meta_links_singletons():
|
def test_all_meta_links_singletons():
|
||||||
postings = (
|
related = core.RelatedPostings(testutil.Posting(
|
||||||
testutil.Posting('Income:Donations', -10, statement=value)
|
'Income:Donations', -10, statement=value, _meta_type=data.Metadata,
|
||||||
for value in itertools.chain(
|
) for value in itertools.chain(
|
||||||
testutil.NON_LINK_METADATA_STRINGS,
|
testutil.NON_LINK_METADATA_STRINGS,
|
||||||
testutil.LINK_METADATA_STRINGS,
|
testutil.LINK_METADATA_STRINGS,
|
||||||
testutil.NON_STRING_METADATA_VALUES,
|
testutil.NON_STRING_METADATA_VALUES,
|
||||||
))
|
))
|
||||||
related = core.RelatedPostings(
|
|
||||||
post._replace(meta=data.Metadata(post.meta))
|
|
||||||
for post in postings
|
|
||||||
)
|
|
||||||
assert set(related.all_meta_links('statement')) == testutil.LINK_METADATA_STRINGS
|
assert set(related.all_meta_links('statement')) == testutil.LINK_METADATA_STRINGS
|
||||||
|
|
||||||
def test_all_meta_links_multiples():
|
def test_all_meta_links_multiples():
|
||||||
postings = (
|
related = core.RelatedPostings(testutil.Posting(
|
||||||
testutil.Posting('Income:Donations', -10, approval=' '.join(value))
|
'Income:Donations', -10, approval=' '.join(value), _meta_type=data.Metadata,
|
||||||
for value in itertools.permutations(testutil.LINK_METADATA_STRINGS, 2)
|
) for value in itertools.permutations(testutil.LINK_METADATA_STRINGS, 2))
|
||||||
)
|
|
||||||
related = core.RelatedPostings(
|
|
||||||
post._replace(meta=data.Metadata(post.meta))
|
|
||||||
for post in postings
|
|
||||||
)
|
|
||||||
assert set(related.all_meta_links('approval')) == testutil.LINK_METADATA_STRINGS
|
assert set(related.all_meta_links('approval')) == testutil.LINK_METADATA_STRINGS
|
||||||
|
|
||||||
def test_all_meta_links_preserves_order():
|
def test_all_meta_links_preserves_order():
|
||||||
postings = (
|
related = core.RelatedPostings(testutil.Posting(
|
||||||
testutil.Posting('Income:Donations', -10, approval=c)
|
'Income:Donations', -10, approval=c, _meta_type=data.Metadata,
|
||||||
for c in '121323'
|
) for c in '121323')
|
||||||
)
|
|
||||||
related = core.RelatedPostings(
|
|
||||||
post._replace(meta=data.Metadata(post.meta))
|
|
||||||
for post in postings
|
|
||||||
)
|
|
||||||
assert list(related.all_meta_links('approval')) == list('123')
|
assert list(related.all_meta_links('approval')) == list('123')
|
||||||
|
|
||||||
def test_group_by_meta_zero():
|
def test_group_by_meta_zero():
|
||||||
|
|
|
@ -116,12 +116,14 @@ def Cost(number, currency='USD', date=FY_MID_DATE, label=None):
|
||||||
|
|
||||||
def Posting(account, number,
|
def Posting(account, number,
|
||||||
currency='USD', cost=None, price=None, flag=None,
|
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:
|
if cost is not None:
|
||||||
cost = Cost(*cost)
|
cost = Cost(*cost)
|
||||||
if not meta:
|
if not meta:
|
||||||
meta = None
|
meta = None
|
||||||
return type_(
|
elif _meta_type:
|
||||||
|
meta = _meta_type(meta)
|
||||||
|
return _post_type(
|
||||||
account,
|
account,
|
||||||
Amount(number, currency),
|
Amount(number, currency),
|
||||||
cost,
|
cost,
|
||||||
|
|
Loading…
Reference in a new issue