def test_report(self, mock_input): capture_print = print_screen() mailroom4.report(donors) clear_screen() table_contents = 'Donor Name | Total Given | Num Gifts | Average Gift |\n' table_contents += '----------------------------------------------------------------------\n' for name, donations in donors.items(): total = sum(donations) num = len(donations) table_contents += "|{:<20}|{:>15.2f}|{:>15}|{:>15.2f}|\n".format(name, total, num, total/num) self.assertEqual(capture_print.getvalue(), table_contents)
def test_report(self): text = f'{"Donor Name":20s} {"| Total Given":20s} {"| Num Gifts |":20s} {"Average Gift":20s}\n' text = text + f'{"-"*76}\n' for name in self.donations.keys(): text = text + f'{name:20s} ${sum(self.donations[name]):20.2f} {len(self.donations[name]):13d}${sum(self.donations[name])/len(self.donations[name]):20.2f}\n' print(text) self.capturedOutput1 = io.StringIO() mailroom4.report() self.capturedOutput2 = io.StringIO() self.assertEqual(self.capturedOutput1.getvalue(), self.capturedOutput2.getvalue())
def test_report(): generatedReport = report(donor) assert (generatedReport == expectedReport) is True
def test_report(self): self.assertEqual(mailroom4.report(), None)
def test_report(capsys): m.report() sys.stderr.write("error") out, err = capsys.readouterr() assert "James Bond" in out
def test_report(self): mailroom4.donors = {'Joe': [3, 3, 3]} self.assertEqual(mailroom4.report(), ['Joe $ ' '9.00 3 ' '$ 3.00'])
def test_report(): data = {"Tom": [100, 200], "Tim": [3000]} expected = [("Tim", 3000, 1, 3000), ("Tom", 300, 2, 150)] actual = report(data) assert expected == actual