def test_print_report(): """ Test to ensure report is generated. """ donor_db = mailroom.donor_dict report = mailroom.print_report(donor_db) print(report)
def test_print_report(capsys): summary = [['Pam Beesley', '$6000.00', '3', '$2000.00'], ['Andy Bernard', '$500.00', '1', '$500.00'], ['Michael Scott', '$60.00', '3', '$20.00'], ['Dwight Shrute', '$5.00', '2', '$2.50'], ['Jim Halpert', '$1.00', '1', '$1.00']] r = ('Donor Name | Total Given | Num Gifts | Average Gift\n' 'Pam Beesley $ $6000.00 | 3 $ $2000.00\n' 'Andy Bernard $ $500.00 | 1 $ $500.00\n' 'Michael Scott $ $60.00 | 3 $ $20.00\n' 'Dwight Shrute $ $5.00 | 2 $ $2.50\n' 'Jim Halpert $ $1.00 |' ' 1 $ $1.00' '\n') print_report(summary) captured = capsys.readouterr() assert captured.out == r
def test_print_report(self): report_text = \ ''' Donor Name | Total Given | Num Gifts | Average Gift ------------------------------------------------------------------ Al Donor1 $ 150.00 5 $ 30.00 Bert Donor2 $ 10.00 1 $ 10.00 Connie Donor3 $ 30.01 3 $ 10.00 Dennis Donor4 $ 50.00 3 $ 16.67 Egbert Donor5 $ 4041.59 4 $ 1010.40 TESTME TESTME $ 4046.59 4 $ 1011.65 ''' capturedprint = io.StringIO() # Redirect stdout to a stringIO object sys.stdout = capturedprint mr.print_report() # Execute function that uses stdout sys.stdout = sys.__stdout__ # Reset stdout back to normal self.assertEqual(capturedprint.getvalue().strip(), report_text.strip())
def test_print_report_check_sorting(): """ Verify that the printed donations report has the correctly sorted top element thereby proving that the sorting function is being called and operating correctly """ report_result = mailroom.print_report()[0] first_row = report_result[0] assert first_row[0] == 'Elmer Fudd' assert first_row[1] == 80730.00 assert first_row[2] == 5 assert first_row[3] == 16146.00
def test_print_report(self): """ test print list of your donors to console """ out = io.StringIO() with redirect_stdout(out): mr.print_report() output = out.getvalue().strip() self.assertIn( "--------------------------------------------------------------------", output) self.assertIn( "Donor Name | Total Given | Num Gifts | Average Gift", output) self.assertIn( "Ken Lenning $ 18,882.74 3 $ 6,294.25", output) self.assertIn( "Lucy Nguyen $ 5,253.82 1 $ 5,253.82", output) self.assertIn( "Ben Cormack $ 157,788.05 3 $ 52,596.02", output) out.close()
def test_print_report_formatting(): """ Verify that the donor report output to the console is correctly formatted given the expected header and row format definitions """ expected_header = 'Donor Name | Total Given | Num Gifts | Average Gift' row_format = '{:<24} ${:>13.2f} {:>12} ${:>13.2f}' report_width = 68 raw_result, formatted_result = mailroom.print_report() assert formatted_result[0] == expected_header assert len(formatted_result[1]) == report_width assert len(formatted_result[-1]) == report_width for row in raw_result: expected_row = row_format.format(*row) assert expected_row in formatted_result
def test_print_report_function_runs(): """Test that print_report() function runs by running True .""" from mailroom import print_report assert print_report(sample_list)