def test_render_truncated(self): # when the bar is too long for the terminal, we prefer not to truncate # the counters because they might be interesting, and because # truncating the numbers might be misleading out, view = self.make_view() task_a = ProgressTask(None, progress_view=view) task_a.update("start_" + "a" * 200 + "_end", 2000, 5000) line = view._render_line() self.assertEqual("- start_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.. 2000/5000", line) self.assertEqual(len(line), 79)
def test_render_truncated(self): # when the bar is too long for the terminal, we prefer not to truncate # the counters because they might be interesting, and because # truncating the numbers might be misleading out, view = self.make_view() task_a = ProgressTask(None, progress_view=view) task_a.update('start_' + 'a' * 200 + '_end', 2000, 5000) line = view._render_line() self.assertEqual( '- start_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.. 2000/5000', line) self.assertEqual(len(line), 79)
def test_render_with_activity(self): # if the progress view has activity, it's shown before the spinner out, view = self.make_view() task_a = ProgressTask(None, progress_view=view) view._last_transport_msg = " 123kB 100kB/s " line = view._render_line() self.assertEqual(" 123kB 100kB/s / ", line) self.assertEqual(len(line), 79) task_a.update("start_" + "a" * 200 + "_end", 2000, 5000) view._last_transport_msg = " 123kB 100kB/s " line = view._render_line() self.assertEqual(" 123kB 100kB/s \\ start_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.. 2000/5000", line) self.assertEqual(len(line), 79)
def test_render_with_activity(self): # if the progress view has activity, it's shown before the spinner out, view = self.make_view() task_a = ProgressTask(None, progress_view=view) view._last_transport_msg = ' 123kB 100kB/s ' line = view._render_line() self.assertEqual( ' 123kB 100kB/s / ', line) self.assertEqual(len(line), 79) task_a.update('start_' + 'a' * 200 + '_end', 2000, 5000) view._last_transport_msg = ' 123kB 100kB/s ' line = view._render_line() self.assertEqual( ' 123kB 100kB/s \\ start_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.. 2000/5000', line) self.assertEqual(len(line), 79)
def test_render_progress_sub_nested(self): """Intermediate tasks don't mess up calculation.""" out, view = self.make_view() view.enable_bar = True task_a = ProgressTask(None, progress_view=view) task_a.update('a', 0, 2) task_b = ProgressTask(task_a, progress_view=view) task_b.update('b') task_c = ProgressTask(task_b, progress_view=view) task_c.update('c', 1, 2) # the top-level task is in its first half; the middle one has no # progress indication, just a label; and the bottom one is half done, # so the overall fraction is 1/4 self.assertEqual( '[####| ] a:b:c 1/2 ', view._render_line())
def test_render_progress_sub_nested(self): """Intermediate tasks don't mess up calculation.""" out, view = self.make_view() view.enable_bar = True task_a = ProgressTask(None, progress_view=view) task_a.update("a", 0, 2) task_b = ProgressTask(task_a, progress_view=view) task_b.update("b") task_c = ProgressTask(task_b, progress_view=view) task_c.update("c", 1, 2) # the top-level task is in its first half; the middle one has no # progress indication, just a label; and the bottom one is half done, # so the overall fraction is 1/4 self.assertEqual( "[####| ] a:b:c 1/2 ", view._render_line() )