cat_totals = 
for cat in categories:
total = 0
for c in cat.ledger:
if c['amount'] < 0:
total += c['amount']
perc_totals = [int(x/sum(cat_totals) * 10)/10 for x in cat_totals]
i = 100
res = 'Percentage spent by category' + '\n'
while i >= 0:
spc = ' '
for value in perc_totals:
if value * 100 >= i:
spc += 'o '
spc += ' '
if i == 0:
res += str(i).rjust(3) + '|' + spc
res += str(i).rjust(3) + '|' + spc + '\n'
i -= 10
#need categories name
cat_names = [x.category for x in categories]
dashes = '-' + '---' * len(cat_names)
res += '\n' + ' ' * 4 + dashes.rjust(3)
maxi = len(max(cat_names, key = len))
names = ' ' * 4
for i in range(maxi):
for name in cat_names:
names += ' ' + name[i] + ' '
names += ' '
if i == maxi - 1:
names += ' ' * 4
names += '\n' + ' ' * 4
res += '\n' + names
hello, this appear to be a common problem, i also had hard time making my chart match the expected output. Just like you I browsed different forum posts, which involved the same issue.
The way i managed to fix it, i looked up the tests file, there you can find what the expected output from the chart test is. Its under the form of a string. I compared that to the string my own chart function returns, using the test parameters. Looking it this way, it makes it very clear where differences occur. Iirc, at the end of every line there was an extra space, so i had to look at my code, where those lines were generated and edited with an extra space. Hope that helps.
FAIL: test_create_spend_chart (test_module.UnitTests)
Traceback (most recent call last):
File "/home/runner/boilerplate-budget-app-5/test_module.py", line 94, in test_create_spend_chart
self.assertEqual(actual, expected, 'Expected different chart representation. Check that all spacing is exact.')
AssertionError: 'Perc[226 chars]F E \n u o n \n s o t \n i d[139 chars] ' != 'Perc[226 chars]F E \n u o n \n s o t \n i[148 chars] t '
Diff is 891 characters long. Set self.maxDiff to None to see it. : Expected different chart representation. Check that all spacing is exact.