Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_budgets_yearly():
BUDGET = Decimal(99999.87)
budgets = _get_budgets('2010-01-01 custom "budget" Expenses:Books "yearly" {} EUR'.format(BUDGET)) # noqa
assert budgets.budget('Expenses:Books', date(2011, 2, 1), date(2011, 2, 2))['EUR'] == BUDGET / number_of_days_in_period('yearly', date(2011, 2, 1)) # noqa
assert budgets.budget('Expenses:Books', date(2015, 5, 30), date(2015, 5, 31))['EUR'] == BUDGET / number_of_days_in_period('yearly', date(2015, 5, 30)) # noqa
assert budgets.budget('Expenses:Books', date(2016, 8, 15), date(2016, 8, 16))['EUR'] == BUDGET / number_of_days_in_period('yearly', date(2016, 8, 15)) # noqa
def test_number_of_days_in_period(interval, date_str, expect):
assert number_of_days_in_period(interval, _to_date(date_str)) == expect
def test_budgets_monthly():
BUDGET = Decimal(100)
budgets = _get_budgets('2014-05-01 custom "budget" Expenses:Books "monthly" {} EUR'.format(BUDGET)) # noqa
assert budgets.budget('Expenses:Books', date(2016, 1, 1), date(2016, 1, 2))['EUR'] == BUDGET / number_of_days_in_period('monthly', date(2016, 1, 1)) # noqa
assert budgets.budget('Expenses:Books', date(2016, 2, 1), date(2016, 2, 2))['EUR'] == BUDGET / number_of_days_in_period('monthly', date(2016, 2, 1)) # noqa
assert budgets.budget('Expenses:Books', date(2018, 3, 31), date(2018, 4, 1))['EUR'] == BUDGET / number_of_days_in_period('monthly', date(2016, 3, 31)) # noqa
def test_budgets_weekly():
BUDGET = Decimal(21)
budgets = _get_budgets('2016-05-01 custom "budget" Expenses:Books "weekly" {} EUR'.format(BUDGET)) # noqa
assert budgets.budget('Expenses:Books', date(2016, 5, 1), date(2016, 5, 2))['EUR'] == BUDGET / number_of_days_in_period('weekly', date(2016, 5, 1)) # noqa
assert budgets.budget('Expenses:Books', date(2016, 9, 1), date(2016, 9, 2))['EUR'] == BUDGET / number_of_days_in_period('weekly', date(2016, 9, 1)) # noqa
assert budgets.budget('Expenses:Books', date(2018, 12, 31), date(2019, 1, 1))['EUR'] == BUDGET / number_of_days_in_period('weekly', date(2018, 12, 31)) # noqa
def test_budgets_quarterly():
BUDGET = Decimal(123456.7)
budgets = _get_budgets('2014-05-01 custom "budget" Expenses:Books "quarterly" {} EUR'.format(BUDGET)) # noqa
assert budgets.budget('Expenses:Books', date(2016, 2, 1), date(2016, 2, 2))['EUR'] == BUDGET / number_of_days_in_period('quarterly', date(2016, 2, 1)) # noqa
assert budgets.budget('Expenses:Books', date(2016, 5, 30), date(2016, 5, 31))['EUR'] == BUDGET / number_of_days_in_period('quarterly', date(2016, 5, 30)) # noqa
assert budgets.budget('Expenses:Books', date(2016, 8, 15), date(2016, 8, 16))['EUR'] == BUDGET / number_of_days_in_period('quarterly', date(2016, 8, 15)) # noqa
assert budgets.budget('Expenses:Books', date(2016, 11, 15), date(2016, 11, 16))['EUR'] == BUDGET / number_of_days_in_period('quarterly', date(2016, 11, 15)) # noqa
def test_number_of_days_in_period2():
with pytest.raises(NotImplementedError):
number_of_days_in_period("test", date(2011, 2, 1))
Returns:
A dictionary of currency to Decimal with the budget for the
specified account and period.
"""
if account_name not in budgets:
return {}
currency_dict = defaultdict(Decimal)
for single_day in days_in_daterange(date_from, date_to):
matches = _matching_budgets(budgets, account_name, single_day)
for budget in matches.values():
currency_dict[budget.currency] += (
budget.number
/ number_of_days_in_period(budget.period, single_day)
)
return currency_dict