本文整理汇总了Python中vcs.utils.progressbar.ProgressBar类的典型用法代码示例。如果您正苦于以下问题:Python ProgressBar类的具体用法?Python ProgressBar怎么用?Python ProgressBar使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ProgressBar类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_iter_ends_at_last_step
def test_iter_ends_at_last_step(self):
bar = ProgressBar()
bar.stream = StringIO()
bar.steps = 20
bar.step = 5
stepped = list(bar)
self.assertEquals(stepped[-1], 20)
示例2: test_write
def test_write(self):
from StringIO import StringIO
stream = StringIO()
bar = ProgressBar()
bar.stream = stream
bar.write('foobar')
self.assertEquals(stream.getvalue(), 'foobar')
示例3: test_iter_starts_from_current_step
def test_iter_starts_from_current_step(self):
bar = ProgressBar()
bar.stream = StringIO()
bar.steps = 20
bar.step = 5
stepped = list(bar)
self.assertEquals(stepped[0], 5)
示例4: test_render_writes_new_line_at_last_step
def test_render_writes_new_line_at_last_step(self):
from StringIO import StringIO
bar = ProgressBar()
bar.stream = StringIO()
bar.steps = 5
bar.render(5)
self.assertEquals(bar.stream.getvalue()[-1], '\n')
示例5: test_context
def test_context(self):
bar = ProgressBar()
context = bar.get_context()
self.assertItemsEqual(context, [
'bar',
'percentage',
'time',
'eta',
'steps',
'speed',
'transfer',
])
示例6: test_get_rendered_transfer
def test_get_rendered_transfer(self):
B = 1
KB = B * 1024
MB = KB * 1024
GB = MB * 1024
bar = ProgressBar()
self.assertEqual(bar.get_rendered_transfer(12, 100),
'Transfer: 12 B / 100 B')
self.assertEqual(bar.get_rendered_transfer(KB * 5, MB),
'Transfer: 5 KB / 1.0 MB')
self.assertEqual(bar.get_rendered_transfer(GB * 2.3, GB * 10),
'Transfer: 2.30 GB / 10.00 GB')
示例7: test_get_percentage
def test_get_percentage(self):
bar = ProgressBar()
bar.steps = 120
bar.step = 60
self.assertEquals(bar.get_percentage(), 50.0)
bar.steps = 100
bar.step = 9
self.assertEquals(bar.get_percentage(), 9.0)
示例8: test_change_stream
def test_change_stream(self):
stream1 = StringIO()
stream2 = StringIO()
bar = ProgressBar()
bar.stream = stream1
bar.write('foo')
bar.stream = stream2
bar.write('bar')
self.assertEquals(stream2.getvalue(), 'bar')
示例9: test_render_raises_error_if_bar_already_finished
def test_render_raises_error_if_bar_already_finished(self):
bar = ProgressBar(10)
bar.stream = StringIO()
bar.render(10)
with self.assertRaises(AlreadyFinishedError):
bar.render(0)
示例10: test_get_eta
def test_get_eta(self):
bar = ProgressBar(100)
bar.stream = StringIO()
bar.render(50)
now = datetime.datetime.now()
delta = now - bar.started
self.assertEquals(get_total_seconds(bar.get_eta(now)),
int(get_total_seconds(delta) * 0.5))
bar.render(75)
now = datetime.datetime.now()
delta = now - bar.started
self.assertEquals(get_total_seconds(bar.get_eta(now)),
int(get_total_seconds(delta) * 0.25))
示例11: test_get_rendered_speed
def test_get_rendered_speed(self):
B = 1
KB = B * 1024
MB = KB * 1024
GB = MB * 1024
bar = ProgressBar(KB)
self.assertEqual(bar.get_rendered_speed(512, 1), 'Speed: 512 B/s')
self.assertEqual(bar.get_rendered_speed(512, 2), 'Speed: 256 B/s')
self.assertEqual(bar.get_rendered_speed(900, 3), 'Speed: 300 B/s')
bar = ProgressBar(GB * 10)
self.assertEqual(bar.get_rendered_speed(KB, 1), 'Speed: 1 KB/s')
self.assertEqual(bar.get_rendered_speed(MB, 1), 'Speed: 1.0 MB/s')
self.assertEqual(bar.get_rendered_speed(GB * 4, 2), 'Speed: 2.00 GB/s')
self.assertEqual(bar.get_rendered_speed(GB * 5, 2), 'Speed: 2.50 GB/s')
示例12: test_get_template
def test_get_template(self):
bar = ProgressBar()
bar.elements = ['foo', 'bar']
bar.separator = ' '
self.assertEquals(bar.get_template().template, '$foo $bar')
示例13: test_default_get_elements
def test_default_get_elements(self):
bar = ProgressBar(elements=['foo', 'bar'])
self.assertItemsEqual(bar.get_elements(), ['foo', 'bar'])
示例14: context_has_correct_speed
def context_has_correct_speed(self):
bar = ProgressBar(100)
speed = bar.get_context()['speed']
self.assertEquals(speed, bar.get_rendered_speed())
示例15: test_context_has_correct_steps
def test_context_has_correct_steps(self):
bar = ProgressBar(100)
steps = bar.get_context()['steps']
self.assertEquals(steps, bar.get_rendered_steps())