Ejemplo n.º 1
0
 def make_task(self, parent_task, view, msg, curr, total):
     # would normally be done by UIFactory; is done here so that we don't
     # have to have one.
     task = ProgressTask(parent_task, progress_view=view)
     task.msg = msg
     task.current_cnt = curr
     task.total_cnt = total
     return task
Ejemplo n.º 2
0
 def make_task(self, parent_task, view, msg, curr, total):
     # would normally be done by UIFactory; is done here so that we don't
     # have to have one.
     task = ProgressTask(parent_task, progress_view=view)
     task.msg = msg
     task.current_cnt = curr
     task.total_cnt = total
     return task
Ejemplo n.º 3
0
 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)
Ejemplo n.º 4
0
 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)
Ejemplo n.º 5
0
 def test_progress_updated_without_widget(self):
     ui_factory = ui.GtkUIFactory()
     MockMethod.bind(self, ui.ProgressBarWindow, 'update')
     task = ProgressTask()
     task.msg = 'test'
     task.current_cnt = 1
     task.total_cnt = 2
     self.assertIs(None, ui_factory._progress_updated(task))
     self.assertIsInstance(
         ui_factory._progress_bar_widget, ui.ProgressBarWindow)
     self.assertIs(True, ui_factory._progress_bar_widget.update.called)
     self.assertEqual(
         ('test', 1, 2), ui_factory._progress_bar_widget.update.args)
Ejemplo n.º 6
0
 def test_progress_updated_with_widget(self):
     ui_factory = ui.GtkUIFactory()
     progress_widget = ui.ProgressPanel()
     MockMethod.bind(self, progress_widget, 'update')
     ui_factory.set_progress_bar_widget(progress_widget)
     task = ProgressTask()
     task.msg = 'test'
     task.current_cnt = 1
     task.total_cnt = 2
     self.assertIs(None, ui_factory._progress_updated(task))
     self.assertIs(True, progress_widget.update.called)
     self.assertEqual(
         ('test', 1, 2), progress_widget.update.args)
Ejemplo n.º 7
0
    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)
Ejemplo n.º 8
0
    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)
Ejemplo n.º 9
0
 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()
     )
Ejemplo n.º 10
0
 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())