def test__display_progress_bar(self, mock_sys): fake_file = StringIO('test') # 4 bytes fake_file.len = 4 pb = progressbar.VerboseFileWrapper(fake_file) pb._display_progress_bar(2) # 2 of 4 bytes = 50% pb._display_progress_bar(1) # 3 of 4 bytes = 75% pb._display_progress_bar(1) # 4 of 4 bytes = 100% expected = [ mock.call('\r[===============> ] 50%'), mock.call('\r[======================> ] 75%'), mock.call('\r[=============================>] 100%'), ] self.assertEqual(expected, mock_sys.stdout.write.mock_calls)
def test__display_progress_bar_unknown_len(self, mock_sys): fake_file = StringIO('') fake_file.len = 0 pb = progressbar.VerboseFileWrapper(fake_file) for i in range(6): pb._display_progress_bar(1) expected = [ mock.call('\r[-] 1 bytes'), mock.call('\r[\\] 2 bytes'), mock.call('\r[|] 3 bytes'), mock.call('\r[/] 4 bytes'), mock.call('\r[-] 5 bytes'), mock.call('\r[\\] 6 bytes'), ] self.assertEqual(expected, mock_sys.stdout.write.mock_calls)