Skip to content

Commit

Permalink
Add some unit tests for get_price_jobs_up_to_date.
Browse files Browse the repository at this point in the history
There are two behaviors I am not sure if they are features or bugs.
1. get_price_jobs_at_date() does not return a price for a date when
   commodity first appears in a transaction (maybe off by one error?).
2. get_price_jobs_(up_to|at)_date() behave differently for commodities
   not held at cost. If this is a bug, I can fix it in this or followup
   PR.
  • Loading branch information
doriath committed Apr 10, 2021
1 parent 2fcc62f commit faf3e92
Showing 1 changed file with 66 additions and 0 deletions.
66 changes: 66 additions & 0 deletions beanprice/price_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,72 @@ def test_get_price_jobs__default_source(self, entries, _, __):
self.assertEqual(1, len(jobs[0].sources))
self.assertIsInstance(jobs[0].sources[0], price.PriceSource)

@loader.load_doc()
def test_get_price_jobs__currencies_not_at_cost(self, entries, _, __):
"""
2000-01-10 open Assets:US:BofA:Checking
2000-01-10 open Assets:US:BofA:CHF
2014-01-01 commodity USD
2014-01-01 commodity CHF
price: "USD:yahoo/CHFUSD=X"
2021-01-04 *
Assets:US:BofA:Checking 100 USD
Assets:US:BofA:CHF -110 CHF @@ 100 USD
"""
# TODO: Shouldn't we actually return (CHF, USD) here?
jobs = price.get_price_jobs_at_date(entries, datetime.date(2021, 1, 4),
False, None)
self.assertEqual(set(), {(job.base, job.quote) for job in jobs})

jobs = price.get_price_jobs_at_date(entries, datetime.date(2021, 1, 6),
False, None)
self.assertEqual({('CHF', 'USD')}, {(job.base, job.quote) for job in jobs})

# TODO: Shouldn't we return (CHF, USD) here, as above?
jobs = price.get_price_jobs_up_to_date(entries, datetime.date(2021, 1, 6),
False, None)
self.assertEqual(set(), {(job.base, job.quote) for job in jobs})

@loader.load_doc()
def test_get_price_jobs_up_to_date(self, entries, _, __):
"""
2000-01-10 open Assets:US:Invest:QQQ
2000-01-10 open Assets:US:Invest:VEA
2000-01-10 open Assets:US:Invest:Margin
2021-01-01 commodity QQQ
price: "USD:yahoo/NASDAQ:QQQ"
2021-01-01 commodity VEA
price: "USD:yahoo/NASDAQ:VEA"
2021-01-04 *
Assets:US:Invest:QQQ 100 QQQ {86.23 USD}
Assets:US:Invest:VEA 200 VEA {43.22 USD}
Assets:US:Invest:Margin
2021-01-05 *
Assets:US:Invest:QQQ -100 QQQ {86.23 USD} @ 91.23 USD
Assets:US:Invest:Margin
2021-01-07 *
Assets:US:Invest:QQQ 10 QQQ {92.32 USD}
Assets:US:Invest:VEA -200 VEA {43.22 USD} @ 41.01 USD
Assets:US:Invest:Margin
"""
jobs = price.get_price_jobs_up_to_date(entries, datetime.date(2021, 1, 8))
self.assertEqual({
('QQQ', 'USD', datetime.date(2021, 1, 4)),
('QQQ', 'USD', datetime.date(2021, 1, 5)),
('QQQ', 'USD', datetime.date(2021, 1, 7)),
('VEA', 'USD', datetime.date(2021, 1, 4)),
('VEA', 'USD', datetime.date(2021, 1, 5)),
('VEA', 'USD', datetime.date(2021, 1, 6)),
('VEA', 'USD', datetime.date(2021, 1, 7)),
}, {(job.base, job.quote, job.date) for job in jobs})


class TestFromFile(unittest.TestCase):

Expand Down

0 comments on commit faf3e92

Please sign in to comment.