def test_by_category(): manager = ExpenseManager() Expense1 = Expense(1, "Food", 50, "2020-04-29") Expense2 = Expense(2, "School", 20, "2021-04-30") Expense3 = Expense(3, "Food", 36.6, "2021-05-01") Expense4 = Expense(4, "Family", 100, "2021-05-02") Expense5 = Expense(5, "Family", 88.8, "2021-01-02") # Add to the manager manager.add_expense(Expense1) manager.add_expense(Expense2) manager.add_expense(Expense3) manager.add_expense(Expense4) manager.add_expense(Expense5) assert manager.by_category()["Food"][0] == 36.6 assert manager.by_category()["Family"][0] == 188.8 assert manager.by_category()["Health"][0] == 0
def display_expense_by_category(): """ Summarize all expenses by category :return: All expenses subtotal by category in last 12 months, with percentage :rtype: dict """ EM = ExpenseManager() EM.from_csv(expense_csv) return EM.by_category()