I have several tests that are failing for the below error and I am not sure why. The chart and print tests are not implemented yet, just looking at the transactional tests now.
Any pointers?
======================================================================
FAIL: test_withdraw_no_description (test_module.UnitTests)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/runner/boilerplate-budget-app-4/test_module.py", line 36, in test_withdraw_no_description
self.assertEqual(actual, expected, 'Expected `withdraw` method with no description to create a blank description.')
AssertionError: "'amount': -45.67, 'description': ''" != {'amount': -45.67, 'description': ''} : Expected `withdraw` method with no description to create a blank description.
----------------------------------------------------------------------
class Category:
def __init__(self, name):
self.name=name
self.ledger = []
def __str__(self):
title = f"{self.name:*^30}\n"
#title = self.name
for lines in self.ledger:
y = lines.split()
title = title + y[3] + str(y[1])+"\n"
print("Food balance " , self.get_balance())
print("")
return title
def deposit(self, amount, description='\'\''):
self.ledger.append("\'amount\': "+str(amount) + ", \'description\': " + description)
return True
def withdraw(self, withd, text='\'\''):
sum = 0
for record in self.ledger:
record = record.split(":")
record = record[1].split(",")
x = record[0].strip()
x = float(x)
sum += x
if sum > withd:
self.ledger.append("\'amount\': -"+str(withd) + ", \'description\': " + text)
return True
else:
return False
def get_balance(self):
sum = 0
for record in self.ledger:
record = record.split(":")
record = record[1].split(",")
x = record[0].strip()
x = float(x)
sum += x
return sum
def transfer(self, amount, bucket):
if self.check_funds(amount):
txt = "\'Transfer to :{}\'"
string = txt.format(bucket.name)
self.deposit("-"+str(amount), string)
txt = "\'Transfer from :{}\'"
string = txt.format(self.name)
bucket.deposit(str(amount), string)
return True
else:
return False
def check_funds (self, amount):
sum = 0
for record in self.ledger:
record = record.split(":")
record = record[1].split(",")
x = record[0].strip()
x = float(x)
sum += x
if sum >= amount:
return True
else:
return False
def create_spend_chart(test):
pass
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.190 Safari/537.36.
Challenge: Budget App
Link to the challenge: