Esempio n. 1
0
 def test_step(self):
     self.bar.iterable = gen_range(100)
     self.assertEqual(self.bar.step, 0)
     iterator = iter(self.bar)
     next(iterator)
     self.assertEqual(self.bar.step, 1)
     next(iterator)
     next(iterator)
     next(iterator)
     self.assertEqual(self.bar.step, 4)
Esempio n. 2
0
 def test_step(self):
     self.bar.iterable = gen_range(100)
     self.assertEqual(self.bar.step, 0)
     iterator = iter(self.bar)
     next(iterator)
     self.assertEqual(self.bar.step, 1)
     next(iterator)
     next(iterator)
     next(iterator)
     self.assertEqual(self.bar.step, 4)
Esempio n. 3
0
 def test_render_len_not_known(self, get_terminal_width):
     get_terminal_width.return_value = None
     self.widget.width = 3
     self.bar = frogress.Bar(gen_range(5), widgets=[self.widget])
     self.bar.treshold = 0
     #self.bar.get_percentage = mock.Mock(return_value=None)
     self.bar.output = io.StringIO()
     list(self.bar)  # exhaust progressbar iterator
     expected = ''.join('\r%s' % line for line in [
         '[#..]',  # step 1
         '[.#.]',  # step 2
         '[..#]',  # step 3
         '[.#.]',  # step 4
         '[#..]',  # step 5
         '[###]',  # bar.finish()
     ])
     self.assertEqual(self.bar.output.getvalue(), expected)
Esempio n. 4
0
 def test_render_len_not_known(self, get_terminal_width):
     get_terminal_width.return_value = None
     self.widget.width = 3
     self.bar = frogress.Bar(gen_range(5), widgets=[self.widget])
     self.bar.treshold = 0
     #self.bar.get_percentage = mock.Mock(return_value=None)
     self.bar.output = io.StringIO()
     list(self.bar) # exhaust progressbar iterator
     expected = ''.join('\r%s' % line for line in [
         '[#..]', # step 1
         '[.#.]', # step 2
         '[..#]', # step 3
         '[.#.]', # step 4
         '[#..]', # step 5
         '[###]', # bar.finish()
     ])
     self.assertEqual(self.bar.output.getvalue(), expected)
Esempio n. 5
0
 def test_progress(self, get_terminal_width):
     get_terminal_width.return_value = None
     self.bar.iterable = gen_range(3)
     self.bar.output = io.StringIO()
     self.bar.treshold = 0
     self.bar.setup_widgets([ProgressWidget])
     next(self.bar)
     next(self.bar)
     next(self.bar)
     with self.assertRaises(StopIteration):
         next(self.bar)
     output = self.bar.output.getvalue()
     self.assertEqual(output, '\r'.join([
         '\rProgress: 1',
         'Progress: 2',
         'Progress: 3',
         'Progress: 3', # show is called on finish too
     ]))
Esempio n. 6
0
 def test_progress(self, get_terminal_width):
     get_terminal_width.return_value = None
     self.bar.iterable = gen_range(3)
     self.bar.output = io.StringIO()
     self.bar.treshold = 0
     self.bar.setup_widgets([ProgressWidget])
     next(self.bar)
     next(self.bar)
     next(self.bar)
     with self.assertRaises(StopIteration):
         next(self.bar)
     output = self.bar.output.getvalue()
     self.assertEqual(
         output,
         '\r'.join([
             '\rProgress: 1',
             'Progress: 2',
             'Progress: 3',
             'Progress: 3',  # show is called on finish too
         ]))
Esempio n. 7
0
 def test_step_callback(self):
     self.bar.iterable = gen_range(100)
     self.bar.step_callback = lambda: 11
     self.assertEqual(self.bar.step, 11)
     self.bar.step_callback = lambda: 209
     self.assertEqual(self.bar.step, 209)
Esempio n. 8
0
 def test_get_percentage_if_len_is_not_known(self):
     self.bar.iterable = gen_range(10)
     self.bar.step = 51
     self.assertIsNone(self.bar.get_percentage())
Esempio n. 9
0
 def test_step_callback(self):
     self.bar.iterable = gen_range(100)
     self.bar.step_callback = lambda: 11
     self.assertEqual(self.bar.step, 11)
     self.bar.step_callback = lambda: 209
     self.assertEqual(self.bar.step, 209)
Esempio n. 10
0
 def test_get_percentage_if_len_is_not_known(self):
     self.bar.iterable = gen_range(10)
     self.bar.step = 51
     self.assertIsNone(self.bar.get_percentage())
Esempio n. 11
0
 def test_generator(self):
     self.assertEqual(frogress.get_iterable_size(gen_range(3)), None)