def update(self): writer = TerminalWriter(StringIO()) progressbar = ProgressBar([], writer, maxsteps=20) widget = PercentageWidget() widget.init(progressbar, writer.get_width()) for i in xrange(5, 96, 5): progressbar.step += 1 result = widget.update(progressbar, writer.get_width()) Assert(result) == '%i%%' % i
def size_hint(self): writer = TerminalWriter(StringIO()) progressbar = ProgressBar([], writer, maxsteps=20) widget = PercentageWidget() assert widget.provides_size_hint Assert(widget.size_hint(progressbar)) == 2 progressbar.step = 1 Assert(widget.size_hint(progressbar)) == 2 progressbar.step = 2 Assert(widget.size_hint(progressbar)) == 3 progressbar.step = 20 Assert(widget.size_hint(progressbar)) == 4
def repr(self): widget = PercentageWidget() Assert(repr(widget)) == 'PercentageWidget()'
def finish(self): writer = TerminalWriter(StringIO()) progressbar = ProgressBar([], writer, maxsteps=100) widget = PercentageWidget() widget.init(progressbar, writer.get_width()) Assert(widget.finish(progressbar, writer.get_width())) == '100%'