Hello everyone, I’m doing the budget app project and I’m stuck with the printing of the budget object. It looks totally fine but in the unittest it shows an error:
MY OUTPUT:
UNITTEST ERROR:
Traceback (most recent call last):
File "/home/runner/boilerplate-budget-app/test_module.py", line 83, in test_to_string
self.assertEqual(actual, expected, 'Expected different string representation of object.')
AssertionError: ' *************Food************* \n deposi[105 chars]4.33' != '*************Food*************\ndeposit [96 chars]4.33'
- *************Food*************
? - -
+ *************Food*************
- deposit 900.00
? - -
+ deposit 900.00
- milk, cereal, eggs, bac -45.67
? - -
+ milk, cereal, eggs, bac -45.67
- Transfer to Entertainme -20.00
? - -
+ Transfer to Entertainme -20.00
- Total: 834.33? -
+ Total: 834.33 : Expected different string representation of object.
MY CODE (str method):
def __str__(self):
li = ["", self.name.center(30, "*"), "\n"]
for ele in self.ledger:
if len(ele["description"]) > 23:
char_li = list(ele["description"])
del char_li[23:]
ele["description"] = "".join(char_li)
x = True
just = 23
while x:
if len(ele["description"].ljust(just) + " " + f"{float(ele['amount']):> 0.2f}") > 30:
just -= 1
else:
x = False
li.append(ele["description"].ljust(just) + " " + f"{float(ele['amount']):> 0.2f}")
li.append("\n")
if type(self.fund) is float:
li.append(f"Total: {self.fund}")
else:
li.append(f"Total: {self.fund}.00")
final_str = ' '.join([str(elem) for elem in li])
return final_str
It probably has to do with spacing but I can’t figure out how to fix it…
Thank you in advance!!!